From 311480c95787752dc6fcad704b66d02090b90422 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Fri, 16 Sep 2016 17:45:12 +0100 Subject: [PATCH 1/2] Updated deprecated phpunit API calls in test suite --- test/unit/Identifier/IdentifierTypeTest.php | 18 ++----- .../NodeCompiler/CompileNodeToValueTest.php | 26 ++++------ .../unit/NodeCompiler/CompilerContextTest.php | 6 +-- .../Adapter/ReflectionClassTest.php | 18 ++----- .../Adapter/ReflectionFunctionTest.php | 13 ++--- .../Adapter/ReflectionMethodTest.php | 21 +++------ .../Adapter/ReflectionObjectTest.php | 18 ++----- .../Adapter/ReflectionParameterTest.php | 21 +++------ .../Adapter/ReflectionPropertyTest.php | 13 ++--- test/unit/Reflection/ReflectionClassTest.php | 41 ++++++++-------- .../ReflectionFunctionAbstractTest.php | 10 ++-- test/unit/Reflection/ReflectionMethodTest.php | 5 +- test/unit/Reflection/ReflectionObjectTest.php | 26 ++++------ .../Reflection/ReflectionParameterTest.php | 16 ++++--- .../Reflection/ReflectionPropertyTest.php | 4 +- .../Ast/FindReflectionsInTreeTest.php | 47 +++++-------------- test/unit/SourceLocator/Ast/LocatorTest.php | 4 +- .../Ast/Strategy/NodeToReflectionTest.php | 10 ++-- .../Located/LocatedSourceTest.php | 15 ++++-- .../Type/AbstractSourceLocatorTest.php | 44 +++++------------ .../Type/AggregateSourceLocatorTest.php | 34 ++++++-------- .../Type/AutoloadSourceLocatorTest.php | 4 +- .../Type/ClosureSourceLocatorTest.php | 7 +-- .../Type/ComposerSourceLocatorTest.php | 12 ++--- .../Type/EvaledCodeSourceLocatorTest.php | 2 +- .../Type/PhpInternalSourceLocatorTest.php | 2 +- .../Type/SingleFileSourceLocatorTest.php | 11 +++-- .../Type/StringSourceLocatorTest.php | 4 +- .../TypesFinder/FindParameterTypeTest.php | 15 ++---- .../unit/TypesFinder/FindPropertyTypeTest.php | 20 ++------ test/unit/TypesFinder/FindReturnTypeTest.php | 15 ++---- 31 files changed, 186 insertions(+), 316 deletions(-) diff --git a/test/unit/Identifier/IdentifierTypeTest.php b/test/unit/Identifier/IdentifierTypeTest.php index 4b26ba876..b77b07421 100644 --- a/test/unit/Identifier/IdentifierTypeTest.php +++ b/test/unit/Identifier/IdentifierTypeTest.php @@ -34,18 +34,14 @@ public function testPossibleIdentifierTypes($full) public function testThrowsAnExceptionWhenInvalidTypeGiven() { - $this->setExpectedException( - InvalidArgumentException::class, - 'foo is not a valid identifier type' - ); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('foo is not a valid identifier type'); new IdentifierType('foo'); } public function testIsMatchingReflectorClass() { - $reflectionClass = $this->getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $reflectionClass = $this->createMock(ReflectionClass::class); $type = new IdentifierType(IdentifierType::IDENTIFIER_CLASS); @@ -54,9 +50,7 @@ public function testIsMatchingReflectorClass() public function testIsMatchingReflectorFunction() { - $reflectionFunction = $this->getMockBuilder(ReflectionFunction::class) - ->disableOriginalConstructor() - ->getMock(); + $reflectionFunction = $this->createMock(ReflectionFunction::class); $type = new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION); @@ -74,9 +68,7 @@ public function testIsMatchingReflectorReturnsFalseWhenTypeIsInvalid() $prop->setAccessible(true); $prop->setValue($classType, 'nonsense'); - $reflectionClass = $this->getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $reflectionClass = $this->createMock(ReflectionClass::class); $this->assertFalse($classType->isMatchingReflector($reflectionClass)); } diff --git a/test/unit/NodeCompiler/CompileNodeToValueTest.php b/test/unit/NodeCompiler/CompileNodeToValueTest.php index e62e3f258..4dbddaecc 100644 --- a/test/unit/NodeCompiler/CompileNodeToValueTest.php +++ b/test/unit/NodeCompiler/CompileNodeToValueTest.php @@ -150,43 +150,35 @@ public function testVariousNodeCompilations($phpCode, $expectedValue) public function testExceptionThrownWhenInvalidNodeGiven() { - $this->setExpectedException( - UnableToCompileNode::class, - 'Unable to compile expression: ' . Yield_::class - ); + $this->expectException(UnableToCompileNode::class); + $this->expectExceptionMessage('Unable to compile expression: ' . Yield_::class); (new CompileNodeToValue())->__invoke(new Yield_(), $this->getDummyContext()); } public function testExceptionThrownWhenCoalesceOperatorUsed() { - $this->setExpectedException( - UnableToCompileNode::class, - 'Unable to compile binary operator' - ); + $this->expectException(UnableToCompileNode::class); + $this->expectExceptionMessage('Unable to compile binary operator'); (new CompileNodeToValue())->__invoke(new Coalesce(new LNumber(5), new LNumber(3)), $this->getDummyContext()); } public function testExceptionThrownWhenSpaceshipOperatorUsed() { - $this->setExpectedException( - UnableToCompileNode::class, - 'Unable to compile binary operator' - ); + $this->expectException(UnableToCompileNode::class); + $this->expectExceptionMessage('Unable to compile binary operator'); (new CompileNodeToValue())->__invoke(new Spaceship(new LNumber(5), new LNumber(3)), $this->getDummyContext()); } public function testExceptionThrownWhenUndefinedConstUsed() { - $this->setExpectedException( - UnableToCompileNode::class, - 'Constant "FOO" has not been defined' - ); + $this->expectException(UnableToCompileNode::class); + $this->expectExceptionMessage('Constant "FOO" has not been defined'); (new CompileNodeToValue())->__invoke(new ConstFetch(new Name('FOO')), $this->getDummyContext()); } public function testConstantValueCompiled() { - $constName = uniqid('BETTER_REFLECTION_TEST_CONST_'); + $constName = uniqid('BETTER_REFLECTION_TEST_CONST_', true); define($constName, 123); $this->assertSame( diff --git a/test/unit/NodeCompiler/CompilerContextTest.php b/test/unit/NodeCompiler/CompilerContextTest.php index ce906020f..dd12e60bc 100644 --- a/test/unit/NodeCompiler/CompilerContextTest.php +++ b/test/unit/NodeCompiler/CompilerContextTest.php @@ -19,10 +19,8 @@ public function testCreatingContextWithoutSelf() $this->assertFalse($context->hasSelf()); $this->assertSame($reflector, $context->getReflector()); - $this->setExpectedException( - \RuntimeException::class, - 'The current context does not have a class for self' - ); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The current context does not have a class for self'); $context->getSelf(); } diff --git a/test/unit/Reflection/Adapter/ReflectionClassTest.php b/test/unit/Reflection/Adapter/ReflectionClassTest.php index 8e0f9db1f..f4e06ca3b 100644 --- a/test/unit/Reflection/Adapter/ReflectionClassTest.php +++ b/test/unit/Reflection/Adapter/ReflectionClassTest.php @@ -32,17 +32,11 @@ public function testCoreReflectionMethods($methodName) public function methodExpectationProvider() { - $mockMethod = $this->getMockBuilder(BetterReflectionMethod::class) - ->disableOriginalConstructor() - ->getMock(); + $mockMethod = $this->createMock(BetterReflectionMethod::class); - $mockProperty = $this->getMockBuilder(BetterReflectionProperty::class) - ->disableOriginalConstructor() - ->getMock(); + $mockProperty = $this->createMock(BetterReflectionProperty::class); - $mockClassLike = $this->getMockBuilder(BetterReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockClassLike = $this->createMock(BetterReflectionClass::class); return [ ['__toString', null, '', []], @@ -105,9 +99,7 @@ public function methodExpectationProvider() public function testAdapterMethods($methodName, $expectedException, $returnValue, array $args) { /* @var BetterReflectionClass|\PHPUnit_Framework_MockObject_MockObject $reflectionStub */ - $reflectionStub = $this->getMockBuilder(BetterReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $reflectionStub = $this->createMock(BetterReflectionClass::class); if (null === $expectedException) { $reflectionStub->expects($this->once()) @@ -117,7 +109,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue } if (null !== $expectedException) { - $this->setExpectedException($expectedException); + $this->expectException($expectedException); } $adapter = new ReflectionClassAdapter($reflectionStub); diff --git a/test/unit/Reflection/Adapter/ReflectionFunctionTest.php b/test/unit/Reflection/Adapter/ReflectionFunctionTest.php index 995240ab4..8c6527eac 100644 --- a/test/unit/Reflection/Adapter/ReflectionFunctionTest.php +++ b/test/unit/Reflection/Adapter/ReflectionFunctionTest.php @@ -32,9 +32,7 @@ public function testCoreReflectionMethods($methodName) public function methodExpectationProvider() { - $mockParameter = $this->getMockBuilder(BetterReflectionParameter::class) - ->disableOriginalConstructor() - ->getMock(); + $mockParameter = $this->createMock(BetterReflectionParameter::class); return [ // Inherited @@ -81,9 +79,7 @@ public function methodExpectationProvider() public function testAdapterMethods($methodName, $expectedException, $returnValue, array $args) { /* @var BetterReflectionFunction|\PHPUnit_Framework_MockObject_MockObject $reflectionStub */ - $reflectionStub = $this->getMockBuilder(BetterReflectionFunction::class) - ->disableOriginalConstructor() - ->getMock(); + $reflectionStub = $this->createMock(BetterReflectionFunction::class); if (null === $expectedException) { $reflectionStub->expects($this->once()) @@ -93,7 +89,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue } if (null !== $expectedException) { - $this->setExpectedException($expectedException); + $this->expectException($expectedException); } $adapter = new ReflectionFunctionAdapter($reflectionStub); @@ -102,7 +98,8 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue public function testExport() { - $this->setExpectedException(\Exception::class, 'Unable to export statically'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Unable to export statically'); ReflectionFunctionAdapter::export('str_replace'); } } diff --git a/test/unit/Reflection/Adapter/ReflectionMethodTest.php b/test/unit/Reflection/Adapter/ReflectionMethodTest.php index 7cccaa058..e9f0e97fc 100644 --- a/test/unit/Reflection/Adapter/ReflectionMethodTest.php +++ b/test/unit/Reflection/Adapter/ReflectionMethodTest.php @@ -33,17 +33,11 @@ public function testCoreReflectionMethods($methodName) public function methodExpectationProvider() { - $mockParameter = $this->getMockBuilder(BetterReflectionParameter::class) - ->disableOriginalConstructor() - ->getMock(); + $mockParameter = $this->createMock(BetterReflectionParameter::class); - $mockClassLike = $this->getMockBuilder(BetterReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockClassLike = $this->createMock(BetterReflectionClass::class); - $mockMethod = $this->getMockBuilder(BetterReflectionMethod::class) - ->disableOriginalConstructor() - ->getMock(); + $mockMethod = $this->createMock(BetterReflectionMethod::class); return [ // Inherited @@ -101,9 +95,7 @@ public function methodExpectationProvider() public function testAdapterMethods($methodName, $expectedException, $returnValue, array $args) { /* @var BetterReflectionMethod|\PHPUnit_Framework_MockObject_MockObject $reflectionStub */ - $reflectionStub = $this->getMockBuilder(BetterReflectionMethod::class) - ->disableOriginalConstructor() - ->getMock(); + $reflectionStub = $this->createMock(BetterReflectionMethod::class); if (null === $expectedException) { $reflectionStub->expects($this->once()) @@ -113,7 +105,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue } if (null !== $expectedException) { - $this->setExpectedException($expectedException); + $this->expectException($expectedException); } $adapter = new ReflectionMethodAdapter($reflectionStub); @@ -122,7 +114,8 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue public function testExport() { - $this->setExpectedException(\Exception::class, 'Unable to export statically'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Unable to export statically'); ReflectionMethodAdapter::export('\stdClass', 'foo'); } } diff --git a/test/unit/Reflection/Adapter/ReflectionObjectTest.php b/test/unit/Reflection/Adapter/ReflectionObjectTest.php index 4278ee094..36e2df170 100644 --- a/test/unit/Reflection/Adapter/ReflectionObjectTest.php +++ b/test/unit/Reflection/Adapter/ReflectionObjectTest.php @@ -34,17 +34,11 @@ public function testCoreReflectionMethods($methodName) public function methodExpectationProvider() { - $mockMethod = $this->getMockBuilder(BetterReflectionMethod::class) - ->disableOriginalConstructor() - ->getMock(); + $mockMethod = $this->createMock(BetterReflectionMethod::class); - $mockProperty = $this->getMockBuilder(BetterReflectionProperty::class) - ->disableOriginalConstructor() - ->getMock(); + $mockProperty = $this->createMock(BetterReflectionProperty::class); - $mockClassLike = $this->getMockBuilder(BetterReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockClassLike = $this->createMock(BetterReflectionClass::class); return [ ['__toString', null, '', []], @@ -107,9 +101,7 @@ public function methodExpectationProvider() public function testAdapterMethods($methodName, $expectedException, $returnValue, array $args) { /* @var BetterReflectionObject|\PHPUnit_Framework_MockObject_MockObject $reflectionStub */ - $reflectionStub = $this->getMockBuilder(BetterReflectionObject::class) - ->disableOriginalConstructor() - ->getMock(); + $reflectionStub = $this->createMock(BetterReflectionObject::class); if (null === $expectedException) { $reflectionStub->expects($this->once()) @@ -119,7 +111,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue } if (null !== $expectedException) { - $this->setExpectedException($expectedException); + $this->expectException($expectedException); } $adapter = new ReflectionObjectAdapter($reflectionStub); diff --git a/test/unit/Reflection/Adapter/ReflectionParameterTest.php b/test/unit/Reflection/Adapter/ReflectionParameterTest.php index 430e575cb..e30ea0504 100644 --- a/test/unit/Reflection/Adapter/ReflectionParameterTest.php +++ b/test/unit/Reflection/Adapter/ReflectionParameterTest.php @@ -33,17 +33,11 @@ public function testCoreReflectionParameters($methodName) public function methodExpectationProvider() { - $mockFunction = $this->getMockBuilder(BetterReflectionFunction::class) - ->disableOriginalConstructor() - ->getMock(); + $mockFunction = $this->createMock(BetterReflectionFunction::class); - $mockMethod = $this->getMockBuilder(BetterReflectionMethod::class) - ->disableOriginalConstructor() - ->getMock(); + $mockMethod = $this->createMock(BetterReflectionMethod::class); - $mockClassLike = $this->getMockBuilder(BetterReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockClassLike = $this->createMock(BetterReflectionClass::class); return [ ['__toString', null, '', []], @@ -78,9 +72,7 @@ public function methodExpectationProvider() public function testAdapterMethods($methodName, $expectedException, $returnValue, array $args) { /* @var BetterReflectionParameter|\PHPUnit_Framework_MockObject_MockObject $reflectionStub */ - $reflectionStub = $this->getMockBuilder(BetterReflectionParameter::class) - ->disableOriginalConstructor() - ->getMock(); + $reflectionStub = $this->createMock(BetterReflectionParameter::class); if (null === $expectedException) { $reflectionStub->expects($this->once()) @@ -90,7 +82,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue } if (null !== $expectedException) { - $this->setExpectedException($expectedException); + $this->expectException($expectedException); } $adapter = new ReflectionParameterAdapter($reflectionStub); @@ -99,7 +91,8 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue public function testExport() { - $this->setExpectedException(\Exception::class, 'Unable to export statically'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Unable to export statically'); ReflectionParameterAdapter::export('foo', 0); } } diff --git a/test/unit/Reflection/Adapter/ReflectionPropertyTest.php b/test/unit/Reflection/Adapter/ReflectionPropertyTest.php index b31000ea2..be47dfd26 100644 --- a/test/unit/Reflection/Adapter/ReflectionPropertyTest.php +++ b/test/unit/Reflection/Adapter/ReflectionPropertyTest.php @@ -32,9 +32,7 @@ public function testCoreReflectionPropertys($methodName) public function methodExpectationProvider() { - $mockClassLike = $this->getMockBuilder(BetterReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockClassLike = $this->createMock(BetterReflectionClass::class); return [ ['__toString', null, '', []], @@ -63,9 +61,7 @@ public function methodExpectationProvider() public function testAdapterMethods($methodName, $expectedException, $returnValue, array $args) { /* @var BetterReflectionProperty|\PHPUnit_Framework_MockObject_MockObject $reflectionStub */ - $reflectionStub = $this->getMockBuilder(BetterReflectionProperty::class) - ->disableOriginalConstructor() - ->getMock(); + $reflectionStub = $this->createMock(BetterReflectionProperty::class); if (null === $expectedException) { $reflectionStub->expects($this->once()) @@ -75,7 +71,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue } if (null !== $expectedException) { - $this->setExpectedException($expectedException); + $this->expectException($expectedException); } $adapter = new ReflectionPropertyAdapter($reflectionStub); @@ -84,7 +80,8 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue public function testExport() { - $this->setExpectedException(\Exception::class, 'Unable to export statically'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Unable to export statically'); ReflectionPropertyAdapter::export('foo', 0); } } diff --git a/test/unit/Reflection/ReflectionClassTest.php b/test/unit/Reflection/ReflectionClassTest.php index b10f30ef5..a8b6bc58a 100644 --- a/test/unit/Reflection/ReflectionClassTest.php +++ b/test/unit/Reflection/ReflectionClassTest.php @@ -55,16 +55,14 @@ public function testCanReflectInstance() public function testCreateFromInstanceThrowsExceptionWhenInvalidArgumentProvided() { - $this->setExpectedException( - \InvalidArgumentException::class, - 'Instance must be an instance of an object' - ); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Instance must be an instance of an object'); ReflectionClass::createFromInstance('invalid argument'); } public function testCanReflectEvaledClassWithDefaultLocator() { - $className = uniqid('foo'); + $className = uniqid('foo', false); eval('class ' . $className . '{}'); @@ -629,7 +627,7 @@ public function testIsInstance() $this->assertFalse($class->isInstance($this)); $this->assertTrue($class->isInstance(new ClassForHinting())); - $this->setExpectedException(NotAnObject::class); + $this->expectException(NotAnObject::class); $class->isInstance('foo'); } @@ -661,7 +659,7 @@ public function testIsSubclassOf() 'A subclass of a parent class (considering eventual backslashes upfront)' ); - $this->setExpectedException(NotAString::class); + $this->expectException(NotAString::class); $subExampleClass->isSubclassOf($this); } @@ -680,7 +678,7 @@ public function testImplementsInterface() $this->assertTrue($subExampleClass->implementsInterface(\E::class)); $this->assertFalse($subExampleClass->implementsInterface(\Iterator::class)); - $this->setExpectedException(NotAString::class); + $this->expectException(NotAString::class); $subExampleClass->implementsInterface($this); } @@ -751,7 +749,7 @@ public function testGetParentClassesFailsWithClassExtendingFromInterface() $class = $reflector->reflect(InvalidInheritances\ClassExtendingInterface::class); - $this->setExpectedException(NotAClassReflection::class); + $this->expectException(NotAClassReflection::class); $class->getParentClass(); } @@ -763,7 +761,7 @@ public function testGetParentClassesFailsWithClassExtendingFromTrait() $class = $reflector->reflect(InvalidInheritances\ClassExtendingTrait::class); - $this->setExpectedException(NotAClassReflection::class); + $this->expectException(NotAClassReflection::class); $class->getParentClass(); } @@ -775,7 +773,7 @@ public function testGetInterfacesFailsWithInterfaceExtendingFromClass() $class = $reflector->reflect(InvalidInheritances\InterfaceExtendingClass::class); - $this->setExpectedException(NotAnInterfaceReflection::class); + $this->expectException(NotAnInterfaceReflection::class); $class->getInterfaces(); } @@ -787,7 +785,7 @@ public function testGetInterfacesFailsWithInterfaceExtendingFromTrait() $class = $reflector->reflect(InvalidInheritances\InterfaceExtendingTrait::class); - $this->setExpectedException(NotAnInterfaceReflection::class); + $this->expectException(NotAnInterfaceReflection::class); $class->getInterfaces(); } @@ -849,7 +847,8 @@ public function testFetchingFqsenThrowsExceptionWithNonObjectName() $nameNode = new Name(['int']); - $this->setExpectedException(\Exception::class, 'Unable to determine FQSEN for named node'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Unable to determine FQSEN for named node'); $reflectionClassMethodReflection->invoke($reflection, $nameNode); } @@ -882,7 +881,7 @@ public function testExportMatchesFormat() public function testExportWithNoClassName() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); ReflectionClass::export(); } @@ -932,7 +931,7 @@ public function testCannotClone() $reflector = new ClassReflector($this->getComposerLocator()); $classInfo = $reflector->reflect('\BetterReflectionTest\Fixture\ExampleClass'); - $this->setExpectedException(Uncloneable::class); + $this->expectException(Uncloneable::class); $unused = clone $classInfo; } @@ -943,7 +942,7 @@ class Foo {} '; $classInfo = (new ClassReflector(new StringSourceLocator($php)))->reflect('Foo'); - $this->setExpectedException(ClassDoesNotExist::class); + $this->expectException(ClassDoesNotExist::class); $classInfo->getStaticPropertyValue('foo'); } @@ -955,7 +954,7 @@ public function testGetStaticPropertyValueThrowsExceptionWhenPropertyDoesNotExis $classInfo = (new ClassReflector(new SingleFileSourceLocator($staticPropertyGetSetFixture))) ->reflect(StaticPropertyGetSet\Foo::class); - $this->setExpectedException(PropertyDoesNotExist::class); + $this->expectException(PropertyDoesNotExist::class); $classInfo->getStaticPropertyValue('foo'); } @@ -967,7 +966,7 @@ public function testGetStaticPropertyValueThrowsExceptionWhenPropertyIsProtected $classInfo = (new ClassReflector(new SingleFileSourceLocator($staticPropertyGetSetFixture))) ->reflect(StaticPropertyGetSet\Bar::class); - $this->setExpectedException(PropertyNotPublic::class); + $this->expectException(PropertyNotPublic::class); $classInfo->getStaticPropertyValue('bat'); } @@ -979,7 +978,7 @@ public function testGetStaticPropertyValueThrowsExceptionWhenPropertyIsPrivate() $classInfo = (new ClassReflector(new SingleFileSourceLocator($staticPropertyGetSetFixture))) ->reflect(StaticPropertyGetSet\Bar::class); - $this->setExpectedException(PropertyNotPublic::class); + $this->expectException(PropertyNotPublic::class); $classInfo->getStaticPropertyValue('qux'); } @@ -1003,7 +1002,7 @@ class Foo {} '; $classInfo = (new ClassReflector(new StringSourceLocator($php)))->reflect('Foo'); - $this->setExpectedException(ClassDoesNotExist::class); + $this->expectException(ClassDoesNotExist::class); $classInfo->setStaticPropertyValue('foo', 'bar'); } @@ -1015,7 +1014,7 @@ public function testSetStaticPropertyValueThrowsExceptionWhenPropertyDoesNotExis $classInfo = (new ClassReflector(new SingleFileSourceLocator($staticPropertyGetSetFixture))) ->reflect(StaticPropertyGetSet\Foo::class); - $this->setExpectedException(PropertyDoesNotExist::class); + $this->expectException(PropertyDoesNotExist::class); $classInfo->setStaticPropertyValue('foo', 'bar'); } diff --git a/test/unit/Reflection/ReflectionFunctionAbstractTest.php b/test/unit/Reflection/ReflectionFunctionAbstractTest.php index ba6a345a5..e75baa197 100644 --- a/test/unit/Reflection/ReflectionFunctionAbstractTest.php +++ b/test/unit/Reflection/ReflectionFunctionAbstractTest.php @@ -32,7 +32,7 @@ class ReflectionFunctionAbstractTest extends \PHPUnit_Framework_TestCase { public function testExportThrowsException() { - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); ReflectionFunctionAbstract::export(); } @@ -51,7 +51,7 @@ public function testPopulateFunctionAbstractThrowsExceptionWithInvalidNode() $populateMethodReflection = new \ReflectionMethod(ReflectionFunctionAbstract::class, 'populateFunctionAbstract'); $populateMethodReflection->setAccessible(true); - $this->setExpectedException(InvalidAbstractFunctionNodeType::class); + $this->expectException(InvalidAbstractFunctionNodeType::class); $populateMethodReflection->invoke($abstract, $reflector, $breakNode, $locatedSource, null); } @@ -421,7 +421,7 @@ public function testCannotClone() $functionInfo = (new FunctionReflector(new StringSourceLocator($php)))->reflect('foo'); - $this->setExpectedException(Uncloneable::class); + $this->expectException(Uncloneable::class); $unused = clone $functionInfo; } @@ -512,7 +512,7 @@ public function testSetBodyFromAstWithInvalidArgumentsThrowsException() $reflector = new FunctionReflector(new StringSourceLocator($php)); $function = $reflector->reflect('foo'); - $this->setExpectedException(\TypeError::class); + $this->expectException(\TypeError::class); $function->setBodyFromAst([1]); } @@ -539,7 +539,7 @@ public function testSetBodyFromStringWithInvalidArgumentThrowsException() $reflector = new FunctionReflector(new StringSourceLocator($php)); $function = $reflector->reflect('foo'); - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $function->setBodyFromString(['foo' => 'bar']); } diff --git a/test/unit/Reflection/ReflectionMethodTest.php b/test/unit/Reflection/ReflectionMethodTest.php index 6d22328ed..e41991e57 100644 --- a/test/unit/Reflection/ReflectionMethodTest.php +++ b/test/unit/Reflection/ReflectionMethodTest.php @@ -237,7 +237,7 @@ public function testGetPrototype($class, $method, $expectedPrototype) $reflector = new ClassReflector(new SingleFileSourceLocator($fixture)); if (null === $expectedPrototype) { - $this->setExpectedException(MethodPrototypeNotFound::class); + $this->expectException(MethodPrototypeNotFound::class); } $b = $reflector->reflect($class)->getMethod($method)->getPrototype(); @@ -255,7 +255,8 @@ public function testGetMethodNodeFailsWhenNodeIsNotClassMethod() $methodNodeProp->setAccessible(true); $methodNodeProp->setValue($method, new Function_('foo')); - $this->setExpectedException(\RuntimeException::class, 'Expected a ClassMethod node'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Expected a ClassMethod node'); $method->isPublic(); } diff --git a/test/unit/Reflection/ReflectionObjectTest.php b/test/unit/Reflection/ReflectionObjectTest.php index aef279209..0d7ff3c21 100644 --- a/test/unit/Reflection/ReflectionObjectTest.php +++ b/test/unit/Reflection/ReflectionObjectTest.php @@ -36,7 +36,7 @@ private function getPhpParser() public function testExceptionThrownWhenNonObjectGiven() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); ReflectionObject::createFromInstance(123); } @@ -80,9 +80,7 @@ public function testExceptionThrownWhenInvalidInstanceGiven() $classInfo = ReflectionObject::createFromInstance($foo); - $mockClass = $this->getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockClass = $this->createMock(ReflectionClass::class); $reflectionObjectReflection = new \ReflectionObject($classInfo); @@ -94,7 +92,7 @@ public function testExceptionThrownWhenInvalidInstanceGiven() $reflectionObjectReflectionClassReflection->setAccessible(true); $reflectionObjectReflectionClassReflection->setValue($classInfo, $mockClass); - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $classInfo->getProperties(); } @@ -185,27 +183,21 @@ public function testReflectionObjectOverridesAllMethodsInReflectionClass($method public function testCreateFromNodeThrowsException() { /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $mReflector */ - $mReflector = $this->getMockBuilder(Reflector::class) - ->disableOriginalConstructor() - ->getMock(); + $mReflector = $this->createMock(Reflector::class); /** @var ClassLike|\PHPUnit_Framework_MockObject_MockObject $mClassNode */ - $mClassNode = $this->getMockBuilder(ClassLike::class) - ->disableOriginalConstructor() - ->getMock(); + $mClassNode = $this->createMock(ClassLike::class); /** @var LocatedSource|\PHPUnit_Framework_MockObject_MockObject $mLocatedSource */ - $mLocatedSource = $this->getMockBuilder(LocatedSource::class) - ->disableOriginalConstructor() - ->getMock(); + $mLocatedSource = $this->createMock(LocatedSource::class); - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); ReflectionObject::createFromNode($mReflector, $mClassNode, $mLocatedSource); } public function testCreateFromNameThrowsException() { - $this->setExpectedException(\LogicException::class); + $this->expectException(\LogicException::class); ReflectionObject::createFromName('foo'); } @@ -248,7 +240,7 @@ public function testCannotClone() { $classInfo = ReflectionObject::createFromInstance(new \stdClass()); - $this->setExpectedException(Uncloneable::class); + $this->expectException(Uncloneable::class); $unused = clone $classInfo; } } diff --git a/test/unit/Reflection/ReflectionParameterTest.php b/test/unit/Reflection/ReflectionParameterTest.php index 238cb976d..5867b4115 100644 --- a/test/unit/Reflection/ReflectionParameterTest.php +++ b/test/unit/Reflection/ReflectionParameterTest.php @@ -75,13 +75,15 @@ public function testCreateFromSpecWithFunctionName() public function testCreateFromSpecWithClosure() { - $this->setExpectedException(\Exception::class, 'Creating by closure is not supported yet'); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Creating by closure is not supported yet'); ReflectionParameter::createFromSpec(function ($a) {}, 'a'); } public function testCreateFromSpecWithInvalidArgumentThrowsException() { - $this->setExpectedException(\InvalidArgumentException::class, 'Could not create reflection from the spec given'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Could not create reflection from the spec given'); ReflectionParameter::createFromSpec(123, 'a'); } @@ -96,7 +98,7 @@ public function testImplementsReflector() public function testExportThrowsException() { - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); ReflectionParameter::export(); } @@ -143,7 +145,8 @@ public function testGetDefaultValueWhenDefaultValueNotAvailableThrowsException() $methodInfo = $classInfo->getMethod('myMethod'); $paramInfo = $methodInfo->getParameter('var'); - $this->setExpectedException(\LogicException::class, 'This parameter does not have a default value available'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('This parameter does not have a default value available'); $paramInfo->getDefaultValue(); } @@ -446,7 +449,8 @@ public function testIsDefaultValueConstantAndGetDefaultValueConstantName() $intDefault = $method->getParameter('intDefault'); $this->assertFalse($intDefault->isDefaultValueConstant()); - $this->setExpectedException(\LogicException::class, 'This parameter is not a constant default value, so cannot have a constant name'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('This parameter is not a constant default value, so cannot have a constant name'); $intDefault->getDefaultValueConstantName(); } @@ -539,7 +543,7 @@ public function testCannotClone() $methodInfo = $classInfo->getMethod('methodWithParameters'); $paramInfo = $methodInfo->getParameter('parameter1'); - $this->setExpectedException(Uncloneable::class); + $this->expectException(Uncloneable::class); $unused = clone $paramInfo; } } diff --git a/test/unit/Reflection/ReflectionPropertyTest.php b/test/unit/Reflection/ReflectionPropertyTest.php index 5341a7d47..31262bce6 100644 --- a/test/unit/Reflection/ReflectionPropertyTest.php +++ b/test/unit/Reflection/ReflectionPropertyTest.php @@ -154,7 +154,7 @@ public function testGetDocCommentReturnsEmptyStringWithNoComment() public function testExportThrowsException() { - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); ReflectionProperty::export(); } @@ -241,7 +241,7 @@ public function testCannotClone() $classInfo = $this->reflector->reflect('\BetterReflectionTest\Fixture\ExampleClass'); $publicProp = $classInfo->getProperty('publicProperty'); - $this->setExpectedException(Uncloneable::class); + $this->expectException(Uncloneable::class); $unused = clone $publicProp; } diff --git a/test/unit/SourceLocator/Ast/FindReflectionsInTreeTest.php b/test/unit/SourceLocator/Ast/FindReflectionsInTreeTest.php index d4c49da3f..b6bc99906 100644 --- a/test/unit/SourceLocator/Ast/FindReflectionsInTreeTest.php +++ b/test/unit/SourceLocator/Ast/FindReflectionsInTreeTest.php @@ -28,16 +28,13 @@ private function getAstForString($php) public function testInvokeDoesNotCallReflectNodesWhenNoNodesFoundInEmptyAst() { /** @var NodeToReflection|\PHPUnit_Framework_MockObject_MockObject $strategy */ - $strategy = $this->getMockBuilder(NodeToReflection::class) - ->disableOriginalConstructor() - ->setMethods(['__invoke']) - ->getMock(); + $strategy = $this->createMock(NodeToReflection::class); $strategy->expects($this->never()) ->method('__invoke'); /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $reflector */ - $reflector = $this->getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('assertSame( @@ -54,16 +51,13 @@ public function testInvokeDoesNotCallReflectNodesWhenNoNodesFoundInEmptyAst() public function testInvokeDoesNotCallReflectNodesWhenNoNodesFoundInPopulatedAst() { /** @var NodeToReflection|\PHPUnit_Framework_MockObject_MockObject $strategy */ - $strategy = $this->getMockBuilder(NodeToReflection::class) - ->disableOriginalConstructor() - ->setMethods(['__invoke']) - ->getMock(); + $strategy = $this->createMock(NodeToReflection::class); $strategy->expects($this->never()) ->method('__invoke'); /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $reflector */ - $reflector = $this->getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('assertSame( @@ -80,21 +74,16 @@ public function testInvokeDoesNotCallReflectNodesWhenNoNodesFoundInPopulatedAst( public function testInvokeCallsReflectNodesForClassWithoutNamespace() { /** @var NodeToReflection|\PHPUnit_Framework_MockObject_MockObject $strategy */ - $strategy = $this->getMockBuilder(NodeToReflection::class) - ->disableOriginalConstructor() - ->setMethods(['__invoke']) - ->getMock(); + $strategy = $this->createMock(NodeToReflection::class); - $mockReflection = $this->getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockReflection = $this->createMock(ReflectionClass::class); $strategy->expects($this->once()) ->method('__invoke') ->will($this->returnValue($mockReflection)); /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $reflector */ - $reflector = $this->getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('assertSame( @@ -113,21 +102,16 @@ public function testInvokeCallsReflectNodesForClassWithoutNamespace() public function testInvokeCallsReflectNodesForNamespacedClass() { /** @var NodeToReflection|\PHPUnit_Framework_MockObject_MockObject $strategy */ - $strategy = $this->getMockBuilder(NodeToReflection::class) - ->disableOriginalConstructor() - ->setMethods(['__invoke']) - ->getMock(); + $strategy = $this->createMock(NodeToReflection::class); - $mockReflection = $this->getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockReflection = $this->createMock(ReflectionClass::class); $strategy->expects($this->once()) ->method('__invoke') ->will($this->returnValue($mockReflection)); /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $reflector */ - $reflector = $this->getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('assertSame( @@ -146,21 +130,16 @@ public function testInvokeCallsReflectNodesForNamespacedClass() public function testInvokeCallsReflectNodesForFunction() { /** @var NodeToReflection|\PHPUnit_Framework_MockObject_MockObject $strategy */ - $strategy = $this->getMockBuilder(NodeToReflection::class) - ->disableOriginalConstructor() - ->setMethods(['__invoke']) - ->getMock(); + $strategy = $this->createMock(NodeToReflection::class); - $mockReflection = $this->getMockBuilder(ReflectionFunction::class) - ->disableOriginalConstructor() - ->getMock(); + $mockReflection = $this->createMock(ReflectionFunction::class); $strategy->expects($this->once()) ->method('__invoke') ->will($this->returnValue($mockReflection)); /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $reflector */ - $reflector = $this->getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('assertSame( diff --git a/test/unit/SourceLocator/Ast/LocatorTest.php b/test/unit/SourceLocator/Ast/LocatorTest.php index e96cb64fe..ccdac7fd5 100644 --- a/test/unit/SourceLocator/Ast/LocatorTest.php +++ b/test/unit/SourceLocator/Ast/LocatorTest.php @@ -74,7 +74,7 @@ public function testReflectThrowsExeptionWhenClassNotFoundAndNoNodesExist() { $php = 'setExpectedException(IdentifierNotFound::class); + $this->expectException(IdentifierNotFound::class); (new Locator())->findReflection( new ClassReflector(new StringSourceLocator($php)), new LocatedSource($php, null), @@ -89,7 +89,7 @@ public function testReflectThrowsExeptionWhenClassNotFoundButNodesExist() echo 'Hello world'; "; - $this->setExpectedException(IdentifierNotFound::class); + $this->expectException(IdentifierNotFound::class); (new Locator())->findReflection( new ClassReflector(new StringSourceLocator($php)), new LocatedSource($php, null), diff --git a/test/unit/SourceLocator/Ast/Strategy/NodeToReflectionTest.php b/test/unit/SourceLocator/Ast/Strategy/NodeToReflectionTest.php index 8066d717f..c02cb3a93 100644 --- a/test/unit/SourceLocator/Ast/Strategy/NodeToReflectionTest.php +++ b/test/unit/SourceLocator/Ast/Strategy/NodeToReflectionTest.php @@ -26,7 +26,7 @@ private function getFirstAstNodeInString($php) public function testReturnsReflectionForClassNode() { /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $reflector */ - $reflector = $this->getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('getMock(Reflector::class); + $reflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('setExpectedException($expectedException, $expectedMessage); + $this->expectException($expectedException); + $this->expectExceptionMessage($expectedMessage); new LocatedSource($source, $file); } public function testConstructorThrowsExceptionIfEmptyFileGiven() { - $this->setExpectedException(InvalidFileLocation::class, 'Filename was empty'); + $this->expectException(InvalidFileLocation::class); + $this->expectExceptionMessage('Filename was empty'); new LocatedSource('setExpectedException(InvalidFileLocation::class, 'File does not exist'); + $this->expectException(InvalidFileLocation::class); + $this->expectExceptionMessage('File does not exist'); new LocatedSource('setExpectedException(InvalidFileLocation::class, 'Is not a file'); + $this->expectException(InvalidFileLocation::class); + $this->expectExceptionMessage('Is not a file'); new LocatedSource('setExpectedException(InvalidFileLocation::class, 'File is not readable'); + $this->expectException(InvalidFileLocation::class); + $this->expectExceptionMessage('File is not readable'); try { new LocatedSource('getMock(Reflector::class); + $mockReflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockReflection = $this->createMock(ReflectionClass::class); /** @var AstLocator|\PHPUnit_Framework_MockObject_MockObject $astLocator */ - $astLocator = $this->getMockBuilder(AstLocator::class) - ->setMethods(['findReflection']) - ->getMock(); + $astLocator = $this->createMock(AstLocator::class); $astLocator->expects($this->once()) ->method('findReflection') @@ -56,14 +52,12 @@ public function testLocateIdentifierCallsFindReflection() public function testLocateIdentifierReturnsNullWithoutTryingToFindReflectionWhenUnableToLocateSource() { /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $mockReflector */ - $mockReflector = $this->getMock(Reflector::class); + $mockReflector = $this->createMock(Reflector::class); $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS)); /** @var AstLocator|\PHPUnit_Framework_MockObject_MockObject $astLocator */ - $astLocator = $this->getMockBuilder(AstLocator::class) - ->setMethods(['findReflection']) - ->getMock(); + $astLocator = $this->createMock(AstLocator::class); $astLocator->expects($this->never()) ->method('findReflection'); @@ -85,16 +79,14 @@ public function testLocateIdentifierReturnsNullWithoutTryingToFindReflectionWhen public function testLocateIdentifierReturnsNullWhenFindLocatorThrowsException() { /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $mockReflector */ - $mockReflector = $this->getMock(Reflector::class); + $mockReflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('getMockBuilder(AstLocator::class) - ->setMethods(['findReflection']) - ->getMock(); + $astLocator = $this->createMock(AstLocator::class); $astLocator->expects($this->once()) ->method('findReflection') @@ -118,20 +110,16 @@ public function testLocateIdentifierReturnsNullWhenFindLocatorThrowsException() public function testLocateIdentifiersByTypeCallsFindReflectionsOfType() { /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $mockReflector */ - $mockReflector = $this->getMock(Reflector::class); + $mockReflector = $this->createMock(Reflector::class); $locatedSource = new LocatedSource('getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $mockReflection = $this->createMock(ReflectionClass::class); /** @var AstLocator|\PHPUnit_Framework_MockObject_MockObject $astLocator */ - $astLocator = $this->getMockBuilder(AstLocator::class) - ->setMethods(['findReflectionsOfType']) - ->getMock(); + $astLocator = $this->createMock(AstLocator::class); $astLocator->expects($this->once()) ->method('findReflectionsOfType') @@ -153,20 +141,12 @@ public function testLocateIdentifiersByTypeCallsFindReflectionsOfType() public function testLocateIdentifiersByTypeReturnsEmptyArrayWithoutTryingToFindReflectionsWhenUnableToLocateSource() { /** @var Reflector|\PHPUnit_Framework_MockObject_MockObject $mockReflector */ - $mockReflector = $this->getMock(Reflector::class); - - $locatedSource = new LocatedSource('createMock(Reflector::class); $identifierType = new IdentifierType(IdentifierType::IDENTIFIER_CLASS); - $mockReflection = $this->getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); - /** @var AstLocator|\PHPUnit_Framework_MockObject_MockObject $astLocator */ - $astLocator = $this->getMockBuilder(AstLocator::class) - ->setMethods(['findReflectionsOfType']) - ->getMock(); + $astLocator = $this->createMock(AstLocator::class); $astLocator->expects($this->never()) ->method('findReflectionsOfType'); diff --git a/test/unit/SourceLocator/Type/AggregateSourceLocatorTest.php b/test/unit/SourceLocator/Type/AggregateSourceLocatorTest.php index 008e6ea41..2a24433c2 100644 --- a/test/unit/SourceLocator/Type/AggregateSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/AggregateSourceLocatorTest.php @@ -20,13 +20,13 @@ class AggregateSourceLocatorTest extends \PHPUnit_Framework_TestCase */ private function getMockReflector() { - return $this->getMock(Reflector::class); + return $this->createMock(Reflector::class); } public function testInvokeWillTraverseAllGivenLocatorsAndFailToResolve() { - $locator1 = $this->getMock(SourceLocator::class); - $locator2 = $this->getMock(SourceLocator::class); + $locator1 = $this->createMock(SourceLocator::class); + $locator2 = $this->createMock(SourceLocator::class); $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS)); $locator1->expects($this->once())->method('locateIdentifier'); @@ -39,14 +39,12 @@ public function testInvokeWillTraverseAllGivenLocatorsAndSucceed() { $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS)); - $locator1 = $this->getMock(SourceLocator::class); - $locator2 = $this->getMock(SourceLocator::class); - $locator3 = $this->getMock(SourceLocator::class); - $locator4 = $this->getMock(SourceLocator::class); + $locator1 = $this->createMock(SourceLocator::class); + $locator2 = $this->createMock(SourceLocator::class); + $locator3 = $this->createMock(SourceLocator::class); + $locator4 = $this->createMock(SourceLocator::class); - $source3 = $this->getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $source3 = $this->createMock(ReflectionClass::class); $locator1->expects($this->once())->method('locateIdentifier'); $locator2->expects($this->once())->method('locateIdentifier'); @@ -92,18 +90,14 @@ public function testLocateIdentifiersByTypeAggregatesSource() { $identifierType = new IdentifierType; - $locator1 = $this->getMock(SourceLocator::class); - $locator2 = $this->getMock(SourceLocator::class); - $locator3 = $this->getMock(SourceLocator::class); - $locator4 = $this->getMock(SourceLocator::class); + $locator1 = $this->createMock(SourceLocator::class); + $locator2 = $this->createMock(SourceLocator::class); + $locator3 = $this->createMock(SourceLocator::class); + $locator4 = $this->createMock(SourceLocator::class); - $source2 = $this->getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $source2 = $this->createMock(ReflectionClass::class); - $source3 = $this->getMockBuilder(ReflectionClass::class) - ->disableOriginalConstructor() - ->getMock(); + $source3 = $this->createMock(ReflectionClass::class); $locator1->expects($this->once())->method('locateIdentifiersByType')->willReturn([]); $locator2->expects($this->once())->method('locateIdentifiersByType')->willReturn([$source2]); diff --git a/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php b/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php index 978fcdb96..ad5e91c5c 100644 --- a/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php @@ -24,7 +24,7 @@ class AutoloadSourceLocatorTest extends \PHPUnit_Framework_TestCase */ private function getMockReflector() { - return $this->getMock(Reflector::class); + return $this->createMock(Reflector::class); } public function testClassLoads() @@ -139,7 +139,7 @@ public function testFunctionReflectionFailsWhenFunctionNotDefined() { $reflector = new FunctionReflector(new AutoloadSourceLocator()); - $this->setExpectedException(FunctionUndefined::class); + $this->expectException(FunctionUndefined::class); $reflector->reflect('this function does not exist, hopefully'); } diff --git a/test/unit/SourceLocator/Type/ClosureSourceLocatorTest.php b/test/unit/SourceLocator/Type/ClosureSourceLocatorTest.php index 29949dd95..8690d3d8e 100644 --- a/test/unit/SourceLocator/Type/ClosureSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/ClosureSourceLocatorTest.php @@ -19,7 +19,7 @@ class ClosureSourceLocatorTest extends \PHPUnit_Framework_TestCase */ private function getMockReflector() { - return $this->getMock(Reflector::class); + return $this->createMock(Reflector::class); } public function testClosureSourceLocator() @@ -51,7 +51,8 @@ public function testLocateIdentifiersByTypeIsNotImplemented() $locator = new ClosureSourceLocator($closure); - $this->setExpectedException(\LogicException::class, 'Not implemented'); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Not implemented'); $locator->locateIdentifiersByType( $this->getMockReflector(), new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION) @@ -64,7 +65,7 @@ public function testTwoClosuresSameLineFails() $locator = new ClosureSourceLocator($closure1); - $this->setExpectedException(TwoClosuresOneLine::class); + $this->expectException(TwoClosuresOneLine::class); $locator->locateIdentifier( $this->getMockReflector(), diff --git a/test/unit/SourceLocator/Type/ComposerSourceLocatorTest.php b/test/unit/SourceLocator/Type/ComposerSourceLocatorTest.php index e9b06487e..a89d4a1a8 100644 --- a/test/unit/SourceLocator/Type/ComposerSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/ComposerSourceLocatorTest.php @@ -19,7 +19,7 @@ class ComposerSourceLocatorTest extends \PHPUnit_Framework_TestCase */ private function getMockReflector() { - return $this->getMock(Reflector::class); + return $this->createMock(Reflector::class); } public function testInvokableLoadsSource() @@ -27,9 +27,7 @@ public function testInvokableLoadsSource() $className = 'ClassWithNoNamespace'; $fileName = __DIR__ . '/../../Fixture/NoNamespace.php'; - $loader = $this->getMockBuilder(ClassLoader::class) - ->setMethods(['findFile']) - ->getMock(); + $loader = $this->createMock(ClassLoader::class); $loader ->expects($this->once()) @@ -52,9 +50,7 @@ public function testInvokableThrowsExceptionWhenClassNotResolved() { $className = ClassWithNoNamespace::class; - $loader = $this->getMockBuilder(ClassLoader::class) - ->setMethods(['findFile']) - ->getMock(); + $loader = $this->createMock(ClassLoader::class); $loader ->expects($this->once()) @@ -73,7 +69,7 @@ public function testInvokableThrowsExceptionWhenClassNotResolved() public function testInvokeThrowsExceptionWhenTryingToLocateFunction() { - $loader = $this->getMock(ClassLoader::class); + $loader = $this->createMock(ClassLoader::class); /** @var ClassLoader $loader */ $locator = new ComposerSourceLocator($loader); diff --git a/test/unit/SourceLocator/Type/EvaledCodeSourceLocatorTest.php b/test/unit/SourceLocator/Type/EvaledCodeSourceLocatorTest.php index abf14b36b..4e811ca37 100644 --- a/test/unit/SourceLocator/Type/EvaledCodeSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/EvaledCodeSourceLocatorTest.php @@ -20,7 +20,7 @@ class EvaledCodeSourceLocatorTest extends \PHPUnit_Framework_TestCase */ private function getMockReflector() { - return $this->getMock(Reflector::class); + return $this->createMock(Reflector::class); } public function testCanReflectEvaledClass() diff --git a/test/unit/SourceLocator/Type/PhpInternalSourceLocatorTest.php b/test/unit/SourceLocator/Type/PhpInternalSourceLocatorTest.php index 996cee547..3bc15c204 100644 --- a/test/unit/SourceLocator/Type/PhpInternalSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/PhpInternalSourceLocatorTest.php @@ -23,7 +23,7 @@ class PhpInternalSourceLocatorTest extends \PHPUnit_Framework_TestCase */ private function getMockReflector() { - return $this->getMock(Reflector::class); + return $this->createMock(Reflector::class); } /** diff --git a/test/unit/SourceLocator/Type/SingleFileSourceLocatorTest.php b/test/unit/SourceLocator/Type/SingleFileSourceLocatorTest.php index 01c0cdcb3..cce6e77a9 100644 --- a/test/unit/SourceLocator/Type/SingleFileSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/SingleFileSourceLocatorTest.php @@ -18,7 +18,7 @@ class SingleFileSourceLocatorTest extends \PHPUnit_Framework_TestCase */ private function getMockReflector() { - return $this->getMock(Reflector::class); + return $this->createMock(Reflector::class); } public function testReturnsNullWhenSourceDoesNotContainClass() @@ -55,19 +55,22 @@ public function testReturnsReflectionWhenSourceHasClass() public function testConstructorThrowsExceptionIfEmptyFileGiven() { - $this->setExpectedException(InvalidFileLocation::class, 'Filename was empty'); + $this->expectException(InvalidFileLocation::class); + $this->expectExceptionMessage('Filename was empty'); new SingleFileSourceLocator(''); } public function testConstructorThrowsExceptionIfFileDoesNotExist() { - $this->setExpectedException(InvalidFileLocation::class, 'File does not exist'); + $this->expectException(InvalidFileLocation::class); + $this->expectExceptionMessage('File does not exist'); new SingleFileSourceLocator('sdklfjdfslsdfhlkjsdglkjsdflgkj'); } public function testConstructorThrowsExceptionIfFileIsNotAFile() { - $this->setExpectedException(InvalidFileLocation::class, 'Is not a file'); + $this->expectException(InvalidFileLocation::class); + $this->expectExceptionMessage('Is not a file'); new SingleFileSourceLocator(__DIR__); } } diff --git a/test/unit/SourceLocator/Type/StringSourceLocatorTest.php b/test/unit/SourceLocator/Type/StringSourceLocatorTest.php index 734e40e38..af5b76d28 100644 --- a/test/unit/SourceLocator/Type/StringSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/StringSourceLocatorTest.php @@ -18,7 +18,7 @@ class StringSourceLocatorTest extends \PHPUnit_Framework_TestCase */ private function getMockReflector() { - return $this->getMock(Reflector::class); + return $this->createMock(Reflector::class); } public function testReturnsNullWhenSourceDoesNotContainClass() @@ -55,7 +55,7 @@ public function testReturnsReflectionWhenSourceHasClass() public function testConstructorThrowsExceptionIfEmptyStringGiven() { - $this->setExpectedException(EmptyPhpSourceCode::class); + $this->expectException(EmptyPhpSourceCode::class); new StringSourceLocator(''); } } diff --git a/test/unit/TypesFinder/FindParameterTypeTest.php b/test/unit/TypesFinder/FindParameterTypeTest.php index 26a6f4c2f..bed1a95a4 100644 --- a/test/unit/TypesFinder/FindParameterTypeTest.php +++ b/test/unit/TypesFinder/FindParameterTypeTest.php @@ -66,10 +66,7 @@ public function testFindParameterTypeForFunction($docBlock, $nodeName, $expected $node = new ParamNode($nodeName); $docBlock = "/**\n * $docBlock\n */"; - $function = $this->getMockBuilder(ReflectionFunction::class) - ->setMethods(['getDocComment', 'getLocatedSource']) - ->disableOriginalConstructor() - ->getMock(); + $function = $this->createMock(ReflectionFunction::class); $function ->expects($this->once()) @@ -102,20 +99,14 @@ public function testFindParameterTypeForMethod($docBlock, $nodeName, $expectedIn $node = new ParamNode($nodeName); $docBlock = "/**\n * $docBlock\n */"; - $class = $this->getMockBuilder(ReflectionClass::class) - ->setMethods(['getLocatedSource']) - ->disableOriginalConstructor() - ->getMock(); + $class = $this->createMock(ReflectionClass::class); $class ->expects($this->once()) ->method('getLocatedSource') ->will($this->returnValue(new LocatedSource('getMockBuilder(ReflectionMethod::class) - ->setMethods(['getDocComment', 'getDeclaringClass']) - ->disableOriginalConstructor() - ->getMock(); + $method = $this->createMock(ReflectionMethod::class); $method ->expects($this->once()) diff --git a/test/unit/TypesFinder/FindPropertyTypeTest.php b/test/unit/TypesFinder/FindPropertyTypeTest.php index aa751782a..2a155afd1 100644 --- a/test/unit/TypesFinder/FindPropertyTypeTest.php +++ b/test/unit/TypesFinder/FindPropertyTypeTest.php @@ -36,10 +36,7 @@ public function propertyTypeProvider() */ public function testFindPropertyType($docBlock, $expectedInstances) { - $class = $this->getMockBuilder(ReflectionClass::class) - ->setMethods(['getNamespaceName', 'getLocatedSource']) - ->disableOriginalConstructor() - ->getMock(); + $class = $this->createMock(ReflectionClass::class); $class->expects($this->any())->method('getNamespaceName') ->will($this->returnValue('')); @@ -47,10 +44,7 @@ public function testFindPropertyType($docBlock, $expectedInstances) $class->expects($this->any())->method('getLocatedSource') ->will($this->returnValue(new LocatedSource('getMockBuilder(ReflectionProperty::class) - ->setMethods(['getDeclaringClass', 'getDocComment']) - ->disableOriginalConstructor() - ->getMock(); + $property = $this->createMock(ReflectionProperty::class); $property->expects($this->any())->method('getDeclaringClass') ->will($this->returnValue($class)); @@ -93,10 +87,7 @@ class ThingThatLogs public function testFindPropertyTypeReturnsEmptyArrayWhenNoCommentsNodesFound() { - $class = $this->getMockBuilder(ReflectionClass::class) - ->setMethods(['getNamespaceName', 'getLocatedSource']) - ->disableOriginalConstructor() - ->getMock(); + $class = $this->createMock(ReflectionClass::class); $class->expects($this->any())->method('getNamespaceName') ->will($this->returnValue('')); @@ -104,10 +95,7 @@ public function testFindPropertyTypeReturnsEmptyArrayWhenNoCommentsNodesFound() $class->expects($this->any())->method('getLocatedSource') ->will($this->returnValue(new LocatedSource('getMockBuilder(ReflectionProperty::class) - ->setMethods(['getDeclaringClass', 'getDocComment']) - ->disableOriginalConstructor() - ->getMock(); + $property = $this->createMock(ReflectionProperty::class); $property->expects($this->any())->method('getDeclaringClass') ->will($this->returnValue($class)); diff --git a/test/unit/TypesFinder/FindReturnTypeTest.php b/test/unit/TypesFinder/FindReturnTypeTest.php index 570c02a87..222af44ce 100644 --- a/test/unit/TypesFinder/FindReturnTypeTest.php +++ b/test/unit/TypesFinder/FindReturnTypeTest.php @@ -38,10 +38,7 @@ public function testFindReturnTypeForFunction($docBlock, $expectedInstances) { $docBlock = "/**\n * $docBlock\n */"; - $function = $this->getMockBuilder(ReflectionFunction::class) - ->setMethods(['getDocComment', 'getLocatedSource']) - ->disableOriginalConstructor() - ->getMock(); + $function = $this->createMock(ReflectionFunction::class); $function ->expects($this->once()) @@ -72,20 +69,14 @@ public function testFindReturnTypeForMethod($docBlock, $expectedInstances) { $docBlock = "/**\n * $docBlock\n */"; - $class = $this->getMockBuilder(ReflectionClass::class) - ->setMethods(['getLocatedSource']) - ->disableOriginalConstructor() - ->getMock(); + $class = $this->createMock(ReflectionClass::class); $class ->expects($this->once()) ->method('getLocatedSource') ->will($this->returnValue(new LocatedSource('getMockBuilder(ReflectionMethod::class) - ->setMethods(['getDocComment', 'getDeclaringClass']) - ->disableOriginalConstructor() - ->getMock(); + $method = $this->createMock(ReflectionMethod::class); $method ->expects($this->once()) From b6c515171e3ab76527b205368c5e26d8b917e82e Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Fri, 16 Sep 2016 18:03:19 +0100 Subject: [PATCH 2/2] Updated dependencies to account for minimum versions --- composer.json | 6 +++--- test/unit/Reflection/ReflectionTypeTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 4b6b640b5..1ccaea0b2 100644 --- a/composer.json +++ b/composer.json @@ -6,13 +6,13 @@ "php": "^5.6|^7.0", "nikic/php-parser": "^2.0", "phpdocumentor/reflection-docblock": "^2.0", - "phpdocumentor/type-resolver": "^0.1.6", + "phpdocumentor/type-resolver": "^0.2", "zendframework/zend-code": "^3.0", "jeremeamia/superclosure": "^2.2" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^1.11", - "phpunit/phpunit": "^5.2" + "friendsofphp/php-cs-fixer": "^1.12", + "phpunit/phpunit": "^5.4" }, "autoload": { "psr-4": { diff --git a/test/unit/Reflection/ReflectionTypeTest.php b/test/unit/Reflection/ReflectionTypeTest.php index 844511410..41cf3a765 100644 --- a/test/unit/Reflection/ReflectionTypeTest.php +++ b/test/unit/Reflection/ReflectionTypeTest.php @@ -50,7 +50,7 @@ public function testImplicitCastToString() $this->assertSame('callable', (string)ReflectionType::createFromType(new Types\Callable_(), false)); $this->assertSame('bool', (string)ReflectionType::createFromType(new Types\Boolean(), false)); $this->assertSame('float', (string)ReflectionType::createFromType(new Types\Float_(), false)); - $this->assertSame('void', (string)ReflectionType::createFromType(new Types\Void(), false)); + $this->assertSame('void', (string)ReflectionType::createFromType(new Types\Void_(), false)); $this->assertSame('\Foo\Bar\Baz', (string)ReflectionType::createFromType( new Types\Object_(new Fqsen('\Foo\Bar\Baz')),