Skip to content

Commit

Permalink
Merge pull request #212 from Roave/update-test-suite-deprecations
Browse files Browse the repository at this point in the history
Updated deprecated phpunit API calls in test suite
  • Loading branch information
Ocramius authored Sep 16, 2016
2 parents be5fd00 + b6c5151 commit 635e698
Show file tree
Hide file tree
Showing 33 changed files with 190 additions and 320 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 5 additions & 13 deletions test/unit/Identifier/IdentifierTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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));
}
Expand Down
26 changes: 9 additions & 17 deletions test/unit/NodeCompiler/CompileNodeToValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions test/unit/NodeCompiler/CompilerContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
18 changes: 5 additions & 13 deletions test/unit/Reflection/Adapter/ReflectionClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '', []],
Expand Down Expand Up @@ -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())
Expand All @@ -117,7 +109,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue
}

if (null !== $expectedException) {
$this->setExpectedException($expectedException);
$this->expectException($expectedException);
}

$adapter = new ReflectionClassAdapter($reflectionStub);
Expand Down
13 changes: 5 additions & 8 deletions test/unit/Reflection/Adapter/ReflectionFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -93,7 +89,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue
}

if (null !== $expectedException) {
$this->setExpectedException($expectedException);
$this->expectException($expectedException);
}

$adapter = new ReflectionFunctionAdapter($reflectionStub);
Expand All @@ -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');
}
}
21 changes: 7 additions & 14 deletions test/unit/Reflection/Adapter/ReflectionMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -113,7 +105,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue
}

if (null !== $expectedException) {
$this->setExpectedException($expectedException);
$this->expectException($expectedException);
}

$adapter = new ReflectionMethodAdapter($reflectionStub);
Expand All @@ -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');
}
}
18 changes: 5 additions & 13 deletions test/unit/Reflection/Adapter/ReflectionObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '', []],
Expand Down Expand Up @@ -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())
Expand All @@ -119,7 +111,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue
}

if (null !== $expectedException) {
$this->setExpectedException($expectedException);
$this->expectException($expectedException);
}

$adapter = new ReflectionObjectAdapter($reflectionStub);
Expand Down
21 changes: 7 additions & 14 deletions test/unit/Reflection/Adapter/ReflectionParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '', []],
Expand Down Expand Up @@ -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())
Expand All @@ -90,7 +82,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue
}

if (null !== $expectedException) {
$this->setExpectedException($expectedException);
$this->expectException($expectedException);
}

$adapter = new ReflectionParameterAdapter($reflectionStub);
Expand All @@ -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);
}
}
13 changes: 5 additions & 8 deletions test/unit/Reflection/Adapter/ReflectionPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '', []],
Expand Down Expand Up @@ -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())
Expand All @@ -75,7 +71,7 @@ public function testAdapterMethods($methodName, $expectedException, $returnValue
}

if (null !== $expectedException) {
$this->setExpectedException($expectedException);
$this->expectException($expectedException);
}

$adapter = new ReflectionPropertyAdapter($reflectionStub);
Expand All @@ -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);
}
}
Loading

0 comments on commit 635e698

Please sign in to comment.