Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixated PHPStan version #185

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
30 changes: 4 additions & 26 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
- phpstan-stub/Symfony/Component/Process/Exception/LogicException.stub
2 changes: 1 addition & 1 deletion src/Process/Processes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
129 changes: 56 additions & 73 deletions src/Queue/CreateTestsQueueFromPhpUnitXML.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -45,40 +86,19 @@ public static function execute(string $xmlFile): TestsQueue
*
* @throws \ReflectionException
*/
private static function processTestSuite(
private static function processTestSuites(
TestsQueue $testSuites,
\Iterator $testSuiteIterator
): void {
foreach ($testSuiteIterator as $testSuite) {
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
Expand All @@ -97,41 +117,4 @@ private static function addTestFile(TestsQueue $testSuites, $testSuite): void
$testSuites->add($fileName);
}
}

/**
* @param array<string, bool|string|int> $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);
}
}