From 62b41f817e116052b7fbdc9c2bababd64aa7f48a Mon Sep 17 00:00:00 2001 From: Oleg Zhulnev Date: Sun, 18 Nov 2018 05:40:38 +0300 Subject: [PATCH] Get rid of defaultTestSuite (#573) --- .../Config/Builder/MutationConfigBuilder.php | 9 ++----- .../PhpUnit/Config/XmlConfigurationHelper.php | 7 +++++ tests/Fixtures/Files/phpunit/phpunit.xml | 1 + .../Builder/MutationConfigBuilderTest.php | 13 +++++++++ .../Config/XmlConfigurationHelperTest.php | 27 +++++++++++++++++++ 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php b/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php index 3957da3cb..c5dda3cf4 100644 --- a/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php +++ b/src/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilder.php @@ -59,11 +59,6 @@ class MutationConfigBuilder extends ConfigBuilder */ private $xmlConfigurationHelper; - /** - * @var string - */ - private $originalXmlConfigContent; - /** * @var \DOMDocument */ @@ -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 @@ -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', diff --git a/src/TestFramework/PhpUnit/Config/XmlConfigurationHelper.php b/src/TestFramework/PhpUnit/Config/XmlConfigurationHelper.php index b1e0f8827..a177f9372 100644 --- a/src/TestFramework/PhpUnit/Config/XmlConfigurationHelper.php +++ b/src/TestFramework/PhpUnit/Config/XmlConfigurationHelper.php @@ -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 = ''; diff --git a/tests/Fixtures/Files/phpunit/phpunit.xml b/tests/Fixtures/Files/phpunit/phpunit.xml index ad12dd124..7a8ab15a1 100644 --- a/tests/Fixtures/Files/phpunit/phpunit.xml +++ b/tests/Fixtures/Files/phpunit/phpunit.xml @@ -15,6 +15,7 @@ processIsolation="false" syntaxCheck="false" printerClass="Fake\Printer\Class" + defaultTestSuite="unit" > diff --git a/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php b/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php index cd75fd0c3..157190f67 100644 --- a/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php +++ b/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php @@ -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 [ diff --git a/tests/TestFramework/PhpUnit/Config/XmlConfigurationHelperTest.php b/tests/TestFramework/PhpUnit/Config/XmlConfigurationHelperTest.php index 0ba4e6353..c99b0762c 100644 --- a/tests/TestFramework/PhpUnit/Config/XmlConfigurationHelperTest.php +++ b/tests/TestFramework/PhpUnit/Config/XmlConfigurationHelperTest.php @@ -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 + ); + + $xmlconfig = new XmlConfigurationHelper($this->getPathReplacer(), ''); + + $xmlconfig->removeDefaultTestSuite($dom, new \DOMXPath($dom)); + + $this->assertSame(<< + + + +XML + , $dom->saveXML() + ); + } + private function getDomDocument(): \DOMDocument { $dom = new \DOMDocument();