Skip to content

Commit

Permalink
Fix BC promise bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 10, 2021
1 parent 2b4acc6 commit 7cc74bf
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 60 deletions.
14 changes: 0 additions & 14 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@ services:
stubInterfaceName: PHPStan\Mockery\Type\Expects
stubMethodName: expects

-
class: PHPStan\Mockery\Type\ExpectationAfterStubDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
arguments:
stubInterfaceName: PHPStan\Mockery\Type\Allows

-
class: PHPStan\Mockery\Type\ExpectationAfterStubDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
arguments:
stubInterfaceName: PHPStan\Mockery\Type\Expects

-
class: PHPStan\Mockery\Type\MockDynamicReturnTypeExtension
tags:
Expand Down
5 changes: 0 additions & 5 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>-->
<!-- <rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/> -->
<!-- <rule ref="SlevomatCodingStandard.PHP.ShortList"/> -->
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array" value="src=>PHPStan,tests=>PHPStan"/>
</properties>
</rule>
<exclude-pattern>tests/*/data</exclude-pattern>
<exclude-pattern>tests/tmp</exclude-pattern>
</ruleset>
12 changes: 10 additions & 2 deletions src/Mockery/Reflection/StubMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use PHPStan\Reflection\ClassMemberReflection;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionVariant;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\TrivialParametersAcceptor;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\ObjectType;

class StubMethodReflection implements MethodReflection
{
Expand Down Expand Up @@ -59,7 +61,13 @@ public function getPrototype(): ClassMemberReflection
public function getVariants(): array
{
return [
new TrivialParametersAcceptor(),
new FunctionVariant(
TemplateTypeMap::createEmpty(),
TemplateTypeMap::createEmpty(),
[],
true,
new ObjectType('Mockery\\Expectation')
),
];
}

Expand Down
11 changes: 10 additions & 1 deletion src/Mockery/Reflection/StubMethodsClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@

namespace PHPStan\Mockery\Reflection;

use Mockery\Expectation;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPStan\Reflection\ReflectionProvider;

class StubMethodsClassReflectionExtension implements MethodsClassReflectionExtension
{

/** @var ReflectionProvider */
private $reflectionProvider;

/** @var string */
private $stubInterfaceName;

public function __construct(string $stubInterfaceName)
public function __construct(ReflectionProvider $reflectionProvider, string $stubInterfaceName)
{
$this->reflectionProvider = $reflectionProvider;
$this->stubInterfaceName = $stubInterfaceName;
}

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

public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
{
if ($this->reflectionProvider->hasClass(Expectation::class)) {
$classReflection = $this->reflectionProvider->getClass(Expectation::class);
}
return new StubMethodReflection($classReflection, $methodName);
}

Expand Down

This file was deleted.

13 changes: 13 additions & 0 deletions tests/Mockery/DifferentFoo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types = 1);

namespace App;

class DifferentFoo
{

public function doFoo(int $i): int
{
return $i - 1;
}

}
30 changes: 30 additions & 0 deletions tests/Mockery/DifferentNamespaceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types = 1);

namespace App;

use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\MockInterface;

class DifferentNamespaceTest extends MockeryTestCase
{

/** @var MockInterface&DifferentFoo */
private $fooMock;

protected function setUp(): void
{
parent::setUp();

$this->fooMock = \Mockery::mock(DifferentFoo::class);
}

public function testWith(): void
{
$this->fooMock->expects('doFoo')
->with(1)
->andReturn(2);

self::assertSame(2, $this->fooMock->doFoo(1));
}

}

0 comments on commit 7cc74bf

Please sign in to comment.