Skip to content

Commit

Permalink
Support for makePartial()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 15, 2019
1 parent 6afb5cb commit 8f3f0dc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ services:
arguments:
stubInterfaceName: PHPStan\Mockery\Type\Expects

-
class: PHPStan\Mockery\Type\MakePartialDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension

-
class: PHPStan\Mockery\Type\StubDynamicReturnTypeExtension
tags:
Expand Down
29 changes: 29 additions & 0 deletions src/Mockery/Type/MakePartialDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types = 1);

namespace PHPStan\Mockery\Type;

use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Type;

class MakePartialDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{

public function getClass(): string
{
return 'Mockery\\MockInterface';
}

public function isMethodSupported(MethodReflection $methodReflection): bool
{
return $methodReflection->getName() === 'makePartial';
}

public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
{
return $scope->getType($methodCall->var);
}

}
9 changes: 9 additions & 0 deletions tests/Mockery/MockeryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public function testMockWithMethods(): void
self::assertSame('foo', $fooMock->doFoo());
}

public function testMakePartial(): void
{
$fooMock = \Mockery::mock(Foo::class)->makePartial();
$this->requireFoo($fooMock);

$fooMock->allows()->doFoo()->andReturns('foo');
self::assertSame('foo', $fooMock->doFoo());
}

private function requireFoo(Foo $foo): void
{
}
Expand Down

0 comments on commit 8f3f0dc

Please sign in to comment.