Skip to content

Commit

Permalink
Update PHPUnit (#888)
Browse files Browse the repository at this point in the history
* upgrade phpunit, test with low and high deps

* work around possibly-anonymous test cases introduced by newer PHPUnit

* 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.

* don't disable xdebug if it's not enabled

* allowed 7.0/high to fail until PHPUnit 6.5.10 is released

see sebastianbergmann/phpunit#3209
  • Loading branch information
weirdan authored and muglug committed Jul 13, 2018
1 parent 4172952 commit c1e21fc
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 15 deletions.
26 changes: 21 additions & 5 deletions .travis.yml
@@ -1,28 +1,44 @@
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
env: DEPS="" COVERALLS=""
php:
- 7.0
- 7.1
- 7.2
- nightly

env:
- DEPS="--prefer-lowest --prefer-stable" COVERALLS=""
- DEPS="" COVERALLS=""
- DEPS="" COVERALLS=true

cache:
directories:
- ./vendor

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 install
- composer --prefer-source $DEPS update

script:
- vendor/bin/phpunit
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/DocumentationTest.php
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/FileManipulationTest.php
Expand Up @@ -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.');
Expand Down
2 changes: 1 addition & 1 deletion tests/FileReferenceTest.php
Expand Up @@ -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.');
Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase.php
Expand Up @@ -4,6 +4,7 @@
use PHPUnit\Framework\TestCase as BaseTestCase;
use Psalm\Checker\FileChecker;
use Psalm\Checker\ProjectChecker;
use RuntimeException;

class TestCase extends BaseTestCase
{
Expand Down Expand Up @@ -99,4 +100,13 @@ public function analyzeFile($file_path, \Psalm\Context $context)
);
$file_checker->analyze($context);
}
protected function getTestName(bool $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;
}
}
2 changes: 1 addition & 1 deletion tests/Traits/FileCheckerInvalidCodeParseTestTrait.php
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Traits/FileCheckerValidCodeParseTestTrait.php
Expand Up @@ -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.');
Expand Down
4 changes: 2 additions & 2 deletions tests/UnusedCodeTest.php
Expand Up @@ -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.');
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/UnusedVariableTest.php
Expand Up @@ -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.');
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit c1e21fc

Please sign in to comment.