Skip to content

Commit

Permalink
Merge pull request #31 from agorden-ekino/master
Browse files Browse the repository at this point in the history
fix(ci): Make app ci fix, changed MethodReflection to ExtendedMethodReflection
  • Loading branch information
mremi authored Sep 13, 2022
2 parents 46b8d85 + 335cb02 commit 5aa67a4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ master
------

* Add Composer keyword for asking user to add this package to require-dev instead of require
* Fix tests by changing MethodReflection to expected ExtendedMethodRepository

v1.0.0
------
Expand Down
45 changes: 22 additions & 23 deletions tests/Type/ObjectRepositoryDynamicReturnTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Reflection\TrivialParametersAcceptor;
use PHPStan\Type\ArrayType;
Expand Down Expand Up @@ -47,9 +47,9 @@ class ObjectRepositoryDynamicReturnTypeExtensionTest extends TestCase
private $reflectionProvider;

/**
* @var MockObject|MethodReflection
* @var MockObject|ExtendedMethodReflection
*/
private $methodReflection;
private $extendedMethodReflection;

/**
* @var MockObject|MethodCall
Expand All @@ -71,14 +71,14 @@ class ObjectRepositoryDynamicReturnTypeExtensionTest extends TestCase
*/
protected function setUp(): void
{
$this->reflectionProvider = $this->createMock(ReflectionProvider::class);
$this->extension = new ObjectRepositoryDynamicReturnTypeExtension($this->reflectionProvider);
$this->methodReflection = $this->createMock(MethodReflection::class);
$this->methodCall = $this->createMock(MethodCall::class);
$this->scope = $this->createMock(Scope::class);
$this->expr = $this->createMock(Expr::class);
$this->methodCall->var = $this->expr;
$this->methodCall->args = [];
$this->reflectionProvider = $this->createMock(ReflectionProvider::class);
$this->extension = new ObjectRepositoryDynamicReturnTypeExtension($this->reflectionProvider);
$this->extendedMethodReflection = $this->createMock(ExtendedMethodReflection::class);
$this->methodCall = $this->createMock(MethodCall::class);
$this->scope = $this->createMock(Scope::class);
$this->expr = $this->createMock(Expr::class);
$this->methodCall->var = $this->expr;
$this->methodCall->args = [];
}

/**
Expand All @@ -96,10 +96,9 @@ public function testGetClass(): void
*/
public function testIsMethodSupported(bool $expected, string $methodName): void
{
$methodReflection = $this->createMock(MethodReflection::class);
$methodReflection->expects($this->once())->method('getName')->willReturn($methodName);
$this->extendedMethodReflection->expects($this->once())->method('getName')->willReturn($methodName);

$this->assertSame($expected, $this->extension->isMethodSupported($methodReflection));
$this->assertSame($expected, $this->extension->isMethodSupported($this->extendedMethodReflection));
}

