Skip to content

Commit

Permalink
Trim "\n" and "\t" characters when replacing relative paths with abso…
Browse files Browse the repository at this point in the history
…lute ones during XML config creation (#1550)

Fixes #1542
  • Loading branch information
maks-rafalko committed Aug 9, 2021
1 parent 5c6b61f commit d3f81b1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/TestFramework/PhpUnit/Config/Path/PathReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use function Safe\sprintf;
use function str_replace;
use Symfony\Component\Filesystem\Filesystem;
use function trim;

/**
* @internal
Expand All @@ -61,11 +62,13 @@ public function __construct(Filesystem $filesystem, ?string $phpUnitConfigDir =
*/
public function replaceInNode(DOMNode $domElement): void
{
if (!$this->filesystem->isAbsolutePath($domElement->nodeValue)) {
$path = trim($domElement->nodeValue);

if (!$this->filesystem->isAbsolutePath($path)) {
$newPath = sprintf(
'%s/%s',
$this->phpUnitConfigDir,
ltrim($domElement->nodeValue, '\/')
ltrim($path, '\/')
);

// remove all occurrences of "/./". realpath can't be used because of glob patterns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,36 @@ static function (XmlConfigurationManipulator $configManipulator, SafeDOMXPath $x
);
}

public function test_it_replaces_with_absolute_paths_xml_file_with_tabs(): void
{
$this->assertItChangesXML(
<<<'XML'
<phpunit cacheTokens="true">
<testsuites>
<testsuite name="All Tests">
<directory suffix="UnitTest.php">
./Tests
</directory>
</testsuite>
</testsuites>
</phpunit>
XML
,
static function (XmlConfigurationManipulator $configManipulator, SafeDOMXPath $xPath): void {
$configManipulator->replaceWithAbsolutePaths($xPath);
},
<<<'XML'
<phpunit cacheTokens="true">
<testsuites>
<testsuite name="All Tests">
<directory suffix="UnitTest.php">/Tests</directory>
</testsuite>
</testsuites>
</phpunit>
XML
);
}

public function test_it_removes_existing_loggers_from_pre_93_configuration(): void
{
$this->assertItChangesPrePHPUnit93Configuration(
Expand Down

0 comments on commit d3f81b1

Please sign in to comment.