Skip to content

Commit 8f3f0dc

Browse files
committed
Support for makePartial()
1 parent 6afb5cb commit 8f3f0dc

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

extension.neon

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ services:
1313
arguments:
1414
stubInterfaceName: PHPStan\Mockery\Type\Expects
1515

16+
-
17+
class: PHPStan\Mockery\Type\MakePartialDynamicReturnTypeExtension
18+
tags:
19+
- phpstan.broker.dynamicMethodReturnTypeExtension
20+
1621
-
1722
class: PHPStan\Mockery\Type\StubDynamicReturnTypeExtension
1823
tags:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Mockery\Type;
4+
5+
use PhpParser\Node\Expr\MethodCall;
6+
use PHPStan\Analyser\Scope;
7+
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Type\DynamicMethodReturnTypeExtension;
9+
use PHPStan\Type\Type;
10+
11+
class MakePartialDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
12+
{
13+
14+
public function getClass(): string
15+
{
16+
return 'Mockery\\MockInterface';
17+
}
18+
19+
public function isMethodSupported(MethodReflection $methodReflection): bool
20+
{
21+
return $methodReflection->getName() === 'makePartial';
22+
}
23+
24+
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
25+
{
26+
return $scope->getType($methodCall->var);
27+
}
28+
29+
}

tests/Mockery/MockeryTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ public function testMockWithMethods(): void
9595
self::assertSame('foo', $fooMock->doFoo());
9696
}
9797

98+
public function testMakePartial(): void
99+
{
100+
$fooMock = \Mockery::mock(Foo::class)->makePartial();
101+
$this->requireFoo($fooMock);
102+
103+
$fooMock->allows()->doFoo()->andReturns('foo');
104+
self::assertSame('foo', $fooMock->doFoo());
105+
}
106+
98107
private function requireFoo(Foo $foo): void
99108
{
100109
}

0 commit comments

Comments
 (0)