Skip to content

Commit

Permalink
Merge branch '0.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Nov 18, 2018
2 parents 65be86b + 62b41f8 commit 739e782
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
Expand Up @@ -59,11 +59,6 @@ class MutationConfigBuilder extends ConfigBuilder
*/
private $xmlConfigurationHelper;

/**
* @var string
*/
private $originalXmlConfigContent;

/**
* @var \DOMDocument
*/
Expand All @@ -75,12 +70,11 @@ public function __construct(string $tempDirectory, string $originalXmlConfigCont
$this->projectDir = $projectDir;

$this->xmlConfigurationHelper = $xmlConfigurationHelper;
$this->originalXmlConfigContent = $originalXmlConfigContent;

$this->dom = new \DOMDocument();
$this->dom->preserveWhiteSpace = false;
$this->dom->formatOutput = true;
$this->dom->loadXML($this->originalXmlConfigContent);
$this->dom->loadXML($originalXmlConfigContent);
}

public function build(MutantInterface $mutant): string
Expand All @@ -95,6 +89,7 @@ public function build(MutantInterface $mutant): string
$this->xmlConfigurationHelper->deactivateColours($xPath);
$this->xmlConfigurationHelper->removeExistingLoggers($dom, $xPath);
$this->xmlConfigurationHelper->removeExistingPrinters($dom, $xPath);
$this->xmlConfigurationHelper->removeDefaultTestSuite($dom, $xPath);

$customAutoloadFilePath = sprintf(
'%s/interceptor.autoload.%s.infection.php',
Expand Down
7 changes: 7 additions & 0 deletions src/TestFramework/PhpUnit/Config/XmlConfigurationHelper.php
Expand Up @@ -137,6 +137,13 @@ public function validate(\DOMDocument $dom, \DOMXPath $xPath): bool
return true;
}

public function removeDefaultTestSuite(\DOMDocument $dom, \DOMXPath $xPath): void
{
if ($xPath->query('/phpunit/@defaultTestSuite')->length) {
$dom->documentElement->removeAttribute('defaultTestSuite');
}
}

private function getXmlErrorsString(): string
{
$errorsString = '';
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/Files/phpunit/phpunit.xml
Expand Up @@ -15,6 +15,7 @@
processIsolation="false"
syntaxCheck="false"
printerClass="Fake\Printer\Class"
defaultTestSuite="unit"
>
<testsuites>
<testsuite name="Application Test Suite">
Expand Down
Expand Up @@ -262,6 +262,19 @@ public function test_it_sets_sorted_list_of_test_files(array $coverageTests, arr
$this->assertSame($expectedFiles, $files);
}

public function test_it_removes_default_test_suite(): void
{
$this->mutant->shouldReceive('getCoverageTests')->andReturn([]);

$configurationPath = $this->builder->build($this->mutant);

$xml = file_get_contents($configurationPath);

$value = $this->queryXpath($xml, '/phpunit/@defaultTestSuite');

$this->assertCount(0, $value);
}

public function coverageTestsProvider(): array
{
return [
Expand Down
27 changes: 27 additions & 0 deletions tests/TestFramework/PhpUnit/Config/XmlConfigurationHelperTest.php
Expand Up @@ -328,6 +328,33 @@ public function test_it_passes_validation_by_xsd(string $xsdSchema): void
$this->assertTrue(true, $xmlHelper->validate($dom, $xPath));
}

public function test_it_removes_default_test_suite(): void
{
$dom = new \DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML(<<<XML
<?xml version="1.0" encoding="UTF-8"?>
<phpunit syntaxCheck="false" printerClass="Fake\Printer\Class" stopOnFailure="false" defaultTestSuite="unit">
</phpunit>

XML
);

$xmlconfig = new XmlConfigurationHelper($this->getPathReplacer(), '');

$xmlconfig->removeDefaultTestSuite($dom, new \DOMXPath($dom));

$this->assertSame(<<<XML
<?xml version="1.0" encoding="UTF-8"?>
<phpunit syntaxCheck="false" printerClass="Fake\Printer\Class" stopOnFailure="false">
</phpunit>

XML
, $dom->saveXML()
);
}

private function getDomDocument(): \DOMDocument
{
$dom = new \DOMDocument();
Expand Down

0 comments on commit 739e782

Please sign in to comment.