From 2a64c24951cf47a0a790d2533efade602d18eb8b Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 27 Dec 2017 16:02:06 +0100 Subject: [PATCH 1/4] A final private __clone() method cannot be covered --- src/Util/Configuration.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Util/Configuration.php b/src/Util/Configuration.php index 0e62fc05985..2137f269fac 100644 --- a/src/Util/Configuration.php +++ b/src/Util/Configuration.php @@ -170,6 +170,9 @@ protected function __construct($filename) $this->xpath = new DOMXPath($this->document); } + /** + * @codeCoverageIgnore + */ final private function __clone() { } From 04dae68e9350e84ce953fed40e6a58a1cfad43a2 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 27 Dec 2017 16:05:24 +0100 Subject: [PATCH 2/4] Fix CS/WS issues --- tests/Util/ConfigurationTest.php | 270 +++++++++++++++---------------- tests/_files/configuration.xml | 173 ++++++++++---------- 2 files changed, 223 insertions(+), 220 deletions(-) diff --git a/tests/Util/ConfigurationTest.php b/tests/Util/ConfigurationTest.php index 2c8ff95c0bf..663b16500de 100644 --- a/tests/Util/ConfigurationTest.php +++ b/tests/Util/ConfigurationTest.php @@ -75,46 +75,46 @@ public function testFilterConfigurationIsReadCorrectly() { $this->assertEquals( [ - 'whitelist' => - [ - 'addUncoveredFilesFromWhitelist' => true, - 'processUncoveredFilesFromWhitelist' => false, - 'include' => - [ - 'directory' => - [ - 0 => - [ - 'path' => '/path/to/files', - 'prefix' => '', - 'suffix' => '.php', - 'group' => 'DEFAULT' - ], - ], - 'file' => - [ - 0 => '/path/to/file', - 1 => '/path/to/file', - ], - ], - 'exclude' => - [ - 'directory' => - [ - 0 => - [ - 'path' => '/path/to/files', - 'prefix' => '', - 'suffix' => '.php', - 'group' => 'DEFAULT' - ], - ], - 'file' => - [ - 0 => '/path/to/file', - ], - ], - ], + 'whitelist' => + [ + 'addUncoveredFilesFromWhitelist' => true, + 'processUncoveredFilesFromWhitelist' => false, + 'include' => + [ + 'directory' => + [ + 0 => + [ + 'path' => '/path/to/files', + 'prefix' => '', + 'suffix' => '.php', + 'group' => 'DEFAULT' + ], + ], + 'file' => + [ + 0 => '/path/to/file', + 1 => '/path/to/file', + ], + ], + 'exclude' => + [ + 'directory' => + [ + 0 => + [ + 'path' => '/path/to/files', + 'prefix' => '', + 'suffix' => '.php', + 'group' => 'DEFAULT' + ], + ], + 'file' => + [ + 0 => '/path/to/file', + ], + ], + ], ], $this->configuration->getFilterConfiguration() ); @@ -124,14 +124,14 @@ public function testGroupConfigurationIsReadCorrectly() { $this->assertEquals( [ - 'include' => - [ - 0 => 'name', - ], - 'exclude' => - [ - 0 => 'name', - ], + 'include' => + [ + 0 => 'name', + ], + 'exclude' => + [ + 0 => 'name', + ], ], $this->configuration->getGroupConfiguration() ); @@ -163,38 +163,38 @@ public function testListenerConfigurationIsReadCorrectly() $this->assertEquals( [ - 0 => - [ - 'class' => 'MyListener', - 'file' => '/optional/path/to/MyListener.php', - 'arguments' => - [ 0 => + [ + 'class' => 'MyListener', + 'file' => '/optional/path/to/MyListener.php', + 'arguments' => + [ + 0 => + [ + 0 => 'Sebastian', + ], + 1 => 22, + 2 => 'April', + 3 => 19.78, + 4 => null, + 5 => new \stdClass, + 6 => \dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'MyTestFile.php', + 7 => \dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'MyRelativePath', + ], + ], [ - 0 => 'Sebastian', + 'class' => 'IncludePathListener', + 'file' => __FILE__, + 'arguments' => [] + ], + [ + 'class' => 'CompactArgumentsListener', + 'file' => '/CompactArgumentsListener.php', + 'arguments' => + [ + 0 => 42 + ], ], - 1 => 22, - 2 => 'April', - 3 => 19.78, - 4 => null, - 5 => new \stdClass, - 6 => \dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'MyTestFile.php', - 7 => \dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'MyRelativePath', - ], - ], - [ - 'class' => 'IncludePathListener', - 'file' => __FILE__, - 'arguments' => [] - ], - [ - 'class' => 'CompactArgumentsListener', - 'file' => '/CompactArgumentsListener.php', - 'arguments' => - [ - 0 => 42 - ], - ], ], $this->configuration->getListenerConfiguration() ); @@ -206,17 +206,17 @@ public function testLoggingConfigurationIsReadCorrectly() { $this->assertEquals( [ - 'lowUpperBound' => '50', - 'highLowerBound' => '90', - 'coverage-html' => '/tmp/report', - 'coverage-clover' => '/tmp/clover.xml', - 'json' => '/tmp/logfile.json', - 'plain' => '/tmp/logfile.txt', - 'tap' => '/tmp/logfile.tap', - 'junit' => '/tmp/logfile.xml', - 'testdox-html' => '/tmp/testdox.html', - 'testdox-text' => '/tmp/testdox.txt', - 'testdox-xml' => '/tmp/testdox.xml' + 'lowUpperBound' => '50', + 'highLowerBound' => '90', + 'coverage-html' => '/tmp/report', + 'coverage-clover' => '/tmp/clover.xml', + 'json' => '/tmp/logfile.json', + 'plain' => '/tmp/logfile.txt', + 'tap' => '/tmp/logfile.tap', + 'junit' => '/tmp/logfile.xml', + 'testdox-html' => '/tmp/testdox.html', + 'testdox-text' => '/tmp/testdox.txt', + 'testdox-xml' => '/tmp/testdox.xml' ], $this->configuration->getLoggingConfiguration() ); @@ -226,21 +226,21 @@ public function testPHPConfigurationIsReadCorrectly() { $this->assertEquals( [ - 'include_path' => - [ - \dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . '.', - '/path/to/lib' - ], - 'ini' => ['foo' => ['value' => 'bar']], - 'const' => ['FOO' => ['value' => false], 'BAR' => ['value' => true]], - 'var' => ['foo' => ['value' => false]], - 'env' => ['foo' => ['value' => true], 'bar' => ['value' => 'true', 'verbatim' => true], 'foo_force' => ['value' => 'forced', 'force' => true]], - 'post' => ['foo' => ['value' => 'bar']], - 'get' => ['foo' => ['value' => 'bar']], - 'cookie' => ['foo' => ['value' => 'bar']], - 'server' => ['foo' => ['value' => 'bar']], - 'files' => ['foo' => ['value' => 'bar']], - 'request'=> ['foo' => ['value' => 'bar']], + 'include_path' => + [ + \dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . '.', + '/path/to/lib' + ], + 'ini' => ['foo' => ['value' => 'bar']], + 'const' => ['FOO' => ['value' => false], 'BAR' => ['value' => true]], + 'var' => ['foo' => ['value' => false]], + 'env' => ['foo' => ['value' => true], 'bar' => ['value' => 'true', 'verbatim' => true], 'foo_force' => ['value' => 'forced', 'force' => true]], + 'post' => ['foo' => ['value' => 'bar']], + 'get' => ['foo' => ['value' => 'bar']], + 'cookie' => ['foo' => ['value' => 'bar']], + 'server' => ['foo' => ['value' => 'bar']], + 'files' => ['foo' => ['value' => 'bar']], + 'request'=> ['foo' => ['value' => 'bar']], ], $this->configuration->getPHPConfiguration() ); @@ -328,38 +328,38 @@ public function testPHPUnitConfigurationIsReadCorrectly() { $this->assertEquals( [ - 'backupGlobals' => true, - 'backupStaticAttributes' => false, - 'beStrictAboutChangesToGlobalState' => false, - 'bootstrap' => '/path/to/bootstrap.php', - 'cacheTokens' => false, - 'columns' => 80, - 'colors' => 'never', - 'stderr' => false, - 'convertDeprecationsToExceptions' => true, - 'convertErrorsToExceptions' => true, - 'convertNoticesToExceptions' => true, - 'convertWarningsToExceptions' => true, - 'forceCoversAnnotation' => false, - 'stopOnFailure' => false, - 'stopOnWarning' => false, - 'reportUselessTests' => false, - 'strictCoverage' => false, - 'disallowTestOutput' => false, - 'enforceTimeLimit' => false, - 'extensionsDirectory' => '/tmp', - 'printerClass' => 'PHPUnit\TextUI\ResultPrinter', - 'testSuiteLoaderClass' => 'PHPUnit\Runner\StandardTestSuiteLoader', - 'defaultTestSuite' => 'My Test Suite', - 'verbose' => false, - 'timeoutForSmallTests' => 1, - 'timeoutForMediumTests' => 10, - 'timeoutForLargeTests' => 60, - 'beStrictAboutResourceUsageDuringSmallTests' => false, - 'disallowTodoAnnotatedTests' => false, - 'failOnWarning' => false, - 'failOnRisky' => false, - 'ignoreDeprecatedCodeUnitsFromCodeCoverage' => false + 'backupGlobals' => true, + 'backupStaticAttributes' => false, + 'beStrictAboutChangesToGlobalState' => false, + 'bootstrap' => '/path/to/bootstrap.php', + 'cacheTokens' => false, + 'columns' => 80, + 'colors' => 'never', + 'stderr' => false, + 'convertDeprecationsToExceptions' => true, + 'convertErrorsToExceptions' => true, + 'convertNoticesToExceptions' => true, + 'convertWarningsToExceptions' => true, + 'forceCoversAnnotation' => false, + 'stopOnFailure' => false, + 'stopOnWarning' => false, + 'reportUselessTests' => false, + 'strictCoverage' => false, + 'disallowTestOutput' => false, + 'enforceTimeLimit' => false, + 'extensionsDirectory' => '/tmp', + 'printerClass' => 'PHPUnit\TextUI\ResultPrinter', + 'testSuiteLoaderClass' => 'PHPUnit\Runner\StandardTestSuiteLoader', + 'defaultTestSuite' => 'My Test Suite', + 'verbose' => false, + 'timeoutForSmallTests' => 1, + 'timeoutForMediumTests' => 10, + 'timeoutForLargeTests' => 60, + 'beStrictAboutResourceUsageDuringSmallTests' => false, + 'disallowTodoAnnotatedTests' => false, + 'failOnWarning' => false, + 'failOnRisky' => false, + 'ignoreDeprecatedCodeUnitsFromCodeCoverage' => false ], $this->configuration->getPHPUnitConfiguration() ); diff --git a/tests/_files/configuration.xml b/tests/_files/configuration.xml index 1fbed0e0534..c4996f70cba 100644 --- a/tests/_files/configuration.xml +++ b/tests/_files/configuration.xml @@ -1,5 +1,4 @@ - - - - /path/to/files - /path/to/MyTest.php - - + + + /path/to/files + /path/to/MyTest.php + + - - - name - - - name - - + + + name + + + name + + - - - name - - - name - - + + + name + + + name + + - - - /path/to/files - /path/to/file - - /path/to/file - - - /path/to/files - /path/to/file - - - + + + /path/to/files + /path/to/file + + /path/to/file + + + /path/to/files + /path/to/file + + + - - - - - - Sebastian - - - 22 - April - 19.78 - - - MyTestFile.php - MyRelativePath - - - - 42 - + + + + + + Sebastian + + + 22 + April + 19.78 + + + MyTestFile.php + MyRelativePath + + + + + + 42 + + + - - - - - - - - - - - + + + + + + + + + + + - - . - /path/to/lib - - - - - - - - - - - - - - + + . + /path/to/lib + + + + + + + + + + + + + + From 3eeb4420c666a95dda9e7108855ee65298a39f64 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 27 Dec 2017 16:13:43 +0100 Subject: [PATCH 3/4] Improve test coverage of PHPUnit\Util\Configuration::getLoggingConfiguration() --- tests/Util/ConfigurationTest.php | 27 ++++++++++++++++----------- tests/_files/configuration.xml | 2 ++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/Util/ConfigurationTest.php b/tests/Util/ConfigurationTest.php index 663b16500de..f484ff7cc7d 100644 --- a/tests/Util/ConfigurationTest.php +++ b/tests/Util/ConfigurationTest.php @@ -206,17 +206,22 @@ public function testLoggingConfigurationIsReadCorrectly() { $this->assertEquals( [ - 'lowUpperBound' => '50', - 'highLowerBound' => '90', - 'coverage-html' => '/tmp/report', - 'coverage-clover' => '/tmp/clover.xml', - 'json' => '/tmp/logfile.json', - 'plain' => '/tmp/logfile.txt', - 'tap' => '/tmp/logfile.tap', - 'junit' => '/tmp/logfile.xml', - 'testdox-html' => '/tmp/testdox.html', - 'testdox-text' => '/tmp/testdox.txt', - 'testdox-xml' => '/tmp/testdox.xml' + 'lowUpperBound' => '50', + 'highLowerBound' => '90', + 'coverage-html' => '/tmp/report', + 'coverage-clover' => '/tmp/clover.xml', + 'coverage-crap4j' => '/tmp/crap4j.xml', + 'crap4jThreshold' => 50, + 'coverage-text' => '/tmp/coverage.txt', + 'coverageTextShowUncoveredFiles' => true, + 'coverageTextShowOnlySummary' => true, + 'json' => '/tmp/logfile.json', + 'plain' => '/tmp/logfile.txt', + 'tap' => '/tmp/logfile.tap', + 'junit' => '/tmp/logfile.xml', + 'testdox-html' => '/tmp/testdox.html', + 'testdox-text' => '/tmp/testdox.txt', + 'testdox-xml' => '/tmp/testdox.xml' ], $this->configuration->getLoggingConfiguration() ); diff --git a/tests/_files/configuration.xml b/tests/_files/configuration.xml index c4996f70cba..401db05aa32 100644 --- a/tests/_files/configuration.xml +++ b/tests/_files/configuration.xml @@ -99,6 +99,8 @@ + + From 0d4a39498c4c2350e7a6eaa0068b1eada55f9bf8 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 27 Dec 2017 16:21:28 +0100 Subject: [PATCH 4/4] Use appropriate assertions --- tests/Util/ConfigurationTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Util/ConfigurationTest.php b/tests/Util/ConfigurationTest.php index f484ff7cc7d..8500946fcb3 100644 --- a/tests/Util/ConfigurationTest.php +++ b/tests/Util/ConfigurationTest.php @@ -260,11 +260,11 @@ public function testPHPConfigurationIsHandledCorrectly() $path = \dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . '.' . PATH_SEPARATOR . '/path/to/lib'; $this->assertStringStartsWith($path, \ini_get('include_path')); - $this->assertEquals(false, \FOO); - $this->assertEquals(true, \BAR); - $this->assertEquals(false, $GLOBALS['foo']); - $this->assertEquals(true, $_ENV['foo']); - $this->assertEquals(true, \getenv('foo')); + $this->assertFalse(\FOO); + $this->assertTrue(\BAR); + $this->assertFalse($GLOBALS['foo']); + $this->assertTrue($_ENV['foo']); + $this->assertEquals(1, \getenv('foo')); $this->assertEquals('bar', $_POST['foo']); $this->assertEquals('bar', $_GET['foo']); $this->assertEquals('bar', $_COOKIE['foo']); @@ -283,8 +283,8 @@ public function testHandlePHPConfigurationDoesNotOverwrittenExistingEnvArrayVari $_ENV['foo'] = false; $this->configuration->handlePHPConfiguration(); - $this->assertEquals(false, $_ENV['foo']); - $this->assertEquals(true, \getenv('foo')); + $this->assertFalse($_ENV['foo']); + $this->assertEquals(1, \getenv('foo')); } /** @@ -311,7 +311,7 @@ public function testHandlePHPConfigurationDoesNotOverriteVariablesFromPutEnv() \putenv('foo=putenv'); $this->configuration->handlePHPConfiguration(); - $this->assertEquals(true, $_ENV['foo']); + $this->assertTrue($_ENV['foo']); $this->assertEquals('putenv', \getenv('foo')); }