From 602482122c9e7d053790051c4896fbc713f32597 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 5 Feb 2019 13:11:57 +0100 Subject: [PATCH 01/13] Allow PHPUnit 8; fix signatures --- .gitignore | 2 +- composer.json | 4 +- composer.lock | 69 ++++++++++--------- tests/BaseFunctionalTestCase.php | 2 +- tests/BaseIntegrationTestCase.php | 4 +- tests/BaseTestCase.php | 2 +- tests/Functional/Filter/FilterTest.php | 2 +- .../Functional/Parser/JSON/LogPrinterTest.php | 2 +- .../Process/ProcessBuilderFactoryTest.php | 2 +- tests/Unit/Process/ProcessFactoryTest.php | 2 +- 10 files changed, 46 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index d11d8b6e..86c34482 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ ._* *.tgz *.phar -.php_cs.cache +.*.cache .php_cs bin gpg diff --git a/composer.json b/composer.json index ad66371a..32897f97 100644 --- a/composer.json +++ b/composer.json @@ -25,9 +25,9 @@ "require": { "php": "^7.1", "jean85/pretty-package-versions": "^1.0.3", - "phpunit/php-code-coverage": "^4.0||^5.0||^6.0", + "phpunit/php-code-coverage": "^4.0||^5.0||^6.0||^7.0", "phpunit/php-file-iterator": "^1.0||^2.0", - "phpunit/phpunit": "^6.0.9||^7.0", + "phpunit/phpunit": "^6.0.9||^7.0||^8.0", "symfony/console": "^2.8||^3.0||^4.0", "symfony/dependency-injection": "^2.8||^3.0||^4.0", "symfony/event-dispatcher": "^2.8||^3.0||^4.0", diff --git a/composer.lock b/composer.lock index 0b154605..b2f13df2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1a4e035dab3e6111f00b570b71daaf7c", + "content-hash": "1adf25f476c4e42ff158b9ec1049cc4b", "packages": [ { "name": "doctrine/instantiator", @@ -527,40 +527,40 @@ }, { "name": "phpunit/php-code-coverage", - "version": "6.1.4", + "version": "7.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d" + "reference": "4832739a02c418397e404da6c3e4fe680b7a4de7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", - "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4832739a02c418397e404da6c3e4fe680b7a4de7", + "reference": "4832739a02c418397e404da6c3e4fe680b7a4de7", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^7.1", - "phpunit/php-file-iterator": "^2.0", + "php": "^7.2", + "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.0", + "phpunit/php-token-stream": "^3.0.1", "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^3.1 || ^4.0", + "sebastian/environment": "^4.1", "sebastian/version": "^2.0.1", "theseer/tokenizer": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^8.0" }, "suggest": { - "ext-xdebug": "^2.6.0" + "ext-xdebug": "^2.6.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "6.1-dev" + "dev-master": "7.0-dev" } }, "autoload": { @@ -586,7 +586,7 @@ "testing", "xunit" ], - "time": "2018-10-31T16:06:48+00:00" + "time": "2019-02-01T07:29:14+00:00" }, { "name": "phpunit/php-file-iterator", @@ -779,16 +779,16 @@ }, { "name": "phpunit/phpunit", - "version": "7.5.3", + "version": "8.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "2cb759721e53bc05f56487f628c6b9fbb6c18746" + "reference": "753a192050133fc649234de34d1993d87785b134" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2cb759721e53bc05f56487f628c6b9fbb6c18746", - "reference": "2cb759721e53bc05f56487f628c6b9fbb6c18746", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/753a192050133fc649234de34d1993d87785b134", + "reference": "753a192050133fc649234de34d1993d87785b134", "shasum": "" }, "require": { @@ -798,27 +798,25 @@ "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", + "ext-xmlwriter": "*", "myclabs/deep-copy": "^1.7", "phar-io/manifest": "^1.0.2", "phar-io/version": "^2.0", - "php": "^7.1", + "php": "^7.2", "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^6.0.7", + "phpunit/php-code-coverage": "^7.0", "phpunit/php-file-iterator": "^2.0.1", "phpunit/php-text-template": "^1.2.1", "phpunit/php-timer": "^2.0", "sebastian/comparator": "^3.0", "sebastian/diff": "^3.0", - "sebastian/environment": "^4.0", + "sebastian/environment": "^4.1", "sebastian/exporter": "^3.1", - "sebastian/global-state": "^2.0", + "sebastian/global-state": "^3.0", "sebastian/object-enumerator": "^3.0.3", "sebastian/resource-operations": "^2.0", "sebastian/version": "^2.0.1" }, - "conflict": { - "phpunit/phpunit-mock-objects": "*" - }, "require-dev": { "ext-pdo": "*" }, @@ -833,7 +831,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.5-dev" + "dev-master": "8.0-dev" } }, "autoload": { @@ -859,7 +857,7 @@ "testing", "xunit" ], - "time": "2019-02-01T05:24:07+00:00" + "time": "2019-02-03T17:34:56+00:00" }, { "name": "psr/container", @@ -1197,23 +1195,26 @@ }, { "name": "sebastian/global-state", - "version": "2.0.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.2", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "ext-dom": "*", + "phpunit/phpunit": "^8.0" }, "suggest": { "ext-uopz": "*" @@ -1221,7 +1222,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1244,7 +1245,7 @@ "keywords": [ "global state" ], - "time": "2017-04-27T15:39:26+00:00" + "time": "2019-02-01T05:30:01+00:00" }, { "name": "sebastian/object-enumerator", diff --git a/tests/BaseFunctionalTestCase.php b/tests/BaseFunctionalTestCase.php index f052c820..b16169a0 100644 --- a/tests/BaseFunctionalTestCase.php +++ b/tests/BaseFunctionalTestCase.php @@ -6,7 +6,7 @@ abstract class BaseFunctionalTestCase extends BaseIntegrationTestCase { - protected function setUp() + protected function setup(): void { parent::setUp(); diff --git a/tests/BaseIntegrationTestCase.php b/tests/BaseIntegrationTestCase.php index 4ea6fd7a..6e62279d 100644 --- a/tests/BaseIntegrationTestCase.php +++ b/tests/BaseIntegrationTestCase.php @@ -44,14 +44,14 @@ public function __construct($name = null, array $data = [], $dataName = '') $this->setOption('configuration', $this->getStubPath() . DIRECTORY_SEPARATOR . 'phpunit_for_stubs.xml'); } - protected function setUp() + protected function setup(): void { parent::setUp(); $this->cleanUpTempDirForThisExecution(); } - protected function tearDown() + protected function tearDown(): void { $this->cleanUpTempDirForThisExecution(); diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 5c9564d6..e4d4c72c 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -56,7 +56,7 @@ protected function getRandomTempDir(): string return $this->randomTempDir; } - protected function tearDown() + protected function tearDown(): void { putenv(EnvVariables::LOG_DIR); putenv(EnvVariables::PROCESS_UNIQUE_ID); diff --git a/tests/Functional/Filter/FilterTest.php b/tests/Functional/Filter/FilterTest.php index b98c1bdf..3602b337 100644 --- a/tests/Functional/Filter/FilterTest.php +++ b/tests/Functional/Filter/FilterTest.php @@ -9,7 +9,7 @@ class FilterTest extends BaseFunctionalTestCase { - protected function setUp() + protected function setup(): void { $this->setOption('configuration', $this->getStubPath() . DIRECTORY_SEPARATOR . 'phpunit_with_2_testsuites.xml'); $this->setOption('testsuite', 'suite1,suite2'); diff --git a/tests/Functional/Parser/JSON/LogPrinterTest.php b/tests/Functional/Parser/JSON/LogPrinterTest.php index 97c2e692..c544b2ea 100644 --- a/tests/Functional/Parser/JSON/LogPrinterTest.php +++ b/tests/Functional/Parser/JSON/LogPrinterTest.php @@ -11,7 +11,7 @@ class LogPrinterTest extends BaseFunctionalTestCase { - protected function setUp() + protected function setup(): void { parent::setUp(); diff --git a/tests/Unit/Process/ProcessBuilderFactoryTest.php b/tests/Unit/Process/ProcessBuilderFactoryTest.php index 2d3ae5c7..e4602bfe 100644 --- a/tests/Unit/Process/ProcessBuilderFactoryTest.php +++ b/tests/Unit/Process/ProcessBuilderFactoryTest.php @@ -13,7 +13,7 @@ class ProcessBuilderFactoryTest extends BaseUnitTestCase { - protected function setUp() + protected function setup(): void { if (! \class_exists('Symfony\Component\Process\ProcessBuilder')) { $this->markTestSkipped('This test is legacy, will not work under Symfony 4'); diff --git a/tests/Unit/Process/ProcessFactoryTest.php b/tests/Unit/Process/ProcessFactoryTest.php index 9bc93b2d..2484afae 100644 --- a/tests/Unit/Process/ProcessFactoryTest.php +++ b/tests/Unit/Process/ProcessFactoryTest.php @@ -14,7 +14,7 @@ class ProcessFactoryTest extends BaseUnitTestCase { - protected function setUp() + protected function setup(): void { $process = new Process(['cmd as array']); if (\is_array($process->getCommandLine())) { From edc1be1104b28db84b959e97b149745e9d40a139 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 5 Feb 2019 13:40:06 +0100 Subject: [PATCH 02/13] Resolve PHPUnit assertContains deprecations --- tests/BaseTestCase.php | 52 ++++++++++++++++++++++- tests/Unit/Parser/JSON/LogPrinterTest.php | 4 +- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index e4d4c72c..87149e16 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -38,7 +38,7 @@ protected function getStubPath(): string return realpath(__DIR__ . DIRECTORY_SEPARATOR . 'Stub') . DIRECTORY_SEPARATOR; } - protected function createRandomTmpDir() + protected function createRandomTmpDir(): void { $this->randomTempDir = uniqid(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'paraunit-test-', true); $this->randomTempDir .= DIRECTORY_SEPARATOR; @@ -83,4 +83,54 @@ protected function getFileContent(string $filePath): string return $content; } + + /** + * BC compat method provided as a workaround for deprecations. + * The newer methods are present only from PHPUnit 7.5.0 onwards + */ + public static function assertContains( + $needle, + $haystack, + string $message = '', + bool $ignoreCase = false, + bool $checkForObjectIdentity = true, + bool $checkForNonObjectIdentity = false + ): void { + if (\is_string($haystack) && \method_exists(self::class, 'assertStringContainsString')) { + if ($ignoreCase) { + self::assertStringContainsStringIgnoringCase($needle, $haystack, $message); + } else { + self::assertStringContainsString($needle, $haystack, $message); + } + self::assertTrue($checkForObjectIdentity, 'Unsupported parameter!'); + self::assertFalse($checkForNonObjectIdentity, 'Unsupported parameter!'); + } else { + parent::assertContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity); + } + } + + /** + * BC compat method provided as a workaround for deprecations. + * The newer methods are present only from PHPUnit 7.5.0 onwards + */ + public static function assertNotContains( + $needle, + $haystack, + string $message = '', + bool $ignoreCase = false, + bool $checkForObjectIdentity = true, + bool $checkForNonObjectIdentity = false + ): void { + if (\is_string($haystack) && \method_exists(self::class, 'assertStringContainsString')) { + if ($ignoreCase) { + self::assertStringNotContainsStringIgnoringCase($needle, $haystack, $message); + } else { + self::assertStringNotContainsString($needle, $haystack, $message); + } + self::assertTrue($checkForObjectIdentity, 'Unsupported parameter!'); + self::assertFalse($checkForNonObjectIdentity, 'Unsupported parameter!'); + } else { + parent::assertNotContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity); + } + } } diff --git a/tests/Unit/Parser/JSON/LogPrinterTest.php b/tests/Unit/Parser/JSON/LogPrinterTest.php index 563601d9..50e6d98c 100644 --- a/tests/Unit/Parser/JSON/LogPrinterTest.php +++ b/tests/Unit/Parser/JSON/LogPrinterTest.php @@ -55,7 +55,7 @@ public function testAddWarning() $printer = $this->createPrinterAndStartTestSuite(); $test = $this->prophesize(Test::class)->reveal(); // has final methods, cannot be mocked - $warning = new Warning('Warning message', null, new \Exception()); + $warning = new Warning('Warning message', 123, new \Exception()); $line = __LINE__ - 1; $printer->startTest($test); @@ -86,7 +86,7 @@ public function testAddFailure() $printer = $this->createPrinterAndStartTestSuite(); $test = $this->prophesize(Test::class)->reveal(); // has final methods, cannot be mocked - $failure = new AssertionFailedError('Failure message', null, new \Exception()); + $failure = new AssertionFailedError('Failure message', 123, new \Exception()); $line = __LINE__ - 1; $printer->startTest($test); From 96d022cad56e3347ff9c1ed2aa829de6f1b5302b Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 5 Feb 2019 13:47:59 +0100 Subject: [PATCH 03/13] Remove other PHPUnit deprecations --- tests/BaseTestCase.php | 10 ++++++++++ tests/Functional/Command/CoverageCommandTest.php | 2 +- tests/Unit/Parser/JSON/LogFetcherTest.php | 2 -- tests/Unit/Process/CommandLineTest.php | 1 - tests/Unit/Process/CommandLineWithCoverageTest.php | 3 --- tests/Unit/Runner/RunnerTest.php | 4 ---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 87149e16..df21b84e 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -109,6 +109,16 @@ public static function assertContains( } } + public static function assertAttributeSame( + $expected, + string $actualAttributeName, + $actualClassOrObject, + string $message = '' + ): void { + parent::assertAttributeSame($expected, $actualAttributeName, $actualClassOrObject, + $message); // TODO: Change the autogenerated stub + } + /** * BC compat method provided as a workaround for deprecations. * The newer methods are present only from PHPUnit 7.5.0 onwards diff --git a/tests/Functional/Command/CoverageCommandTest.php b/tests/Functional/Command/CoverageCommandTest.php index 661f183a..cf5e63f1 100644 --- a/tests/Functional/Command/CoverageCommandTest.php +++ b/tests/Functional/Command/CoverageCommandTest.php @@ -94,7 +94,7 @@ private function getTempCoverageFilename(): string { /** @var string $filename */ $filename = tempnam(sys_get_temp_dir(), 'coverage.txt'); - $this->assertInternalType('string', $filename); + $this->assertNotFalse($filename); return $filename; } diff --git a/tests/Unit/Parser/JSON/LogFetcherTest.php b/tests/Unit/Parser/JSON/LogFetcherTest.php index 455d11ba..8c9a40a1 100644 --- a/tests/Unit/Parser/JSON/LogFetcherTest.php +++ b/tests/Unit/Parser/JSON/LogFetcherTest.php @@ -24,7 +24,6 @@ public function testFetchAppendsLogEndingAnywayWithMissingLog() $logs = $fetcher->fetch($process); $this->assertNotNull($logs, 'Fetcher returning a non-array'); - $this->assertInternalType('array', $logs, 'Fetcher returning a non-array'); $this->assertCount(1, $logs, 'Log ending missing'); $this->assertContainsOnlyInstancesOf(\stdClass::class, $logs); @@ -50,7 +49,6 @@ public function testFetch() $logs = $fetcher->fetch($process); $this->assertNotNull($logs, 'Fetcher returning a non-array'); - $this->assertInternalType('array', $logs, 'Fetcher returning a non-array'); $this->assertCount(20 + 1, $logs, 'Log ending missing'); $this->assertContainsOnlyInstancesOf(\stdClass::class, $logs); diff --git a/tests/Unit/Process/CommandLineTest.php b/tests/Unit/Process/CommandLineTest.php index baee310f..fbc50d39 100644 --- a/tests/Unit/Process/CommandLineTest.php +++ b/tests/Unit/Process/CommandLineTest.php @@ -40,7 +40,6 @@ public function testGetOptionsFor() $cli = new CommandLine($phpunit->reveal()); $options = $cli->getOptions($config->reveal()); - $this->assertInternalType('array', $options, 'Expecting an array, got ' . gettype($options)); $this->assertContains('--configuration=/path/to/phpunit.xml', $options); $this->assertContains('--printer=' . LogPrinter::class, $options); $this->assertContains('--opt', $options); diff --git a/tests/Unit/Process/CommandLineWithCoverageTest.php b/tests/Unit/Process/CommandLineWithCoverageTest.php index 49510fc3..1c17a79a 100644 --- a/tests/Unit/Process/CommandLineWithCoverageTest.php +++ b/tests/Unit/Process/CommandLineWithCoverageTest.php @@ -79,7 +79,6 @@ public function testGetOptionsForWithoutDbg() $options = $cli->getOptions($config->reveal()); - $this->assertInternalType('array', $options, 'Expecting an array, got ' . gettype($options)); $this->assertContains('--configuration=/path/to/phpunit.xml', $options); $this->assertContains('--printer=' . LogPrinter::class, $options); $this->assertContains('--opt', $options); @@ -106,7 +105,6 @@ public function testGetOptionsForWithDbg() $options = $cli->getOptions($config->reveal()); - $this->assertInternalType('array', $options, 'Expecting an array, got ' . gettype($options)); $this->assertContains('-qrr', $options); $this->assertEquals('-qrr', $options[0], '-qrr option needs to be the first one!'); $this->assertContains('path/to/phpunit', $options); @@ -131,7 +129,6 @@ public function testGetSpecificOptions() $options = $cli->getSpecificOptions($testFilename); - $this->assertInternalType('array', $options, 'Expecting an array, got ' . gettype($options)); $this->assertContains('--coverage-php=/path/to/coverage.php', $options); } } diff --git a/tests/Unit/Runner/RunnerTest.php b/tests/Unit/Runner/RunnerTest.php index 4d1db1a6..be4af0fe 100644 --- a/tests/Unit/Runner/RunnerTest.php +++ b/tests/Unit/Runner/RunnerTest.php @@ -96,8 +96,6 @@ public function testOnProcessParsingCompletedWithFailedProcess() ); $runner->onProcessParsingCompleted(new ProcessEvent($process)); - - $this->assertAttributeNotSame(0, 'exitCode', $runner); } public function testOnProcessToBeRetried() @@ -125,8 +123,6 @@ public function testOnProcessToBeRetried() ); $runner->onProcessToBeRetried(new ProcessEvent($process)); - - $this->assertAttributeSame(0, 'exitCode', $runner); } private function mockEventDispatcher(): EventDispatcherInterface From 907ef118a48a92c5af11c69e6ba6e08b877b371f Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 5 Feb 2019 13:50:59 +0100 Subject: [PATCH 04/13] Remove deprecated method --- tests/BaseTestCase.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index df21b84e..87149e16 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -109,16 +109,6 @@ public static function assertContains( } } - public static function assertAttributeSame( - $expected, - string $actualAttributeName, - $actualClassOrObject, - string $message = '' - ): void { - parent::assertAttributeSame($expected, $actualAttributeName, $actualClassOrObject, - $message); // TODO: Change the autogenerated stub - } - /** * BC compat method provided as a workaround for deprecations. * The newer methods are present only from PHPUnit 7.5.0 onwards From ed9290532e911c42c469f7f152de4d356bfc8da5 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 8 Feb 2019 16:38:03 +0100 Subject: [PATCH 05/13] Ignore PHPStan error with method_exists --- phpstan.neon | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.neon b/phpstan.neon index ed416765..3712c5e7 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,6 +6,7 @@ parameters: - '/Call to function is_array\(\) with string will always evaluate to false./' - '/Class Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher not found/' - '/Parameter #3 \$offset of function strpos expects int, int\|false given\./' + - '/Call to function method_exists.. with .Tests..BaseTestCase. and .assertStringContain.... will always evaluate to false./' excludes_analyse: - src/Paraunit/Parser/JSON/LogPrinterV6.php - src/Paraunit/Process/ProcessBuilderFactory.php From d9894fd55a5b5668a0a4e82a5853e920867ee10c Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 20 Feb 2019 11:31:28 +0100 Subject: [PATCH 06/13] Require phpunit/php-code-coverage ^7.0.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 32897f97..fd0a3a4b 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "require": { "php": "^7.1", "jean85/pretty-package-versions": "^1.0.3", - "phpunit/php-code-coverage": "^4.0||^5.0||^6.0||^7.0", + "phpunit/php-code-coverage": "^4.0||^5.0||^6.0||^7.0.2", "phpunit/php-file-iterator": "^1.0||^2.0", "phpunit/phpunit": "^6.0.9||^7.0||^8.0", "symfony/console": "^2.8||^3.0||^4.0", From f54869a54a1f59134898b11f55ffdaee51dfef73 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 21 Feb 2019 18:32:32 +0100 Subject: [PATCH 07/13] Fix PHP version in .lock CI job --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 36b15b3e..96044341 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ jobs: - env: VENDOR=prefer-lowest install: composer update --prefer-lowest --prefer-dist --prefer-stable --no-interaction - env: VENDOR=lock + php: 7.2 install: composer install --prefer-dist --no-interaction - stage: Code style, static analysis and E2E env: E2E=true From 54f82508812561ec6b38fed88f0cfc77e9ecba58 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 21 Feb 2019 18:34:37 +0100 Subject: [PATCH 08/13] Update composer.lock --- composer.lock | 99 ++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 53 deletions(-) diff --git a/composer.lock b/composer.lock index b2f13df2..885be29c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1adf25f476c4e42ff158b9ec1049cc4b", + "content-hash": "e19719428d61713f5756222cc43da0cd", "packages": [ { "name": "doctrine/instantiator", @@ -161,16 +161,16 @@ }, { "name": "ocramius/package-versions", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/Ocramius/PackageVersions.git", - "reference": "4489d5002c49d55576fa0ba786f42dbb009be46f" + "reference": "a4d4b60d0e60da2487bd21a2c6ac089f85570dbb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/4489d5002c49d55576fa0ba786f42dbb009be46f", - "reference": "4489d5002c49d55576fa0ba786f42dbb009be46f", + "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/a4d4b60d0e60da2487bd21a2c6ac089f85570dbb", + "reference": "a4d4b60d0e60da2487bd21a2c6ac089f85570dbb", "shasum": "" }, "require": { @@ -179,6 +179,7 @@ }, "require-dev": { "composer/composer": "^1.6.3", + "doctrine/coding-standard": "^5.0.1", "ext-zip": "*", "infection/infection": "^0.7.1", "phpunit/phpunit": "^7.0.0" @@ -206,7 +207,7 @@ } ], "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "time": "2018-02-05T13:05:30+00:00" + "time": "2019-02-21T12:16:21+00:00" }, { "name": "phar-io/manifest", @@ -527,16 +528,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "7.0.1", + "version": "7.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "4832739a02c418397e404da6c3e4fe680b7a4de7" + "reference": "cfca9c5f7f2694ca0c7749ffb142927d9f05250f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4832739a02c418397e404da6c3e4fe680b7a4de7", - "reference": "4832739a02c418397e404da6c3e4fe680b7a4de7", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/cfca9c5f7f2694ca0c7749ffb142927d9f05250f", + "reference": "cfca9c5f7f2694ca0c7749ffb142927d9f05250f", "shasum": "" }, "require": { @@ -586,7 +587,7 @@ "testing", "xunit" ], - "time": "2019-02-01T07:29:14+00:00" + "time": "2019-02-15T13:40:27+00:00" }, { "name": "phpunit/php-file-iterator", @@ -681,16 +682,16 @@ }, { "name": "phpunit/php-timer", - "version": "2.0.0", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f" + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b8454ea6958c3dee38453d3bd571e023108c91f", - "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b389aebe1b8b0578430bda0c7c95a829608e059", + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059", "shasum": "" }, "require": { @@ -702,7 +703,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -726,7 +727,7 @@ "keywords": [ "timer" ], - "time": "2018-02-01T13:07:23+00:00" + "time": "2019-02-20T10:12:59+00:00" }, { "name": "phpunit/php-token-stream", @@ -779,16 +780,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.0.1", + "version": "8.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "753a192050133fc649234de34d1993d87785b134" + "reference": "a7af0201285445c9c73c4bdf869c486e36b41604" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/753a192050133fc649234de34d1993d87785b134", - "reference": "753a192050133fc649234de34d1993d87785b134", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a7af0201285445c9c73c4bdf869c486e36b41604", + "reference": "a7af0201285445c9c73c4bdf869c486e36b41604", "shasum": "" }, "require": { @@ -857,7 +858,7 @@ "testing", "xunit" ], - "time": "2019-02-03T17:34:56+00:00" + "time": "2019-02-18T09:23:05+00:00" }, { "name": "psr/container", @@ -2340,16 +2341,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v2.14.0", + "version": "v2.14.2", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "b788ea0af899cedc8114dca7db119c93b6685da2" + "reference": "ff401e58261ffc5934a58f795b3f95b355e276cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/b788ea0af899cedc8114dca7db119c93b6685da2", - "reference": "b788ea0af899cedc8114dca7db119c93b6685da2", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/ff401e58261ffc5934a58f795b3f95b355e276cb", + "reference": "ff401e58261ffc5934a58f795b3f95b355e276cb", "shasum": "" }, "require": { @@ -2370,9 +2371,6 @@ "symfony/process": "^3.0 || ^4.0", "symfony/stopwatch": "^3.0 || ^4.0" }, - "conflict": { - "hhvm": "*" - }, "require-dev": { "johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0", "justinrainbow/json-schema": "^5.0", @@ -2396,11 +2394,6 @@ "php-cs-fixer" ], "type": "application", - "extra": { - "branch-alias": { - "dev-master": "2.14-dev" - } - }, "autoload": { "psr-4": { "PhpCsFixer\\": "src/" @@ -2432,7 +2425,7 @@ } ], "description": "A tool to automatically fix PHP code style", - "time": "2019-01-04T18:29:47+00:00" + "time": "2019-02-17T17:44:13+00:00" }, { "name": "guzzlehttp/guzzle", @@ -2872,31 +2865,31 @@ }, { "name": "nette/neon", - "version": "v2.4.3", + "version": "v3.0.0", "source": { "type": "git", "url": "https://github.com/nette/neon.git", - "reference": "5e72b1dd3e2d34f0863c5561139a19df6a1ef398" + "reference": "cbff32059cbdd8720deccf9e9eace6ee516f02eb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/neon/zipball/5e72b1dd3e2d34f0863c5561139a19df6a1ef398", - "reference": "5e72b1dd3e2d34f0863c5561139a19df6a1ef398", + "url": "https://api.github.com/repos/nette/neon/zipball/cbff32059cbdd8720deccf9e9eace6ee516f02eb", + "reference": "cbff32059cbdd8720deccf9e9eace6ee516f02eb", "shasum": "" }, "require": { "ext-iconv": "*", "ext-json": "*", - "php": ">=5.6.0" + "php": ">=7.0" }, "require-dev": { - "nette/tester": "~2.0", + "nette/tester": "^2.0", "tracy/tracy": "^2.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -2929,7 +2922,7 @@ "nette", "yaml" ], - "time": "2018-03-21T12:12:21+00:00" + "time": "2019-02-05T21:30:40+00:00" }, { "name": "nette/php-generator", @@ -3142,16 +3135,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.2.0", + "version": "v4.2.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "594bcae1fc0bccd3993d2f0d61a018e26ac2865a" + "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/594bcae1fc0bccd3993d2f0d61a018e26ac2865a", - "reference": "594bcae1fc0bccd3993d2f0d61a018e26ac2865a", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/5221f49a608808c1e4d436df32884cbc1b821ac0", + "reference": "5221f49a608808c1e4d436df32884cbc1b821ac0", "shasum": "" }, "require": { @@ -3189,7 +3182,7 @@ "parser", "php" ], - "time": "2019-01-12T16:31:37+00:00" + "time": "2019-02-16T20:54:15+00:00" }, { "name": "paragonie/random_compat", @@ -3418,16 +3411,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.11.1", + "version": "0.11.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "a138b8a2731b2c19f1dffa2f1411984a638fe977" + "reference": "8e185a74004920419ee97bf9dc62e6a175e8dca5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a138b8a2731b2c19f1dffa2f1411984a638fe977", - "reference": "a138b8a2731b2c19f1dffa2f1411984a638fe977", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8e185a74004920419ee97bf9dc62e6a175e8dca5", + "reference": "8e185a74004920419ee97bf9dc62e6a175e8dca5", "shasum": "" }, "require": { @@ -3487,7 +3480,7 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "time": "2019-01-19T20:23:08+00:00" + "time": "2019-02-12T14:54:38+00:00" }, { "name": "phpstan/phpstan-phpunit", From 464bf5363ae3e398548860e75a063fd2fdbb1f84 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 21 Feb 2019 18:44:32 +0100 Subject: [PATCH 09/13] Do not assert exit code on warning, it can change --- tests/Functional/Runner/RunnerTest.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Functional/Runner/RunnerTest.php b/tests/Functional/Runner/RunnerTest.php index acb9028d..048ca152 100644 --- a/tests/Functional/Runner/RunnerTest.php +++ b/tests/Functional/Runner/RunnerTest.php @@ -16,7 +16,7 @@ class RunnerTest extends BaseIntegrationTestCase { - public function testAllGreen() + public function testAllGreen(): void { $this->setTextFilter('ThreeGreenTestStub.php'); $this->loadContainer(); @@ -36,7 +36,7 @@ public function testAllGreen() ]); } - public function testMaxRetryEntityManagerIsClosed() + public function testMaxRetryEntityManagerIsClosed(): void { $this->setTextFilter('EntityManagerClosedTestStub.php'); $this->loadContainer(); @@ -61,7 +61,7 @@ public function testMaxRetryEntityManagerIsClosed() /** * @dataProvider stubFilenameProvider */ - public function testMaxRetryDeadlock(string $stubFilePath) + public function testMaxRetryDeadlock(string $stubFilePath): void { $this->setTextFilter($stubFilePath); $this->loadContainer(); @@ -83,7 +83,7 @@ public function stubFilenameProvider(): array ]; } - public function testSegFault() + public function testSegFault(): void { $this->setTextFilter('SegFaultTestStub.php'); $this->loadContainer(); @@ -109,12 +109,12 @@ public function testSegFault() ); } - public function testWarning() + public function testWarning(): void { $this->setTextFilter('MissingProviderTestStub.php'); $this->loadContainer(); - $this->assertNotEquals(0, $this->executeRunner(), 'Exit code should not be 0'); + $this->executeRunner(); $output = $this->getConsoleOutput()->getOutput(); $this->assertRegExp('/\nW\s+1\n/', $output, 'Missing W output'); @@ -130,7 +130,7 @@ public function testWarning() ); } - public function testNoTestExecutedDoesntGetMistakenAsAbnormalTermination() + public function testNoTestExecutedDoesntGetMistakenAsAbnormalTermination(): void { $this->setTextFilter('ThreeGreenTestStub.php'); $this->loadContainer(); @@ -151,7 +151,7 @@ public function testNoTestExecutedDoesntGetMistakenAsAbnormalTermination() $this->assertContains('ThreeGreenTestStub.php', $output); } - public function testRegressionFatalErrorsRecognizedAsUnknownResults() + public function testRegressionFatalErrorsRecognizedAsUnknownResults(): void { $this->setTextFilter('FatalErrorTestStub.php'); $this->loadContainer(); @@ -164,7 +164,7 @@ public function testRegressionFatalErrorsRecognizedAsUnknownResults() $this->assertNotContains('UNKNOWN', $output, 'REGRESSION: fatal error mistaken for unknown result'); } - public function testRegressionMissingLogAsUnknownResults() + public function testRegressionMissingLogAsUnknownResults(): void { $this->setTextFilter('ParseErrorTestStub.php'); $this->loadContainer(); @@ -181,7 +181,7 @@ public function testRegressionMissingLogAsUnknownResults() ); } - public function testRegressionFatalErrorsShouldNotLeakToOutput() + public function testRegressionFatalErrorsShouldNotLeakToOutput(): void { $this->setTextFilter('RaisingNoticeTestStub.php'); $this->loadContainer(); @@ -195,7 +195,7 @@ public function testRegressionFatalErrorsShouldNotLeakToOutput() ); } - public function testRegressionTestResultsBeforeRetryShouldNotBeReported() + public function testRegressionTestResultsBeforeRetryShouldNotBeReported(): void { $this->setTextFilter('PassThenRetryTestStub'); $this->loadContainer(); From 3604cc224ad408af82242a753f7f18e233a1d4ac Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 21 Feb 2019 18:51:25 +0100 Subject: [PATCH 10/13] Fix CS --- tests/BaseTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 87149e16..de905bbb 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -85,7 +85,7 @@ protected function getFileContent(string $filePath): string } /** - * BC compat method provided as a workaround for deprecations. + * BC compat method provided as a workaround for deprecations. * The newer methods are present only from PHPUnit 7.5.0 onwards */ public static function assertContains( From e66c298b4f3e018794936ff0ccf72dca5fd1f725 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 21 Feb 2019 18:55:12 +0100 Subject: [PATCH 11/13] Run CI on newest PHP version available by default --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96044341..8859387e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,9 @@ cache: - $HOME/.composer/cache/files php: - - 7.1 - - 7.2 - 7.3 + - 7.2 + - 7.1 before_install: - if [[ !$XDEBUG ]]; then phpenv config-rm xdebug.ini; fi @@ -23,6 +23,7 @@ jobs: - stage: Test env: XDEBUG=true - env: VENDOR=prefer-lowest + php: 7.1 install: composer update --prefer-lowest --prefer-dist --prefer-stable --no-interaction - env: VENDOR=lock php: 7.2 From 979764c183f4b079c6f545ca6101e027b95abd66 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 21 Feb 2019 19:18:28 +0100 Subject: [PATCH 12/13] Fix hidden PHPStan failures --- phpstan.neon | 1 - src/Paraunit/Configuration/PHPDbgBinFile.php | 7 ++++++- src/Paraunit/Coverage/CoverageMerger.php | 6 +++++- src/Paraunit/Filter/Filter.php | 22 ++++++-------------- src/Paraunit/Runner/Pipeline.php | 12 +++++------ tests/BaseIntegrationTestCase.php | 17 ++++++++------- tests/Unit/Coverage/CoverageMergerTest.php | 14 +++++++++++-- tests/Unit/Parser/JSON/LogPrinterTest.php | 5 ++++- 8 files changed, 49 insertions(+), 35 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 3712c5e7..cef3a679 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,6 @@ parameters: ignoreErrors: - '/does not call parent constructor from PHPUnit\\Util\\Printer/' - - '/Method Tests\\BaseTestCase::getRandomTempDir\(\) should return string but returns string|null\./' - '/Parameter #1 $process of class Paraunit\\Lifecycle\\ProcessEvent constructor expects Paraunit\\Process\\AbstractParaunitProcess, Paraunit\\Process\\AbstractParaunitProcess|null given\./' - '/Call to function is_array\(\) with string will always evaluate to false./' - '/Class Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher not found/' diff --git a/src/Paraunit/Configuration/PHPDbgBinFile.php b/src/Paraunit/Configuration/PHPDbgBinFile.php index 36d88263..c7440d08 100644 --- a/src/Paraunit/Configuration/PHPDbgBinFile.php +++ b/src/Paraunit/Configuration/PHPDbgBinFile.php @@ -45,6 +45,11 @@ private function getPhpDbgBinLocation(): string $locator = new Process(['command', '-v', 'phpdbg']); $locator->run(); - return preg_replace('/\s/', '', $locator->getOutput()); + $trimmed = preg_replace('/\s/', '', $locator->getOutput()); + if (null === $trimmed) { + throw new \RuntimeException('Preg replace failed'); + } + + return $trimmed; } } diff --git a/src/Paraunit/Coverage/CoverageMerger.php b/src/Paraunit/Coverage/CoverageMerger.php index f9e4e53a..b57c3fd2 100644 --- a/src/Paraunit/Coverage/CoverageMerger.php +++ b/src/Paraunit/Coverage/CoverageMerger.php @@ -52,6 +52,10 @@ private function merge(AbstractParaunitProcess $process) public function getCoverageData(): CodeCoverage { - return $this->coverageData; + if ($this->coverageData) { + return $this->coverageData; + } + + throw new \RuntimeException('Coverage data not ready'); } } diff --git a/src/Paraunit/Filter/Filter.php b/src/Paraunit/Filter/Filter.php index 4b9ead51..a40fd566 100644 --- a/src/Paraunit/Filter/Filter.php +++ b/src/Paraunit/Filter/Filter.php @@ -32,10 +32,6 @@ class Filter /** @var string | null */ private $stringFilter; - /** - * @param string | null $testSuiteFilter - * @param string | null $stringFilter - */ public function __construct( PHPUnitUtilXMLProxy $utilXml, Facade $fileIteratorFacade, @@ -116,7 +112,7 @@ private function getExcludesArray(\DOMElement $testSuiteNode): array * @param string[] $aggregatedFiles * @param string[] $excludes */ - private function addTestsFromDirectoryNodes(\DOMElement $testSuiteNode, array &$aggregatedFiles, array $excludes) + private function addTestsFromDirectoryNodes(\DOMElement $testSuiteNode, array &$aggregatedFiles, array $excludes): void { foreach ($testSuiteNode->getElementsByTagName('directory') as $directoryNode) { $directory = (string) $directoryNode->nodeValue; @@ -137,15 +133,15 @@ private function addTestsFromDirectoryNodes(\DOMElement $testSuiteNode, array &$ /** * @param string[] $aggregatedFiles */ - private function addTestsFromFileNodes(\DOMElement $testSuiteNode, array &$aggregatedFiles) + private function addTestsFromFileNodes(\DOMElement $testSuiteNode, array &$aggregatedFiles): void { foreach ($testSuiteNode->getElementsByTagName('file') as $fileNode) { - $fileName = $this->relativePath . (string) $fileNode->nodeValue; + $fileName = $this->relativePath . $fileNode->nodeValue; $this->addFileToAggregateArray($aggregatedFiles, $fileName); } } - private function addFileToAggregateArray(array &$aggregatedFiles, string $fileName) + private function addFileToAggregateArray(array &$aggregatedFiles, string $fileName): void { // optimized array_unique $aggregatedFiles[$fileName] = $fileName; @@ -155,11 +151,7 @@ private function getDOMNodeAttribute( \DOMElement $testSuiteNode, string $nodeName, string $defaultValue = null - ): string { - /* - * @var string - * @var \DOMAttr - */ + ): ?string { foreach ($testSuiteNode->attributes as $attrName => $attrNode) { if ($attrName === $nodeName) { return $attrNode->value; @@ -170,11 +162,9 @@ private function getDOMNodeAttribute( } /** - * @param string | null $stringFilter - * * @return string[] */ - private function filterByString(array $aggregatedFiles, $stringFilter): array + private function filterByString(array $aggregatedFiles, ?string $stringFilter): array { if ($stringFilter !== null) { $aggregatedFiles = array_filter($aggregatedFiles, function ($value) use ($stringFilter) { diff --git a/src/Paraunit/Runner/Pipeline.php b/src/Paraunit/Runner/Pipeline.php index 9090502f..3a865235 100644 --- a/src/Paraunit/Runner/Pipeline.php +++ b/src/Paraunit/Runner/Pipeline.php @@ -25,7 +25,7 @@ public function __construct(EventDispatcherInterface $dispatcher, int $number) $this->number = $number; } - public function execute(AbstractParaunitProcess $process) + public function execute(AbstractParaunitProcess $process): void { if (! $this->isFree()) { throw new \RuntimeException('This pipeline is not free'); @@ -44,16 +44,16 @@ public function isFree(): bool public function isTerminated(): bool { - if ($this->isFree()) { - return true; + if ($this->process) { + return $this->process->isTerminated(); } - return $this->process->isTerminated(); + return true; } public function triggerTermination(): bool { - if ($this->isFree()) { + if (null === $this->process) { return false; } @@ -71,7 +71,7 @@ public function getNumber(): int return $this->number; } - private function handleProcessTermination() + private function handleProcessTermination(): void { $this->dispatcher->dispatch(ProcessEvent::PROCESS_TERMINATED, new ProcessEvent($this->process)); $this->process = null; diff --git a/tests/BaseIntegrationTestCase.php b/tests/BaseIntegrationTestCase.php index 6e62279d..47b1c445 100644 --- a/tests/BaseIntegrationTestCase.php +++ b/tests/BaseIntegrationTestCase.php @@ -125,21 +125,24 @@ protected function processAllTheStubLogs(): void } /** - * @throws \Exception - * * @return object */ public function getService(string $serviceName) { - return $this->container->get(sprintf(ParallelConfiguration::PUBLIC_ALIAS_FORMAT, $serviceName)); + if ($this->container) { + return $this->container->get(sprintf(ParallelConfiguration::PUBLIC_ALIAS_FORMAT, $serviceName)); + } + + throw new \RuntimeException('Container not ready'); } - /** - * @throws \Exception - */ public function getParameter(string $parameterName) { - return $this->container->getParameter($parameterName); + if ($this->container) { + return $this->container->getParameter($parameterName); + } + + throw new \RuntimeException('Container not ready'); } protected function loadContainer(): void diff --git a/tests/Unit/Coverage/CoverageMergerTest.php b/tests/Unit/Coverage/CoverageMergerTest.php index 870166d5..5d2d25ed 100644 --- a/tests/Unit/Coverage/CoverageMergerTest.php +++ b/tests/Unit/Coverage/CoverageMergerTest.php @@ -12,7 +12,17 @@ class CoverageMergerTest extends BaseUnitTestCase { - public function testMergeFirstCoverageData() + public function testGetCoverageWhenNotReady(): void + { + $merger = new CoverageMerger($this->prophesize(CoverageFetcher::class)->reveal()); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('not ready'); + + $merger->getCoverageData(); + } + + public function testMergeFirstCoverageData(): void { $process = new StubbedParaunitProcess(); @@ -30,7 +40,7 @@ public function testMergeFirstCoverageData() $this->assertSame($newCoverageData, $merger->getCoverageData()); } - public function testMergeNextCoverageData() + public function testMergeNextCoverageData(): void { $process1 = new StubbedParaunitProcess('test1'); $process2 = new StubbedParaunitProcess('test2'); diff --git a/tests/Unit/Parser/JSON/LogPrinterTest.php b/tests/Unit/Parser/JSON/LogPrinterTest.php index 50e6d98c..d4aaee55 100644 --- a/tests/Unit/Parser/JSON/LogPrinterTest.php +++ b/tests/Unit/Parser/JSON/LogPrinterTest.php @@ -258,7 +258,10 @@ private function getLogContent(): string $logFilename = $this->getRandomTempDir() . 'log-file-name.json.log'; $content = $this->getFileContent($logFilename); - return preg_replace('/\r\n/', "\n", $content); + $parsedOutput = preg_replace('/\r\n/', "\n", $content); + $this->assertNotNull($parsedOutput, 'Preg replace failed'); + + return $parsedOutput; } private function encodeWithStartTestSuite(array $data = []): string From 7ec259d23709c144a104d51c9b226bf3748d9b42 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 21 Feb 2019 19:28:20 +0100 Subject: [PATCH 13/13] Fix other PHPStan hidden errors --- phpstan.neon | 4 ++-- src/Paraunit/Configuration/ParallelConfiguration.php | 7 ++++--- src/Paraunit/Filter/Filter.php | 4 ++-- src/Paraunit/Runner/Pipeline.php | 6 ++++-- tests/BaseIntegrationTestCase.php | 1 + tests/Functional/Parser/JSON/LogParserTest.php | 1 + 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index cef3a679..26aecbdc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,12 +1,12 @@ parameters: ignoreErrors: - '/does not call parent constructor from PHPUnit\\Util\\Printer/' - - '/Parameter #1 $process of class Paraunit\\Lifecycle\\ProcessEvent constructor expects Paraunit\\Process\\AbstractParaunitProcess, Paraunit\\Process\\AbstractParaunitProcess|null given\./' + # needed with Symfony <3.3 - '/Call to function is_array\(\) with string will always evaluate to false./' - '/Class Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher not found/' - - '/Parameter #3 \$offset of function strpos expects int, int\|false given\./' - '/Call to function method_exists.. with .Tests..BaseTestCase. and .assertStringContain.... will always evaluate to false./' excludes_analyse: + # needed with PHPUnit 6 - src/Paraunit/Parser/JSON/LogPrinterV6.php - src/Paraunit/Process/ProcessBuilderFactory.php - tests/Stub/ParseErrorTestStub.php diff --git a/src/Paraunit/Configuration/ParallelConfiguration.php b/src/Paraunit/Configuration/ParallelConfiguration.php index 22229be4..28a990e7 100644 --- a/src/Paraunit/Configuration/ParallelConfiguration.php +++ b/src/Paraunit/Configuration/ParallelConfiguration.php @@ -51,14 +51,15 @@ public function buildContainer(InputInterface $input, OutputInterface $output): return $containerBuilder; } - protected function tagEventSubscribers(ContainerBuilder $container) + protected function tagEventSubscribers(ContainerBuilder $container): void { - foreach ($container->getDefinitions() as $definition) { + foreach ($container->getDefinitions() as $id => $definition) { if ($definition->isSynthetic() || $definition->isAbstract()) { continue; } - if (array_key_exists(EventSubscriberInterface::class, class_implements($definition->getClass()))) { + $class = $definition->getClass() ?? (string) $id; + if (array_key_exists(EventSubscriberInterface::class, class_implements($class))) { $definition->addTag(self::TAG_EVENT_SUBSCRIBER); } } diff --git a/src/Paraunit/Filter/Filter.php b/src/Paraunit/Filter/Filter.php index a40fd566..5de0078a 100644 --- a/src/Paraunit/Filter/Filter.php +++ b/src/Paraunit/Filter/Filter.php @@ -151,14 +151,14 @@ private function getDOMNodeAttribute( \DOMElement $testSuiteNode, string $nodeName, string $defaultValue = null - ): ?string { + ): string { foreach ($testSuiteNode->attributes as $attrName => $attrNode) { if ($attrName === $nodeName) { return $attrNode->value; } } - return $defaultValue; + return $defaultValue ?? ''; } /** diff --git a/src/Paraunit/Runner/Pipeline.php b/src/Paraunit/Runner/Pipeline.php index 3a865235..03b9bab7 100644 --- a/src/Paraunit/Runner/Pipeline.php +++ b/src/Paraunit/Runner/Pipeline.php @@ -73,7 +73,9 @@ public function getNumber(): int private function handleProcessTermination(): void { - $this->dispatcher->dispatch(ProcessEvent::PROCESS_TERMINATED, new ProcessEvent($this->process)); - $this->process = null; + if ($this->process) { + $this->dispatcher->dispatch(ProcessEvent::PROCESS_TERMINATED, new ProcessEvent($this->process)); + $this->process = null; + } } } diff --git a/tests/BaseIntegrationTestCase.php b/tests/BaseIntegrationTestCase.php index 47b1c445..1b981f3c 100644 --- a/tests/BaseIntegrationTestCase.php +++ b/tests/BaseIntegrationTestCase.php @@ -84,6 +84,7 @@ protected function assertOutputOrder(UnformattedOutputStub $output, array $strin $previousPosition = 0; $previousString = ''; foreach ($strings as $string) { + /** @var int $position */ $position = strpos($output->getOutput(), $string, $previousPosition); $this->assertNotFalse($position, $output->getOutput() . PHP_EOL . 'String not found: ' . $string); $this->assertGreaterThan( diff --git a/tests/Functional/Parser/JSON/LogParserTest.php b/tests/Functional/Parser/JSON/LogParserTest.php index dcdec0ad..a3adceba 100644 --- a/tests/Functional/Parser/JSON/LogParserTest.php +++ b/tests/Functional/Parser/JSON/LogParserTest.php @@ -42,6 +42,7 @@ public function testParse(string $stubLog, string $expectedResult, bool $hasAbno $this->assertEquals($hasAbnormalTermination, $process->hasAbnormalTermination()); if ($process->getTestClassName()) { + $this->assertNotNull($process->getTestClassName(), 'Empty test class name'); $this->assertStringStartsWith('Paraunit\Tests\Stub\\', $process->getTestClassName()); } }