From e2ea5a9fdf59bb6a1fa4e3c8dac4e3555a57da9b Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Fri, 13 Jul 2018 01:20:43 +0300 Subject: [PATCH 1/5] upgrade phpunit, test with low and high deps --- .travis.yml | 18 +++++++++++++++--- composer.json | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a8d48d0c7ce..5ccd47035c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,26 @@ language: php matrix: - include: + exclude: - php: 7.0 + env: DEPS="" COVERALLS=true - php: 7.1 + env: DEPS="" COVERALLS=true - php: 7.2 - env: COVERALLS=true + env: DEPS="" COVERALLS="" - php: nightly + env: DEPS="" COVERALLS=true allow_failures: - php: nightly +php: + - 7.0 + - 7.1 + - 7.2 + +env: + - DEPS="--prefer-lowest --prefer-stable" COVERALLS="" + - DEPS="" COVERALLS="" + - DEPS="" COVERALLS=true cache: directories: @@ -22,7 +34,7 @@ before_install: - if [[ $COVERALLS = "" ]]; then phpenv config-rm xdebug.ini; fi install: - - composer --prefer-source install + - composer --prefer-source $DEPS update script: - vendor/bin/phpunit diff --git a/composer.json b/composer.json index f159f2c117d..7e117b3e216 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "optimize-autoloader": true }, "require-dev": { - "phpunit/phpunit": "^5.7.4", + "phpunit/phpunit": "^6.0 || ^7.0", "squizlabs/php_codesniffer": "^3.0", "php-coveralls/php-coveralls": "^2.0", "bamarni/composer-bin-plugin": "^1.2" From 528c9bada9413868e5af606b360b0965b92894ec Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Fri, 13 Jul 2018 03:40:01 +0300 Subject: [PATCH 2/5] work around possibly-anonymous test cases introduced by newer PHPUnit --- .travis.yml | 1 + tests/TestCase.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5ccd47035c9..1392a8fa080 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ php: - 7.0 - 7.1 - 7.2 + - nightly env: - DEPS="--prefer-lowest --prefer-stable" COVERALLS="" diff --git a/tests/TestCase.php b/tests/TestCase.php index 986ec2adc07..a442cafbc42 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase as BaseTestCase; use Psalm\Checker\FileChecker; use Psalm\Checker\ProjectChecker; +use RuntimeException; class TestCase extends BaseTestCase { @@ -99,4 +100,13 @@ public function analyzeFile($file_path, \Psalm\Context $context) ); $file_checker->analyze($context); } + public function getName($withDataSet = true): string + { + $name = parent::getName($withDataSet); + /** @psalm-suppress DocblockTypeContradiction PHPUnit 7 introduced nullable name */ + if (null === $name) { + throw new RuntimeException('anonymous test - shouldn\'t happen'); + } + return $name; + } } From cf14d27ca28334b4977831af8999d7c2984f2ade Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Fri, 13 Jul 2018 04:38:04 +0300 Subject: [PATCH 3/5] Alternative TestCase::getName() nullability workaround Previous workaround was failing due to PHP warnings on 7.1 or 7.2 (depending on specific signature). There's just no signature that would be working for all 4 variants of (ver / dep) matrix. --- tests/DocumentationTest.php | 2 +- tests/FileManipulationTest.php | 2 +- tests/FileReferenceTest.php | 2 +- tests/TestCase.php | 2 +- tests/Traits/FileCheckerInvalidCodeParseTestTrait.php | 2 +- tests/Traits/FileCheckerValidCodeParseTestTrait.php | 2 +- tests/UnusedCodeTest.php | 4 ++-- tests/UnusedVariableTest.php | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index 2a7fd98cab6..46a2abb5548 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -110,7 +110,7 @@ public function testAllIssuesCovered() */ public function testInvalidCode($code, $error_message, $error_levels = [], $check_references = false) { - if (strpos($this->getName(), 'SKIPPED-') !== false) { + if (strpos($this->getTestName(), 'SKIPPED-') !== false) { $this->markTestSkipped(); } diff --git a/tests/FileManipulationTest.php b/tests/FileManipulationTest.php index efe0cddd71b..c80db7c4ccf 100644 --- a/tests/FileManipulationTest.php +++ b/tests/FileManipulationTest.php @@ -33,7 +33,7 @@ public function setUp() */ public function testValidCode($input_code, $output_code, $php_version, array $issues_to_fix, $safe_types) { - $test_name = $this->getName(); + $test_name = $this->getTestName(); if (strpos($test_name, 'PHP7-') !== false) { if (version_compare(PHP_VERSION, '7.0.0dev', '<')) { $this->markTestSkipped('Test case requires PHP 7.'); diff --git a/tests/FileReferenceTest.php b/tests/FileReferenceTest.php index a575d73962e..a4a5d11eb21 100644 --- a/tests/FileReferenceTest.php +++ b/tests/FileReferenceTest.php @@ -41,7 +41,7 @@ public function setUp() */ public function testValidCode($input_code, $symbol, $expected_locations) { - $test_name = $this->getName(); + $test_name = $this->getTestName(); if (strpos($test_name, 'PHP7-') !== false) { if (version_compare(PHP_VERSION, '7.0.0dev', '<')) { $this->markTestSkipped('Test case requires PHP 7.'); diff --git a/tests/TestCase.php b/tests/TestCase.php index a442cafbc42..16e12dbb698 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -100,7 +100,7 @@ public function analyzeFile($file_path, \Psalm\Context $context) ); $file_checker->analyze($context); } - public function getName($withDataSet = true): string + protected function getTestName(bool $withDataSet = true): string { $name = parent::getName($withDataSet); /** @psalm-suppress DocblockTypeContradiction PHPUnit 7 introduced nullable name */ diff --git a/tests/Traits/FileCheckerInvalidCodeParseTestTrait.php b/tests/Traits/FileCheckerInvalidCodeParseTestTrait.php index ffac8a6a30c..77a2634a5d9 100644 --- a/tests/Traits/FileCheckerInvalidCodeParseTestTrait.php +++ b/tests/Traits/FileCheckerInvalidCodeParseTestTrait.php @@ -24,7 +24,7 @@ abstract public function providerFileCheckerInvalidCodeParse(); */ public function testInvalidCode($code, $error_message, $error_levels = [], $strict_mode = false) { - if (strpos($this->getName(), 'SKIPPED-') !== false) { + if (strpos($this->getTestName(), 'SKIPPED-') !== false) { $this->markTestSkipped(); } diff --git a/tests/Traits/FileCheckerValidCodeParseTestTrait.php b/tests/Traits/FileCheckerValidCodeParseTestTrait.php index 0594a51d982..abac5f4d557 100644 --- a/tests/Traits/FileCheckerValidCodeParseTestTrait.php +++ b/tests/Traits/FileCheckerValidCodeParseTestTrait.php @@ -26,7 +26,7 @@ abstract public function providerFileCheckerValidCodeParse(); */ public function testValidCode($code, $assertions = [], $error_levels = [], $scope_vars = []) { - $test_name = $this->getName(); + $test_name = $this->getTestName(); if (strpos($test_name, 'PHP7-') !== false) { if (version_compare(PHP_VERSION, '7.0.0dev', '<')) { $this->markTestSkipped('Test case requires PHP 7.'); diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index c8b631761f7..627957cc444 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -40,7 +40,7 @@ public function setUp() */ public function testValidCode($code, array $error_levels = []) { - $test_name = $this->getName(); + $test_name = $this->getTestName(); if (strpos($test_name, 'PHP7-') !== false) { if (version_compare(PHP_VERSION, '7.0.0dev', '<')) { $this->markTestSkipped('Test case requires PHP 7.'); @@ -81,7 +81,7 @@ public function testValidCode($code, array $error_levels = []) */ public function testInvalidCode($code, $error_message, $error_levels = []) { - if (strpos($this->getName(), 'SKIPPED-') !== false) { + if (strpos($this->getTestName(), 'SKIPPED-') !== false) { $this->markTestSkipped(); } diff --git a/tests/UnusedVariableTest.php b/tests/UnusedVariableTest.php index 36cd06bd577..fde78c9af85 100644 --- a/tests/UnusedVariableTest.php +++ b/tests/UnusedVariableTest.php @@ -40,7 +40,7 @@ public function setUp() */ public function testValidCode($code, array $error_levels = []) { - $test_name = $this->getName(); + $test_name = $this->getTestName(); if (strpos($test_name, 'PHP7-') !== false) { if (version_compare(PHP_VERSION, '7.0.0dev', '<')) { $this->markTestSkipped('Test case requires PHP 7.'); @@ -81,7 +81,7 @@ public function testValidCode($code, array $error_levels = []) */ public function testInvalidCode($code, $error_message, $error_levels = []) { - if (strpos($this->getName(), 'SKIPPED-') !== false) { + if (strpos($this->getTestName(), 'SKIPPED-') !== false) { $this->markTestSkipped(); } From 777fbf741bee68727e2d7b4eacca6cbaae19f05d Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Fri, 13 Jul 2018 05:02:40 +0300 Subject: [PATCH 4/5] don't disable xdebug if it's not enabled --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1392a8fa080..5846cee1046 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,10 +29,11 @@ cache: before_install: # determine INI file - - export INI=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini + - export INI_DIR=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d + - export INI=$INI_DIR/travis.ini # disable default memory limit - echo memory_limit = 2G >> $INI - - if [[ $COVERALLS = "" ]]; then phpenv config-rm xdebug.ini; fi + - if [[ $COVERALLS = "" && -f $INI_DIR/xdebug.ini ]]; then phpenv config-rm xdebug.ini; fi install: - composer --prefer-source $DEPS update From 1e335fee5e2c0e42cd499df1619e2ad798365c35 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Fri, 13 Jul 2018 21:52:35 +0300 Subject: [PATCH 5/5] allowed 7.0/high to fail until PHPUnit 6.5.10 is released see sebastianbergmann/phpunit#3209 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5846cee1046..71e8d262882 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ matrix: env: DEPS="" COVERALLS=true allow_failures: - php: nightly + - php: 7.0 + env: DEPS="" COVERALLS="" php: - 7.0 - 7.1