Skip to content

Commit

Permalink
Improve test coverage of Configuration
Browse files Browse the repository at this point in the history
- test a list of root config options not covered elsewhere
- test validation errors reusing existing 'invalid colors' test
- indirectly test integer default value of attribute via 'columns'
- add 'disableCodeCoverageIgnore' found in missing coverage to schema
  • Loading branch information
Ewout Pieter den Ouden authored and sebastianbergmann committed Jun 1, 2018
1 parent 0b01bce commit eeb4122
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpunit.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
<xs:attribute name="convertErrorsToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="convertNoticesToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="convertWarningsToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="disableCodeCoverageIgnore" type="xs:boolean" default="false"/>
<xs:attribute name="forceCoversAnnotation" type="xs:boolean" default="false"/>
<xs:attribute name="printerClass" type="xs:string" default="PHPUnit\TextUI\ResultPrinter"/>
<xs:attribute name="printerFile" type="xs:anyURI"/>
Expand Down
1 change: 1 addition & 0 deletions src/Util/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* convertErrorsToExceptions="true"
* convertNoticesToExceptions="true"
* convertWarningsToExceptions="true"
* disableCodeCoverageIgnore="false"
* forceCoversAnnotation="false"
* processIsolation="false"
* stopOnError="false"
Expand Down
61 changes: 61 additions & 0 deletions tests/Util/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use PHPUnit\Framework\Exception;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\TestSuiteSorter;
use PHPUnit\TextUI\ResultPrinter;

class ConfigurationTest extends TestCase
Expand Down Expand Up @@ -71,6 +72,66 @@ public function testShouldReadColorsWhenInvalidInConfigurationFile(): void
$this->assertEquals(ResultPrinter::COLOR_NEVER, $configurationValues['colors']);
}

public function testInvalidConfigurationGeneratesValidationErrors(): void
{
$configurationFilename = \dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'configuration.colors.invalid.xml';
$configurationInstance = Configuration::getInstance($configurationFilename);

$this->assertTrue($configurationInstance->hasValidationErrors());
$this->assertArraySubset([1 => ["Element 'phpunit', attribute 'colors': 'Something else' is not a valid value of the atomic type 'xs:boolean'."]], $configurationInstance->getValidationErrors());
}

public function testNonIntegerValueReturnsDefault(): void
{
$configurationFilename = \dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'configuration.columns.default.xml';
$configurationInstance = Configuration::getInstance($configurationFilename);
$configurationValues = $configurationInstance->getPHPUnitConfiguration();

$this->assertEquals(80, $configurationValues['columns']);
}

/**
* @dataProvider configurationRootOptionsProvider
*
* @param bool|int|string $expected
*/
public function testConfigurationRootOptions(string $optionName, string $optionValue, $expected): void
{
$tmpFilename = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'phpunit.' . $optionName . \uniqid() . '.xml';
$xml = "<phpunit $optionName='$optionValue'></phpunit>" . PHP_EOL;
\file_put_contents($tmpFilename, $xml);

$configurationInstance = Configuration::getInstance($tmpFilename);
$this->assertFalse($configurationInstance->hasValidationErrors(), 'option causes validation error');

$configurationValues = $configurationInstance->getPHPUnitConfiguration();
$this->assertEquals($expected, $configurationValues[$optionName]);

@\unlink($tmpFilename);
}

public function configurationRootOptionsProvider(): array
{
return [
['executionOrder', 'default', TestSuiteSorter::ORDER_DEFAULT],
['executionOrder', 'random', TestSuiteSorter::ORDER_RANDOMIZED],
['executionOrder', 'reverse', TestSuiteSorter::ORDER_REVERSED],
['columns', 'max', 'max'],
['stopOnFailure', 'true', true],
['stopOnWarning', 'true', true],
['stopOnIncomplete', 'true', true],
['stopOnRisky', 'true', true],
['stopOnSkipped', 'true', true],
['failOnWarning', 'true', true],
['failOnRisky', 'true', true],
['disableCodeCoverageIgnore', 'true', true],
['processIsolation', 'true', true],
['testSuiteLoaderFile', '/path/to/file', '/path/to/file'],
['reverseDefectList', 'true', true],
['registerMockObjectsFromTestArgumentsRecursively', 'true', true],
];
}

public function testFilterConfigurationIsReadCorrectly(): void
{
$this->assertEquals(
Expand Down
1 change: 1 addition & 0 deletions tests/_files/configuration.columns.default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<phpunit columns="invalid value"></phpunit>

0 comments on commit eeb4122

Please sign in to comment.