Skip to content

Commit

Permalink
PHPUnit 8 future-proofing on Travis CI (#668)
Browse files Browse the repository at this point in the history
* PHPUnit 8 compatibility

* PHPUnit 8 future-proofing on Travis CI
  • Loading branch information
sanmai authored and maks-rafalko committed Mar 22, 2019
1 parent 334983e commit 7685ed8
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 25 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Expand Up @@ -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:
Expand Down
12 changes: 5 additions & 7 deletions tests/AutoReview/ProjectCodeTest.php
Expand Up @@ -246,7 +246,7 @@ public function test_non_extension_points_are_internal(string $className): void
)
);
}
$this->assertNotContains(
$this->assertStringNotContainsString(
'@internal',
$docBlock,
sprintf(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions tests/Console/E2ETest.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -155,7 +159,7 @@ public function e2eTestSuiteDataProvider(): \Generator
continue;
}

yield basename((string) $dirName) => [$dirName];
yield basename((string) $dirName) => [(string) $dirName];
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Console/LogVerbosityTest.php
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/Finder/Exception/FinderExceptionTest.php
Expand Up @@ -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()
);
Expand All @@ -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()
);
Expand All @@ -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()
);
Expand All @@ -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()
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Finder/TestFrameworkFinderTest.php
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Mutator/Operator/CoalesceTest.php
Expand Up @@ -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'
<?php
Expand Down
2 changes: 1 addition & 1 deletion tests/Performance/Time/TimerTest.php
Expand Up @@ -58,7 +58,7 @@ public function test_it_returns_return_seconds_on_stop(): void
$this->timer->start();
$timeInSeconds = $this->timer->stop();

$this->assertInternalType('float', $timeInSeconds);
$this->assertIsFloat($timeInSeconds);
$this->assertGreaterThanOrEqual(0, $timeInSeconds);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Process/Builder/ProcessBuilderTest.php
Expand Up @@ -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());
}

Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/StreamWrapper/IncludeInterceptorTest.php
Expand Up @@ -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();
Expand Down
Expand Up @@ -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')
);
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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());
}
}

0 comments on commit 7685ed8

Please sign in to comment.