From 7685ed8dd3c2d6153828e8f75d05fbbf6dbcf467 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Sat, 23 Mar 2019 06:46:28 +0900 Subject: [PATCH] PHPUnit 8 future-proofing on Travis CI (#668) * PHPUnit 8 compatibility * PHPUnit 8 future-proofing on Travis CI --- .travis.yml | 11 +++++++++++ tests/AutoReview/ProjectCodeTest.php | 12 +++++------- tests/Console/E2ETest.php | 8 ++++++-- tests/Console/LogVerbosityTest.php | 2 +- tests/Finder/Exception/FinderExceptionTest.php | 10 +++++----- tests/Finder/TestFrameworkFinderTest.php | 2 +- tests/Mutator/Operator/CoalesceTest.php | 2 +- tests/Performance/Time/TimerTest.php | 2 +- tests/Process/Builder/ProcessBuilderTest.php | 4 ++-- tests/StreamWrapper/IncludeInterceptorTest.php | 2 +- .../Config/Builder/MutationConfigBuilderTest.php | 2 +- .../Config/Builder/MutationConfigBuilderTest.php | 4 ++-- .../InvalidPhpUnitXmlConfigExceptionTest.php | 2 +- 13 files changed, 38 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 79d594b89..809211b9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -147,6 +147,17 @@ jobs: INFECTION_PR_FLAGS=$(get-infection-pr-flags); phpdbg -qrr bin/infection $INFECTION_FLAGS $INFECTION_PR_FLAGS; + - stage: PHPUnit 8 future-proofing + php: 7.2 + env: PHPUNIT_BIN='vendor/bin/phpunit' + install: + - composer config --unset platform.php + - composer require --dev phpunit/phpunit:^8 --no-update + - composer update + script: + - if [[ $PHPDBG != 1 ]]; then xdebug-enable; fi + - if [[ $PHPDBG != 1 ]]; then $PHPUNIT_BIN; else phpdbg -qrr $PHPUNIT_BIN; fi + - stage: Deploy php: 7.2 install: diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index 96a394de6..972fad4a4 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -246,7 +246,7 @@ public function test_non_extension_points_are_internal(string $className): void ) ); } - $this->assertNotContains( + $this->assertStringNotContainsString( '@internal', $docBlock, sprintf( @@ -258,15 +258,14 @@ public function test_non_extension_points_are_internal(string $className): void return; } - $this->assertInternalType( - 'string', + $this->assertIsString( $docBlock, sprintf( 'The "%s" class is not an extension point, and should be marked as internal.', $className ) ); - $this->assertContains( + $this->assertStringContainsString( '@internal', $docBlock, sprintf( @@ -389,15 +388,14 @@ public function test_all_test_classes_are_marked_internal(string $className): vo $rc = new \ReflectionClass($className); $docBlock = $rc->getDocComment(); - $this->assertInternalType( - 'string', + $this->assertIsString( $docBlock, sprintf( 'Test class "%s" must be marked internal.', $className ) ); - $this->assertContains( + $this->assertStringContainsString( '@internal', $rc->getDocComment(), sprintf( diff --git a/tests/Console/E2ETest.php b/tests/Console/E2ETest.php index d2bf4c224..10725d9c4 100644 --- a/tests/Console/E2ETest.php +++ b/tests/Console/E2ETest.php @@ -78,6 +78,10 @@ protected function setUp(): void $this->markTestSkipped('This test needs copious amounts of virtual memory. It will fail unless it is allowed to overcommit memory.'); } + if (\version_compare(\PHPUnit\Runner\Version::id(), '8', '>=')) { + $this->markTestSkipped('Most E2E tests use an earlier version of PHPUnit, which is incompatible with PHPUnit 8 and later'); + } + // E2E tests usually require to chdir to their location // Hence we would need to go back to this dir $this->cwd = getcwd(); @@ -129,7 +133,7 @@ public function test_it_runs_configure_command_if_no_configuration(): void $output = $this->runInfection(self::EXPECT_ERROR); - $this->assertContains(ConfigureCommand::NONINTERACTIVE_MODE_ERROR, $output); + $this->assertStringContainsString(ConfigureCommand::NONINTERACTIVE_MODE_ERROR, $output); } /** @@ -155,7 +159,7 @@ public function e2eTestSuiteDataProvider(): \Generator continue; } - yield basename((string) $dirName) => [$dirName]; + yield basename((string) $dirName) => [(string) $dirName]; } } diff --git a/tests/Console/LogVerbosityTest.php b/tests/Console/LogVerbosityTest.php index d015ab6df..8302a4e34 100644 --- a/tests/Console/LogVerbosityTest.php +++ b/tests/Console/LogVerbosityTest.php @@ -57,7 +57,7 @@ public function test_it_works_if_verbosity_is_valid(): void /** * @dataProvider provideConvertedLogVerbosity */ - public function test_it_converts_int_version_to_string_version_of_verbosity(int $input, string $output): void + public function test_it_converts_int_version_to_string_version_of_verbosity($input, string $output): void { $input = $this->setInputExpectationsWhenItDoesChange($input, $output); $io = $this->createMock(SymfonyStyle::class); diff --git a/tests/Finder/Exception/FinderExceptionTest.php b/tests/Finder/Exception/FinderExceptionTest.php index 1d6266eb0..84f792b57 100644 --- a/tests/Finder/Exception/FinderExceptionTest.php +++ b/tests/Finder/Exception/FinderExceptionTest.php @@ -48,7 +48,7 @@ public function test_composer_not_found_exception(): void $exception = FinderException::composerNotFound(); $this->assertInstanceOf(FinderException::class, $exception); - $this->assertContains( + $this->assertStringContainsString( 'Unable to locate a Composer executable on local system', $exception->getMessage() ); @@ -59,7 +59,7 @@ public function test_php_executable_not_found(): void $exception = FinderException::phpExecutableNotFound(); $this->assertInstanceOf(FinderException::class, $exception); - $this->assertContains( + $this->assertStringContainsString( 'Unable to locate the PHP executable on the local system', $exception->getMessage() ); @@ -70,11 +70,11 @@ public function test_test_framework_not_found(): void $exception = FinderException::testFrameworkNotFound('framework'); $this->assertInstanceOf(FinderException::class, $exception); - $this->assertContains( + $this->assertStringContainsString( 'Unable to locate a framework executable on local system.', $exception->getMessage() ); - $this->assertContains( + $this->assertStringContainsString( 'Ensure that framework is installed and available.', $exception->getMessage() ); @@ -85,7 +85,7 @@ public function test_test_custom_path_does_not_exsist(): void $exception = FinderException::testCustomPathDoesNotExist('framework', 'foo/bar/abc'); $this->assertInstanceOf(FinderException::class, $exception); - $this->assertContains( + $this->assertStringContainsString( 'The custom path to framework was set as "foo/bar/abc"', $exception->getMessage() ); diff --git a/tests/Finder/TestFrameworkFinderTest.php b/tests/Finder/TestFrameworkFinderTest.php index 720868a1f..be3ce8705 100644 --- a/tests/Finder/TestFrameworkFinderTest.php +++ b/tests/Finder/TestFrameworkFinderTest.php @@ -157,7 +157,7 @@ public function test_it_adds_vendor_bin_to_path_if_needed(): void // Vendor bin should be the first item $pathList = explode(PATH_SEPARATOR, $pathAfterTest); - $this->assertContains('vendor', $pathList[0]); + $this->assertStringContainsString('vendor', $pathList[0]); $this->assertNotSame($path, $pathAfterTest); diff --git a/tests/Mutator/Operator/CoalesceTest.php b/tests/Mutator/Operator/CoalesceTest.php index 1dadbd54f..e51593ba3 100644 --- a/tests/Mutator/Operator/CoalesceTest.php +++ b/tests/Mutator/Operator/CoalesceTest.php @@ -126,7 +126,7 @@ public function provideMutationCases(): \Generator PHP ]; - yield 'Mutate coalesce with variable as second argument' => [ + yield 'Mutate coalesce with constants in a conditional' => [ <<<'PHP' timer->start(); $timeInSeconds = $this->timer->stop(); - $this->assertInternalType('float', $timeInSeconds); + $this->assertIsFloat($timeInSeconds); $this->assertGreaterThanOrEqual(0, $timeInSeconds); } diff --git a/tests/Process/Builder/ProcessBuilderTest.php b/tests/Process/Builder/ProcessBuilderTest.php index ab689d537..13f377427 100644 --- a/tests/Process/Builder/ProcessBuilderTest.php +++ b/tests/Process/Builder/ProcessBuilderTest.php @@ -57,7 +57,7 @@ public function test_getProcessForInitialTestRun_has_no_timeout(): void $process = $builder->getProcessForInitialTestRun('', false); - $this->assertContains('/usr/bin/php', $process->getCommandLine()); + $this->assertStringContainsString('/usr/bin/php', $process->getCommandLine()); $this->assertNull($process->getTimeout()); } @@ -73,7 +73,7 @@ public function test_getProcessForMutant_has_timeout(): void $process = $builder->getProcessForMutant($this->createMock(MutantInterface::class))->getProcess(); - $this->assertContains('/usr/bin/php', $process->getCommandLine()); + $this->assertStringContainsString('/usr/bin/php', $process->getCommandLine()); $this->assertSame(100.0, $process->getTimeout()); } } diff --git a/tests/StreamWrapper/IncludeInterceptorTest.php b/tests/StreamWrapper/IncludeInterceptorTest.php index 75beb6e63..6867d5a2d 100644 --- a/tests/StreamWrapper/IncludeInterceptorTest.php +++ b/tests/StreamWrapper/IncludeInterceptorTest.php @@ -107,7 +107,7 @@ public function test_it_not_intercepts_when_not_included(): void { $before = file_get_contents(self::$files[1]); // Sanity check - $this->assertContains('1', $before); + $this->assertStringContainsString('1', $before); IncludeInterceptor::intercept(self::$files[1], self::$files[2]); IncludeInterceptor::enable(); diff --git a/tests/TestFramework/PhpSpec/Config/Builder/MutationConfigBuilderTest.php b/tests/TestFramework/PhpSpec/Config/Builder/MutationConfigBuilderTest.php index df01f2643..0c29a1640 100644 --- a/tests/TestFramework/PhpSpec/Config/Builder/MutationConfigBuilderTest.php +++ b/tests/TestFramework/PhpSpec/Config/Builder/MutationConfigBuilderTest.php @@ -116,7 +116,7 @@ public function test_it_adds_original_bootstrap_file_to_custom_autoload(): void $builder = new MutationConfigBuilder($this->tmpDir, $originalYamlConfigPath, $projectDir); $this->assertSame($this->tmpDir . '/phpspecConfiguration.a1b2c3.infection.yml', $builder->build($mutant)); - $this->assertContains( + $this->assertStringContainsString( "require_once '/project/dir/bootstrap.php';", file_get_contents($this->tmpDir . '/interceptor.phpspec.autoload.a1b2c3.infection.php') ); diff --git a/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php b/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php index 6fbf8ae11..085a8c84f 100644 --- a/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php +++ b/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php @@ -151,7 +151,7 @@ public function test_it_sets_custom_autoloader(): void ); $this->assertSame($expectedCustomAutoloadFilePath, $resultAutoLoaderFilePath); - $this->assertContains('app/autoload2.php', file_get_contents($expectedCustomAutoloadFilePath)); + $this->assertStringContainsString('app/autoload2.php', file_get_contents($expectedCustomAutoloadFilePath)); } public function test_it_sets_custom_autoloader_when_attribute_is_absent(): void @@ -181,7 +181,7 @@ public function test_it_sets_custom_autoloader_when_attribute_is_absent(): void ); $this->assertSame($expectedCustomAutoloadFilePath, $resultAutoLoaderFilePath); - $this->assertContains('vendor/autoload.php', file_get_contents($expectedCustomAutoloadFilePath)); + $this->assertStringContainsString('vendor/autoload.php', file_get_contents($expectedCustomAutoloadFilePath)); } public function test_it_sets_stop_on_failure_flag(): void diff --git a/tests/TestFramework/PhpUnit/Config/Exception/InvalidPhpUnitXmlConfigExceptionTest.php b/tests/TestFramework/PhpUnit/Config/Exception/InvalidPhpUnitXmlConfigExceptionTest.php index c8ae1689b..ac6ea2f72 100644 --- a/tests/TestFramework/PhpUnit/Config/Exception/InvalidPhpUnitXmlConfigExceptionTest.php +++ b/tests/TestFramework/PhpUnit/Config/Exception/InvalidPhpUnitXmlConfigExceptionTest.php @@ -58,6 +58,6 @@ public function test_for_xsd_schema(): void $this->assertInstanceOf(InvalidPhpUnitXmlConfigException::class, $exception); - $this->assertContains('phpunit.xml file does not pass XSD schema validation.', $exception->getMessage()); + $this->assertStringContainsString('phpunit.xml file does not pass XSD schema validation.', $exception->getMessage()); } }