From 9cd74e86037cf4d390bb98bab8c507d1f5e63d65 Mon Sep 17 00:00:00 2001 From: DonCallisto Date: Fri, 25 Mar 2022 11:49:16 +0100 Subject: [PATCH] Fixated PHPStan version --- composer.json | 4 +- phpstan.neon | 30 +---- src/Process/Processes.php | 2 +- src/Queue/CreateTestsQueueFromPhpUnitXML.php | 129 ++++++++----------- 4 files changed, 63 insertions(+), 102 deletions(-) diff --git a/composer.json b/composer.json index 7f68078..a45be68 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ }, "require-dev": { "behat/behat": "^3.6", - "phpstan/phpstan": "^0.12.99", - "phpstan/phpstan-phpunit": "^0.12.22" + "phpstan/phpstan": "1.8.11", + "phpstan/phpstan-phpunit": "1.1.3" }, "config": { "bin-dir": "bin/" diff --git a/phpstan.neon b/phpstan.neon index 501b3d1..955d7fe 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,31 +7,9 @@ parameters: - src - tests stubFiles: - - phpstan-stub/Doctrine/Common/Collections/ArrayCollection.stub #@todo To be removed in v2, when drop support for older deps - - phpstan-stub/Doctrine/Common/Collections/Collection.stub #@todo To be removed in v2, when drop support for older deps - - phpstan-stub/Doctrine/Common/Collections/Selectable.stub #@todo To be removed in v2, when drop support for older deps + - phpstan-stub/Doctrine/Common/Collections/ArrayCollection.stub #@todo To be removed when drop support for older deps + - phpstan-stub/Doctrine/Common/Collections/Collection.stub #@todo To be removed when drop support for older deps + - phpstan-stub/Doctrine/Common/Collections/Selectable.stub #@todo To be removed when drop support for older deps - phpstan-stub/Symfony/Component/Process/Process.stub - phpstan-stub/Symfony/Component/Process/Exception/ExceptionInterface.stub - - 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 #" - # @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 \ No newline at end of file + - phpstan-stub/Symfony/Component/Process/Exception/LogicException.stub \ No newline at end of file diff --git a/src/Process/Processes.php b/src/Process/Processes.php index b2b9efd..b942ef5 100644 --- a/src/Process/Processes.php +++ b/src/Process/Processes.php @@ -232,7 +232,7 @@ private function assertTerminated(int $key): void private function moveToCompletedProcesses(int $key, Process $process): void { $env = $process->getEnv(); - $suite = $env[EnvCommandCreator::ENV_TEST_ARGUMENT]; + $suite = (string) $env[EnvCommandCreator::ENV_TEST_ARGUMENT]; $number = $env[EnvCommandCreator::ENV_TEST_CHANNEL]; $numberOnThread = $env[EnvCommandCreator::ENV_TEST_IS_FIRST_ON_CHANNEL]; diff --git a/src/Queue/CreateTestsQueueFromPhpUnitXML.php b/src/Queue/CreateTestsQueueFromPhpUnitXML.php index 51e15a4..b1ff0f0 100644 --- a/src/Queue/CreateTestsQueueFromPhpUnitXML.php +++ b/src/Queue/CreateTestsQueueFromPhpUnitXML.php @@ -6,37 +6,78 @@ 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); + // phpunit 8.5 compatibility + if (class_exists('\PHPUnit\Util\Configuration')) { + $configuration = \PHPUnit\Util\Configuration::getInstance($xmlFile); + $testSuites = new TestsQueue(); + + $config = $configuration->getPHPUnitConfiguration(); + $filename = isset($config['bootstrap']) ? $config['bootstrap'] : 'vendor/autoload.php'; + + \PHPUnit\Util\FileLoader::checkAndLoad($filename); + + self::processTestSuites($testSuites, $configuration->getTestSuiteConfiguration()->getIterator()); + + return $testSuites; + } + // phpunit < 9.3 compatibility + if (class_exists('\PHPUnit\TextUI\Configuration\Registry') && class_exists('\PHPUnit\TextUI\Configuration\TestSuiteMapper')) { + $configuration = \PHPUnit\TextUI\Configuration\Registry::getInstance()->get($xmlFile); $testSuites = new TestsQueue(); - self::handlePhpUnitBootstrapV90($configuration->phpunit()); - self::processTestSuiteCollectionV90($testSuites, $configuration->testSuite()); + $PHPUnit = $configuration->phpunit(); + $filename = $PHPUnit->hasBootstrap() ? $PHPUnit->bootstrap() : 'vendor/autoload.php'; + + \PHPUnit\Util\FileLoader::checkAndLoad($filename); + + $testSuite = (new \PHPUnit\TextUI\Configuration\TestSuiteMapper)->map($configuration->testSuite(), ''); + self::processTestSuites($testSuites, $testSuite->getIterator()); return $testSuites; } // phpunit 9.3 compatibility - if (class_exists('\PHPUnit\TextUI\XmlConfiguration\Configuration')) { + if (class_exists('\PHPUnit\TextUI\XmlConfiguration\Loader') && class_exists('\PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper')) { $configuration = (new \PHPUnit\TextUI\XmlConfiguration\Loader)->load($xmlFile); $testSuites = new TestsQueue(); - self::handlePhpUnitBootstrapV93($configuration->phpunit()); - self::processTestSuiteCollectionV93($testSuites, $configuration->testSuite()); + $PHPUnit = $configuration->phpunit(); + $filename = $PHPUnit->hasBootstrap() ? $PHPUnit->bootstrap() : 'vendor/autoload.php'; + + \PHPUnit\Util\FileLoader::checkAndLoad($filename); + $testSuiteCollection = $configuration->testSuite(); + + $testSuite = (new \PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper)->map($testSuiteCollection, ''); + $iterator = $testSuite->getIterator(); + + self::processTestSuites($testSuites, $iterator); return $testSuites; } - $configuration = \PHPUnit\Util\Configuration::getInstance($xmlFile); - $testSuites = new TestsQueue(); + // phpunit > 9.3 compatibility + if (class_exists('\PHPUnit\TextUI\XmlConfiguration\Loader') && class_exists('\PHPUnit\TextUI\TestSuiteMapper')) { + $configuration = (new \PHPUnit\TextUI\XmlConfiguration\Loader)->load($xmlFile); + + $testSuites = new TestsQueue(); + + $PHPUnit = $configuration->phpunit(); + $filename = $PHPUnit->hasBootstrap() ? $PHPUnit->bootstrap() : 'vendor/autoload.php'; + + \PHPUnit\Util\FileLoader::checkAndLoad($filename); + $testSuiteCollection = $configuration->testSuite(); + + $testSuite = (new \PHPUnit\TextUI\TestSuiteMapper)->map($testSuiteCollection, ''); + $iterator = $testSuite->getIterator(); - self::handleBootstrap($configuration->getPHPUnitConfiguration()); - self::processTestSuite($testSuites, $configuration->getTestSuiteConfiguration()->getIterator()); + self::processTestSuites($testSuites, $iterator); - return $testSuites; + return $testSuites; + } + + return new TestsQueue(); } /** @@ -45,7 +86,7 @@ public static function execute(string $xmlFile): TestsQueue * * @throws \ReflectionException */ - private static function processTestSuite( + private static function processTestSuites( TestsQueue $testSuites, \Iterator $testSuiteIterator ): void { @@ -53,32 +94,11 @@ private static function processTestSuite( self::addTestFile($testSuites, $testSuite); if ($testSuite instanceof \PHPUnit\Framework\TestSuite) { - self::processTestSuite($testSuites, $testSuite->getIterator()); + self::processTestSuites($testSuites, $testSuite->getIterator()); } } } - 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 @@ -97,41 +117,4 @@ private static function addTestFile(TestsQueue $testSuites, $testSuite): void $testSuites->add($fileName); } } - - /** - * @param array $config - * - * @return void - */ - private static function handleBootstrap(array $config): void - { - /** @var string $filename */ - $filename = isset($config['bootstrap']) ? $config['bootstrap'] : 'vendor/autoload.php'; - - \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); - } }