Skip to content

Commit 7cc74bf

Browse files
committed
Fix BC promise bug
1 parent 2b4acc6 commit 7cc74bf

7 files changed

+63
-60
lines changed

extension.neon

-14
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,6 @@ services:
4040
stubInterfaceName: PHPStan\Mockery\Type\Expects
4141
stubMethodName: expects
4242

43-
-
44-
class: PHPStan\Mockery\Type\ExpectationAfterStubDynamicReturnTypeExtension
45-
tags:
46-
- phpstan.broker.dynamicMethodReturnTypeExtension
47-
arguments:
48-
stubInterfaceName: PHPStan\Mockery\Type\Allows
49-
50-
-
51-
class: PHPStan\Mockery\Type\ExpectationAfterStubDynamicReturnTypeExtension
52-
tags:
53-
- phpstan.broker.dynamicMethodReturnTypeExtension
54-
arguments:
55-
stubInterfaceName: PHPStan\Mockery\Type\Expects
56-
5743
-
5844
class: PHPStan\Mockery\Type\MockDynamicReturnTypeExtension
5945
tags:

phpcs.xml

-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@
5656
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>-->
5757
<!-- <rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/> -->
5858
<!-- <rule ref="SlevomatCodingStandard.PHP.ShortList"/> -->
59-
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
60-
<properties>
61-
<property name="rootNamespaces" type="array" value="src=>PHPStan,tests=>PHPStan"/>
62-
</properties>
63-
</rule>
6459
<exclude-pattern>tests/*/data</exclude-pattern>
6560
<exclude-pattern>tests/tmp</exclude-pattern>
6661
</ruleset>

src/Mockery/Reflection/StubMethodReflection.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
use PHPStan\Reflection\ClassMemberReflection;
66
use PHPStan\Reflection\ClassReflection;
7+
use PHPStan\Reflection\FunctionVariant;
78
use PHPStan\Reflection\MethodReflection;
8-
use PHPStan\Reflection\TrivialParametersAcceptor;
99
use PHPStan\TrinaryLogic;
10+
use PHPStan\Type\Generic\TemplateTypeMap;
11+
use PHPStan\Type\ObjectType;
1012

1113
class StubMethodReflection implements MethodReflection
1214
{
@@ -59,7 +61,13 @@ public function getPrototype(): ClassMemberReflection
5961
public function getVariants(): array
6062
{
6163
return [
62-
new TrivialParametersAcceptor(),
64+
new FunctionVariant(
65+
TemplateTypeMap::createEmpty(),
66+
TemplateTypeMap::createEmpty(),
67+
[],
68+
true,
69+
new ObjectType('Mockery\\Expectation')
70+
),
6371
];
6472
}
6573

src/Mockery/Reflection/StubMethodsClassReflectionExtension.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22

33
namespace PHPStan\Mockery\Reflection;
44

5+
use Mockery\Expectation;
56
use PHPStan\Reflection\ClassReflection;
67
use PHPStan\Reflection\MethodReflection;
78
use PHPStan\Reflection\MethodsClassReflectionExtension;
9+
use PHPStan\Reflection\ReflectionProvider;
810

911
class StubMethodsClassReflectionExtension implements MethodsClassReflectionExtension
1012
{
1113

14+
/** @var ReflectionProvider */
15+
private $reflectionProvider;
16+
1217
/** @var string */
1318
private $stubInterfaceName;
1419

15-
public function __construct(string $stubInterfaceName)
20+
public function __construct(ReflectionProvider $reflectionProvider, string $stubInterfaceName)
1621
{
22+
$this->reflectionProvider = $reflectionProvider;
1723
$this->stubInterfaceName = $stubInterfaceName;
1824
}
1925

@@ -24,6 +30,9 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
2430

2531
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
2632
{
33+
if ($this->reflectionProvider->hasClass(Expectation::class)) {
34+
$classReflection = $this->reflectionProvider->getClass(Expectation::class);
35+
}
2736
return new StubMethodReflection($classReflection, $methodName);
2837
}
2938

src/Mockery/Type/ExpectationAfterStubDynamicReturnTypeExtension.php

-38
This file was deleted.

tests/Mockery/DifferentFoo.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace App;
4+
5+
class DifferentFoo
6+
{
7+
8+
public function doFoo(int $i): int
9+
{
10+
return $i - 1;
11+
}
12+
13+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace App;
4+
5+
use Mockery\Adapter\Phpunit\MockeryTestCase;
6+
use Mockery\MockInterface;
7+
8+
class DifferentNamespaceTest extends MockeryTestCase
9+
{
10+
11+
/** @var MockInterface&DifferentFoo */
12+
private $fooMock;
13+
14+
protected function setUp(): void
15+
{
16+
parent::setUp();
17+
18+
$this->fooMock = \Mockery::mock(DifferentFoo::class);
19+
}
20+
21+
public function testWith(): void
22+
{
23+
$this->fooMock->expects('doFoo')
24+
->with(1)
25+
->andReturn(2);
26+
27+
self::assertSame(2, $this->fooMock->doFoo(1));
28+
}
29+
30+
}

0 commit comments

Comments
 (0)