Skip to content

Commit

Permalink
Merge pull request #153 from biozshock/phpunit-9
Browse files Browse the repository at this point in the history
Support for new PHPUnit 9 value object configuration
  • Loading branch information
DonCallisto committed Jan 16, 2021
2 parents f2c779c + 99d2c5e commit ef1ac47
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 8 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ php:

env:
matrix:
- PREFER_LOWEST="--prefer-lowest"
- PREFER_LOWEST=""
- PREFER_LOWEST="--prefer-lowest" PHPUNIT_VERSION="^8.2"
- PREFER_LOWEST="" PHPUNIT_VERSION="^8.2"
- PREFER_LOWEST="" PHPUNIT_VERSION="~9.0"
- PREFER_LOWEST="" PHPUNIT_VERSION="~9.3"
- PREFER_LOWEST="" PHPUNIT_VERSION="~9.5"

cache:
directories:
- $HOME/.composer/cache

before_script:
- phpenv config-rm xdebug.ini
- composer selfupdate
- composer require "phpunit/phpunit:^8.2" --no-update;
- composer require "phpunit/phpunit:$PHPUNIT_VERSION" --no-update;
- composer update $PREFER_LOWEST

script:
Expand Down
2 changes: 1 addition & 1 deletion adapters/Behat/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function theConsoleOutputShouldHaveLinesEndingIn(PyStringNode $string)
*/
public function theConsoleOutputShouldContain($string)
{
\PHPUnit\Framework\Assert::assertContains($string, $this->lastBehatStdOut);
\PHPUnit\Framework\Assert::assertStringContainsString($string, $this->lastBehatStdOut);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion adapters/Behat2/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function theConsoleOutputShouldHaveLinesEndingIn(PyStringNode $string)
*/
public function theConsoleOutputShouldContain($string)
{
\PHPUnit\Framework\Assert::assertContains($string, $this->lastBehatStdOut);
\PHPUnit\Framework\Assert::assertStringContainsString($string, $this->lastBehatStdOut);
}

/**
Expand Down
21 changes: 20 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,23 @@ parameters:
- phpstan-stub/Symfony/Component/Process/Exception/LogicException.stub
reportUnmatchedIgnoredErrors: false
ignoreErrors: #see https://github.com/phpstan/phpstan/issues/1267#issuecomment-552874947 -> @todo remove when sf 3.4 support ends
- "#^Call to an undefined static method #"
- "#^Call to an undefined static method #"
# @todo remove when phpunit 8.5 support ends
- message: '#^Call to static method getInstance\(\) on an unknown class PHPUnit\\TextUI\\(:?|Xml)Configuration\\Registry.$#'
path: src/Queue/CreateTestsQueueFromPhpUnitXML.php
- message: '#has invalid typehint type PHPUnit\\TextUI\\(:?|Xml)Configuration\\TestSuiteCollection.$#'
path: src/Queue/CreateTestsQueueFromPhpUnitXML.php
- message: '#^Call to method map\(\) on an unknown class PHPUnit\\TextUI\\(:?|Xml)Configuration\\TestSuiteMapper.$#'
path: src/Queue/CreateTestsQueueFromPhpUnitXML.php
- message: '#has invalid typehint type PHPUnit\\TextUI\\(:?|Xml)Configuration\\PHPUnit.$#'
path: src/Queue/CreateTestsQueueFromPhpUnitXML.php
- message: '#on an unknown class PHPUnit\\TextUI\\(:?|Xml)Configuration\\PHPUnit.$#'
path: src/Queue/CreateTestsQueueFromPhpUnitXML.php
- message: '#^Instantiated class PHPUnit\\TextUI\\(:?|Xml)Configuration\\TestSuiteMapper not found.$#'
path: src/Queue/CreateTestsQueueFromPhpUnitXML.php
- message: '#^Call to method load\(\) on an unknown class PHPUnit\\TextUI\\XmlConfiguration\\Loader.$#'
path: src/Queue/CreateTestsQueueFromPhpUnitXML.php
- message: '#^Instantiated class PHPUnit\\TextUI\\XmlConfiguration\\Loader not found.$#'
path: src/Queue/CreateTestsQueueFromPhpUnitXML.php
- message: '#^Call to static method getInstance\(\) on an unknown class PHPUnit\\Util\\Configuration.$#'
path: src/Queue/CreateTestsQueueFromPhpUnitXML.php
69 changes: 69 additions & 0 deletions src/Queue/CreateTestsQueueFromPhpUnitXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ class CreateTestsQueueFromPhpUnitXML
{
public static function execute(string $xmlFile): TestsQueue
{
// phpunit 9.0 compatibility
if (class_exists('\PHPUnit\TextUI\Configuration\Configuration')) {
$configuration = \PHPUnit\TextUI\Configuration\Registry::getInstance()->get($xmlFile);

$testSuites = new TestsQueue();

self::handlePhpUnitBootstrapV90($configuration->phpunit());
self::processTestSuiteCollectionV90($testSuites, $configuration->testSuite());

return $testSuites;
}

// phpunit 9.3 compatibility
if (class_exists('\PHPUnit\TextUI\XmlConfiguration\Configuration')) {
$configuration = (new \PHPUnit\TextUI\XmlConfiguration\Loader)->load($xmlFile);

$testSuites = new TestsQueue();

self::handlePhpUnitBootstrapV93($configuration->phpunit());
self::processTestSuiteCollectionV93($testSuites, $configuration->testSuite());

return $testSuites;
}

$configuration = \PHPUnit\Util\Configuration::getInstance($xmlFile);
$testSuites = new TestsQueue();

Expand Down Expand Up @@ -34,6 +58,27 @@ private static function processTestSuite(
}
}

private static function processTestSuiteCollectionV90(
TestsQueue $testSuites,
\PHPUnit\TextUI\Configuration\TestSuiteCollection $testSuiteCollection
): void {
$testSuite = (new \PHPUnit\TextUI\Configuration\TestSuiteMapper)->map($testSuiteCollection, '');
self::processTestSuite($testSuites, $testSuite->getIterator());
}

private static function processTestSuiteCollectionV93(
TestsQueue $testSuites,
\PHPUnit\TextUI\XmlConfiguration\TestSuiteCollection $testSuiteCollection
): void {
// phpunit 9.5 compatibility
if (class_exists('\PHPUnit\TextUI\TestSuiteMapper')) {
$testSuite = (new \PHPUnit\TextUI\TestSuiteMapper)->map($testSuiteCollection, '');
} else {
$testSuite = (new \PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper)->map($testSuiteCollection, '');
}
self::processTestSuite($testSuites, $testSuite->getIterator());
}

/**
* @param TestsQueue $testSuites
* @param \PHPUnit\Framework\TestSuite<\PHPUnit\Framework\Test>|\PHPUnit\Framework\TestCase $testSuite
Expand Down Expand Up @@ -65,4 +110,28 @@ private static function handleBootstrap(array $config): void

\PHPUnit\Util\FileLoader::checkAndLoad($filename);
}

/**
* Loads a bootstrap file.
*
* @param \PHPUnit\TextUI\Configuration\PHPUnit $PHPUnit The Phpunit config
*/
private static function handlePhpUnitBootstrapV90(\PHPUnit\TextUI\Configuration\PHPUnit $PHPUnit): void
{
$filename = $PHPUnit->hasBootstrap() ? $PHPUnit->bootstrap() : 'vendor/autoload.php';

\PHPUnit\Util\FileLoader::checkAndLoad($filename);
}

/**
* Loads a bootstrap file.
*
* @param \PHPUnit\TextUI\XmlConfiguration\PHPUnit $PHPUnit The Phpunit config
*/
private static function handlePhpUnitBootstrapV93(\PHPUnit\TextUI\XmlConfiguration\PHPUnit $PHPUnit): void
{
$filename = $PHPUnit->hasBootstrap() ? $PHPUnit->bootstrap() : 'vendor/autoload.php';

\PHPUnit\Util\FileLoader::checkAndLoad($filename);
}
}
3 changes: 1 addition & 2 deletions tests/Process/ProcessesManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public function shouldCreate6ProcessesGivingThemTheCorrectEnvParameters(): void
->method('getIndexesOfCompletedChannel')
->willReturn(range(1, 3));
$processes->expects($this->any())
->method('add')
->willReturn(true);
->method('add');
$processes->expects($this->any())
->method('start')
->willReturn(true);
Expand Down

0 comments on commit ef1ac47

Please sign in to comment.