From f5e5add13e73933c65878f53d5a94cdc0f120cc4 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 19 Nov 2018 10:54:06 +0100 Subject: [PATCH] Closes #3288 --- .php_cs.dist | 2 +- ChangeLog-8.0.md | 4 ++++ .../MockObject/Matcher/StatelessInvocation.php | 2 +- src/Framework/TestCase.php | 16 ++++++++-------- tests/_files/ClassThatImplementsSerializable.php | 2 +- tests/_files/ClassWithAllPossibleReturnTypes.php | 2 +- tests/_files/ClassWithSelfTypeHint.php | 2 +- tests/_files/ClassWithStaticMethod.php | 2 +- tests/_files/DataproviderExecutionOrderTest.php | 8 ++++---- tests/_files/MethodCallbackByReference.php | 4 ++-- tests/_files/MultiDependencyTest.php | 4 ++-- tests/_files/PartialMockTestClass.php | 4 ++-- tests/_files/SingletonClass.php | 8 ++++---- tests/_files/SomeClass.php | 2 ++ tests/_files/StaticMockTestClass.php | 2 +- tests/_files/StopOnErrorTestSuite.php | 6 +++--- .../regression/GitHub/3093/Issue3093Test.php | 2 +- tests/unit/Framework/AssertTest.php | 4 ++-- .../unit/Framework/MockObject/GeneratorTest.php | 4 ++-- .../unit/Framework/MockObject/MockMethodTest.php | 4 ++-- 20 files changed, 45 insertions(+), 39 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 283cbfba2ea..6f8ac884920 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -184,7 +184,7 @@ return PhpCsFixer\Config::create() 'property', ], ], - //'void_return' => true, + 'void_return' => true, 'whitespace_after_comma_in_array' => true, ] ) diff --git a/ChangeLog-8.0.md b/ChangeLog-8.0.md index ad6f2f318dd..e2c97cfacb1 100644 --- a/ChangeLog-8.0.md +++ b/ChangeLog-8.0.md @@ -4,6 +4,10 @@ All notable changes of the PHPUnit 8.0 release series are documented in this fil ## [8.0.0] - 2019-02-01 +### Changed + +* Implemented [#3288](https://github.com/sebastianbergmann/phpunit/issues/3288): The `void_return` fixer of php-cs-fixer is now in effect + ### Removed * Implemented [#2762](https://github.com/sebastianbergmann/phpunit/issues/2762): Drop support for PHP 7.1 diff --git a/src/Framework/MockObject/Matcher/StatelessInvocation.php b/src/Framework/MockObject/Matcher/StatelessInvocation.php index f4e50a627cd..be8a25879d8 100644 --- a/src/Framework/MockObject/Matcher/StatelessInvocation.php +++ b/src/Framework/MockObject/Matcher/StatelessInvocation.php @@ -33,7 +33,7 @@ abstract class StatelessInvocation implements Invocation * * @param BaseInvocation $invocation Object containing information on a mocked or stubbed method which was invoked */ - public function invoked(BaseInvocation $invocation) + public function invoked(BaseInvocation $invocation): void { } diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 0d30afc49ae..58b9a2f6a7b 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -390,28 +390,28 @@ public function __construct($name = null, array $data = [], $dataName = '') /** * This method is called before the first test of this test class is run. */ - public static function setUpBeforeClass()/* The :void return type declaration that should be here would cause a BC issue */ + public static function setUpBeforeClass(): void { } /** * This method is called after the last test of this test class is run. */ - public static function tearDownAfterClass()/* The :void return type declaration that should be here would cause a BC issue */ + public static function tearDownAfterClass(): void { } /** * This method is called before each test. */ - protected function setUp()/* The :void return type declaration that should be here would cause a BC issue */ + protected function setUp(): void { } /** * This method is called after each test. */ - protected function tearDown()/* The :void return type declaration that should be here would cause a BC issue */ + protected function tearDown(): void { } @@ -614,7 +614,7 @@ public function expectExceptionObject(\Exception $exception): void $this->expectExceptionCode($exception->getCode()); } - public function expectNotToPerformAssertions() + public function expectNotToPerformAssertions(): void { $this->doesNotPerformAssertions = true; } @@ -1567,7 +1567,7 @@ protected function createResult(): TestResult * * This method is called between setUp() and test. */ - protected function assertPreConditions()/* The :void return type declaration that should be here would cause a BC issue */ + protected function assertPreConditions(): void { } @@ -1576,7 +1576,7 @@ protected function assertPreConditions()/* The :void return type declaration tha * * This method is called between test and tearDown(). */ - protected function assertPostConditions()/* The :void return type declaration that should be here would cause a BC issue */ + protected function assertPostConditions(): void { } @@ -1585,7 +1585,7 @@ protected function assertPostConditions()/* The :void return type declaration th * * @throws Throwable */ - protected function onNotSuccessfulTest(Throwable $t)/* The :void return type declaration that should be here would cause a BC issue */ + protected function onNotSuccessfulTest(Throwable $t): void { throw $t; } diff --git a/tests/_files/ClassThatImplementsSerializable.php b/tests/_files/ClassThatImplementsSerializable.php index d7950365407..7dbce93d1d0 100644 --- a/tests/_files/ClassThatImplementsSerializable.php +++ b/tests/_files/ClassThatImplementsSerializable.php @@ -14,7 +14,7 @@ public function serialize() return \get_object_vars($this); } - public function unserialize($serialized) + public function unserialize($serialized): void { foreach (\unserialize($serialized) as $key => $value) { $this->{$key} = $value; diff --git a/tests/_files/ClassWithAllPossibleReturnTypes.php b/tests/_files/ClassWithAllPossibleReturnTypes.php index 9af8ef07857..6bb069713b5 100644 --- a/tests/_files/ClassWithAllPossibleReturnTypes.php +++ b/tests/_files/ClassWithAllPossibleReturnTypes.php @@ -9,7 +9,7 @@ */ class ClassWithAllPossibleReturnTypes { - public function methodWithNoReturnTypeDeclaration() + public function methodWithNoReturnTypeDeclaration(): void { } diff --git a/tests/_files/ClassWithSelfTypeHint.php b/tests/_files/ClassWithSelfTypeHint.php index ee597bc4273..440237cb95c 100644 --- a/tests/_files/ClassWithSelfTypeHint.php +++ b/tests/_files/ClassWithSelfTypeHint.php @@ -9,7 +9,7 @@ */ class ClassWithSelfTypeHint { - public function foo(self $foo) + public function foo(self $foo): void { } } diff --git a/tests/_files/ClassWithStaticMethod.php b/tests/_files/ClassWithStaticMethod.php index 6b2618a3295..0940e584a15 100644 --- a/tests/_files/ClassWithStaticMethod.php +++ b/tests/_files/ClassWithStaticMethod.php @@ -9,7 +9,7 @@ */ class ClassWithStaticMethod { - public static function staticMethod() + public static function staticMethod(): void { } } diff --git a/tests/_files/DataproviderExecutionOrderTest.php b/tests/_files/DataproviderExecutionOrderTest.php index b920d7171ff..5041fd27708 100644 --- a/tests/_files/DataproviderExecutionOrderTest.php +++ b/tests/_files/DataproviderExecutionOrderTest.php @@ -11,7 +11,7 @@ class DataproviderExecutionOrderTest extends TestCase { - public function testFirstTestThatAlwaysWorks() + public function testFirstTestThatAlwaysWorks(): void { $this->assertTrue(true); } @@ -19,12 +19,12 @@ public function testFirstTestThatAlwaysWorks() /** * @dataProvider dataproviderAdditions */ - public function testAddNumbersWithADataprovider(int $a, int $b, int $sum) + public function testAddNumbersWithADataprovider(int $a, int $b, int $sum): void { $this->assertSame($sum, $a + $b); } - public function testTestInTheMiddleThatAlwaysWorks() + public function testTestInTheMiddleThatAlwaysWorks(): void { $this->assertTrue(true); } @@ -32,7 +32,7 @@ public function testTestInTheMiddleThatAlwaysWorks() /** * @dataProvider dataproviderAdditions */ - public function testAddMoreNumbersWithADataprovider(int $a, int $b, int $sum) + public function testAddMoreNumbersWithADataprovider(int $a, int $b, int $sum): void { $this->assertSame($sum, $a + $b); } diff --git a/tests/_files/MethodCallbackByReference.php b/tests/_files/MethodCallbackByReference.php index 78624e8217b..9fa4ceb56a4 100644 --- a/tests/_files/MethodCallbackByReference.php +++ b/tests/_files/MethodCallbackByReference.php @@ -9,12 +9,12 @@ */ class MethodCallbackByReference { - public function bar(&$a, &$b, $c) + public function bar(&$a, &$b, $c): void { Legacy::bar($a, $b, $c); } - public function callback(&$a, &$b, $c) + public function callback(&$a, &$b, $c): void { $b = 1; } diff --git a/tests/_files/MultiDependencyTest.php b/tests/_files/MultiDependencyTest.php index 21945dcaace..40da2ae3786 100644 --- a/tests/_files/MultiDependencyTest.php +++ b/tests/_files/MultiDependencyTest.php @@ -38,12 +38,12 @@ public function testThree($a, $b): void /** * @depends MultiDependencyTest::testThree */ - public function testFour() + public function testFour(): void { $this->assertTrue(true); } - public function testFive() + public function testFive(): void { $this->assertTrue(true); } diff --git a/tests/_files/PartialMockTestClass.php b/tests/_files/PartialMockTestClass.php index 6966588f2c2..db0add436ca 100644 --- a/tests/_files/PartialMockTestClass.php +++ b/tests/_files/PartialMockTestClass.php @@ -16,11 +16,11 @@ public function __construct() $this->constructorCalled = true; } - public function doSomething() + public function doSomething(): void { } - public function doAnotherThing() + public function doAnotherThing(): void { } } diff --git a/tests/_files/SingletonClass.php b/tests/_files/SingletonClass.php index c2549be166e..7cf874d421f 100644 --- a/tests/_files/SingletonClass.php +++ b/tests/_files/SingletonClass.php @@ -9,7 +9,7 @@ */ class SingletonClass { - public static function getInstance() + public static function getInstance(): void { } @@ -17,11 +17,11 @@ protected function __construct() { } - private function __sleep() + private function __sleep(): void { } - private function __wakeup() + private function __wakeup(): void { } @@ -29,7 +29,7 @@ private function __clone() { } - public function doSomething() + public function doSomething(): void { } } diff --git a/tests/_files/SomeClass.php b/tests/_files/SomeClass.php index 9ee1249b186..63a579071be 100644 --- a/tests/_files/SomeClass.php +++ b/tests/_files/SomeClass.php @@ -11,9 +11,11 @@ class SomeClass { public function doSomething($a, $b) { + return 'something'; } public function doSomethingElse($c) { + return 'something else'; } } diff --git a/tests/_files/StaticMockTestClass.php b/tests/_files/StaticMockTestClass.php index 9effe2ebf3f..7fca966f14b 100644 --- a/tests/_files/StaticMockTestClass.php +++ b/tests/_files/StaticMockTestClass.php @@ -9,7 +9,7 @@ */ class StaticMockTestClass { - public static function doSomething() + public static function doSomething(): void { } diff --git a/tests/_files/StopOnErrorTestSuite.php b/tests/_files/StopOnErrorTestSuite.php index 3a9d21095ec..fb8b5b540ff 100644 --- a/tests/_files/StopOnErrorTestSuite.php +++ b/tests/_files/StopOnErrorTestSuite.php @@ -10,19 +10,19 @@ class StopOnErrorTestSuite extends \PHPUnit\Framework\TestCase { - public function testIncomplete() + public function testIncomplete(): void { $this->markTestIncomplete(); } - public function testWithError() + public function testWithError(): void { $this->assertTrue(true); throw new Error('StopOnErrorTestSuite_error'); } - public function testThatIsNeverReached() + public function testThatIsNeverReached(): void { $this->assertTrue(true); } diff --git a/tests/end-to-end/regression/GitHub/3093/Issue3093Test.php b/tests/end-to-end/regression/GitHub/3093/Issue3093Test.php index 2fc50fd1364..e3773469312 100644 --- a/tests/end-to-end/regression/GitHub/3093/Issue3093Test.php +++ b/tests/end-to-end/regression/GitHub/3093/Issue3093Test.php @@ -23,7 +23,7 @@ public function testFirstWithoutDependencies(): void * @depends testFirstWithoutDependencies * @dataProvider someDataProvider */ - public function testSecondThatDependsOnFirstAndDataprovider($value) + public function testSecondThatDependsOnFirstAndDataprovider($value): void { self::assertTrue(true); } diff --git a/tests/unit/Framework/AssertTest.php b/tests/unit/Framework/AssertTest.php index 8fa34c3b46f..9b1d0512026 100644 --- a/tests/unit/Framework/AssertTest.php +++ b/tests/unit/Framework/AssertTest.php @@ -2660,7 +2660,7 @@ public function testScalarTypeCanBeAsserted(): void public function testCallableTypeCanBeAsserted(): void { - $this->assertIsCallable(function () { + $this->assertIsCallable(function (): void { }); try { @@ -2807,7 +2807,7 @@ public function testNotCallableTypeCanBeAsserted(): void $this->assertIsNotCallable(null); try { - $this->assertIsNotCallable(function () { + $this->assertIsNotCallable(function (): void { }); } catch (AssertionFailedError $e) { return; diff --git a/tests/unit/Framework/MockObject/GeneratorTest.php b/tests/unit/Framework/MockObject/GeneratorTest.php index bc39b8d10aa..a29aa7e29b7 100644 --- a/tests/unit/Framework/MockObject/GeneratorTest.php +++ b/tests/unit/Framework/MockObject/GeneratorTest.php @@ -211,7 +211,7 @@ public function testMockingOfThrowable(): void $this->assertInstanceOf(MockObject::class, $stub); } - public function testVariadicArgumentsArePassedToOriginalMethod() + public function testVariadicArgumentsArePassedToOriginalMethod(): void { /** @var ClassWithVariadicArgumentMethod|MockObject $mock */ $mock = $this->generator->getMock( @@ -230,7 +230,7 @@ public function testVariadicArgumentsArePassedToOriginalMethod() $this->assertSame($arguments, $mock->foo(...$arguments)); } - public function testVariadicArgumentsArePassedToMockedMethod() + public function testVariadicArgumentsArePassedToMockedMethod(): void { /** @var ClassWithVariadicArgumentMethod|MockObject $mock */ $mock = $this->createMock(ClassWithVariadicArgumentMethod::class); diff --git a/tests/unit/Framework/MockObject/MockMethodTest.php b/tests/unit/Framework/MockObject/MockMethodTest.php index f9e74ff17fb..df4165221da 100644 --- a/tests/unit/Framework/MockObject/MockMethodTest.php +++ b/tests/unit/Framework/MockObject/MockMethodTest.php @@ -14,7 +14,7 @@ class MockMethodTest extends TestCase { - public function testGetNameReturnsMethodName() + public function testGetNameReturnsMethodName(): void { $method = new MockMethod( 'ClassName', @@ -33,7 +33,7 @@ public function testGetNameReturnsMethodName() $this->assertEquals('methodName', $method->getName()); } - public function testFailWhenReturnTypeIsParentButThereIsNoParentClass() + public function testFailWhenReturnTypeIsParentButThereIsNoParentClass(): void { $method = new MockMethod( \stdClass::class,