/**
Expand Down Expand Up @@ -129,7 +128,7 @@ public function testGetTypeFromMethodCallWithoutClassNameType(): void
$type = $this->createMock(Type::class);
$this->scope->expects($this->once())->method('getType')->with($this->expr)->willReturn($type);

$this->assertInstanceOf(MixedType::class, $this->extension->getTypeFromMethodCall($this->methodReflection, $this->methodCall, $this->scope));
$this->assertInstanceOf(MixedType::class, $this->extension->getTypeFromMethodCall($this->extendedMethodReflection, $this->methodCall, $this->scope));
}

/**
Expand All @@ -140,7 +139,7 @@ public function testGetTypeFromMethodCallWithClassNameType(): void
$type = $this->createMock(TypeWithClassName::class);
$this->scope->expects($this->once())->method('getType')->with($this->expr)->willReturn($type);

$this->assertInstanceOf(MixedType::class, $this->extension->getTypeFromMethodCall($this->methodReflection, $this->methodCall, $this->scope));
$this->assertInstanceOf(MixedType::class, $this->extension->getTypeFromMethodCall($this->extendedMethodReflection, $this->methodCall, $this->scope));
}

/**
Expand All @@ -153,18 +152,18 @@ public function testGetTypeFromMethodCallWithDynamicClassNameType(string $method
$type = $this->createMock(TypeWithClassName::class);
$type->expects($this->exactly(2))->method('getClassName')->willReturn('Foo');
$this->scope->expects($this->once())->method('getType')->with($this->expr)->willReturn($type);
$this->methodReflection->expects($this->once())->method('getName')->willReturn($methodName);
$this->extendedMethodReflection->expects($this->once())->method('getName')->willReturn($methodName);

$returnedMethodReflection = $this->createMock(MethodReflection::class);
$returnedMethodReflection->expects($this->once())->method('getVariants')->willReturn([new TrivialParametersAcceptor()]);
$returnedExtendedMethodReflection = $this->createMock(ExtendedMethodReflection::class);
$returnedExtendedMethodReflection->expects($this->once())->method('getVariants')->willReturn([new TrivialParametersAcceptor()]);

$classReflection = $this->createMock(ClassReflection::class);
$classReflection->expects($this->once())->method('hasNativeMethod')->with($methodName)->willReturn(true);
$classReflection->expects($this->once())->method('getNativeMethod')->with($methodName)->willReturn($returnedMethodReflection);
$classReflection->expects($this->once())->method('getNativeMethod')->with($methodName)->willReturn($returnedExtendedMethodReflection);
$this->reflectionProvider->expects($this->once())->method('hasClass')->with('Foo')->willReturn(true);
$this->reflectionProvider->expects($this->once())->method('getClass')->with('Foo')->willReturn($classReflection);

$this->assertInstanceOf(MixedType::class, $this->extension->getTypeFromMethodCall($this->methodReflection, $this->methodCall, $this->scope));
$this->assertInstanceOf(MixedType::class, $this->extension->getTypeFromMethodCall($this->extendedMethodReflection, $this->methodCall, $this->scope));
}

/**
Expand All @@ -187,11 +186,11 @@ public function testGetTypeFromMethodCallWithObjectRepositoryType(string $expect
$type = $this->createMock(ObjectRepositoryType::class);
$type->expects($this->once())->method('getClassName')->willReturn('Foo');
$this->scope->expects($this->once())->method('getType')->with($this->expr)->willReturn($type);
$this->methodReflection->expects($this->once())->method('getName')->willReturn($methodName);
$this->extendedMethodReflection->expects($this->once())->method('getName')->willReturn($methodName);

$this->reflectionProvider->expects($this->once())->method('hasClass')->with('Foo')->willReturn(false);

$this->assertInstanceOf($expected, $this->extension->getTypeFromMethodCall($this->methodReflection, $this->methodCall, $this->scope));
$this->assertInstanceOf($expected, $this->extension->getTypeFromMethodCall($this->extendedMethodReflection, $this->methodCall, $this->scope));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Type/ProxyQueryDynamicReturnTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use PHPStan\Broker\Broker;
use PHPStan\Reflection\BrokerAwareExtension;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface as AdminProxyQueryInterface;
Expand Down Expand Up @@ -97,16 +97,16 @@ public function hasMethodDataProvider(): \Generator
*/
public function testGetMethod(): void
{
$methodReflection = $this->createMock(MethodReflection::class);
$extendedMethodReflection = $this->createMock(ExtendedMethodReflection::class);

$dummyClassReflection = $this->createMock(ClassReflection::class);
$dummyClassReflection->expects($this->once())->method('getNativeMethod')->willReturn($methodReflection);
$dummyClassReflection->expects($this->once())->method('getNativeMethod')->willReturn($extendedMethodReflection);

$broker = $this->createMock(Broker::class);
$broker->expects($this->once())->method('getClass')->with($this->equalTo(QueryBuilder::class))->willReturn($dummyClassReflection);

$this->extension->setBroker($broker);

$this->assertSame($methodReflection, $this->extension->getMethod($this->createMock(ClassReflection::class), 'leftJoin'));
$this->assertSame($extendedMethodReflection, $this->extension->getMethod($this->createMock(ClassReflection::class), 'leftJoin'));
}
}

0 comments on commit 5aa67a4

Please sign in to comment.