Skip to content

Commit

Permalink
Namespaces with escaped backslashes in strings are not replaced
Browse files Browse the repository at this point in the history
@roberts91
coenjacobs#129
  • Loading branch information
BrianHenryIE committed May 1, 2021
1 parent 567281d commit 783d5c2
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions tests/Issues/MozartIssue129Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* Namespaces with escaped backslashes in strings are not replaced.
*
* @see https://github.com/coenjacobs/mozart/issues/129
*
* Also affects mpdf: Tag.php:170
*
* $className = 'Mpdf\Tag\\';
*
* @author BrianHenryIE
*/

namespace BrianHenryIE\Strauss\Tests\Issues;

use BrianHenryIE\Strauss\ChangeEnumerator;
use BrianHenryIE\Strauss\Composer\Extra\StraussConfig;
use BrianHenryIE\Strauss\Prefixer;
use PHPUnit\Framework\TestCase;

/**
* Class MozartIssue129Test
* @package BrianHenryIE\Strauss\Tests\Issues
* @coversNothing
*/
class MozartIssue129Test extends TestCase
{

/**
* @author BrianHenryIE
*
* @dataProvider pairTestDataProvider
*/
public function test_test($phpString, $expected)
{

$config = $this->createMock(StraussConfig::class);

$original = 'Example\Sdk\Endpoints';
$replacement = 'Strauss\Example\Sdk\Endpoints';

$replacer = new Prefixer($config, __DIR__);

$result = $replacer->replaceNamespace($phpString, $original, $replacement);

$this->assertEquals($expected, $result);
}

public function pairTestDataProvider()
{

$fromTo = [];

$contents = <<<'EOD'
$baseNamespace = "\Example\Sdk\Endpoints";
EOD;
$expected = <<<'EOD'
$baseNamespace = "\Strauss\Example\Sdk\Endpoints";
EOD;
$fromTo[] = [ $contents, $expected];

$contents = <<<'EOD'
$baseNamespace = "Example\\Sdk\\Endpoints";
EOD;
$expected = <<<'EOD'
$baseNamespace = "Strauss\\Example\\Sdk\\Endpoints";
EOD;
$fromTo[] = [ $contents, $expected];

$contents = <<<'EOD'
$baseNamespace = "Example\Sdk\Endpoints";
EOD;
$expected = <<<'EOD'
$baseNamespace = "Strauss\Example\Sdk\Endpoints";
EOD;
$fromTo[] = [ $contents, $expected];

$contents = <<<'EOD'
$baseNamespace = '\\Example\\Sdk\\Endpoints';
EOD;
$expected = <<<'EOD'
$baseNamespace = '\\Strauss\\Example\\Sdk\\Endpoints';
EOD;
$fromTo[] = [ $contents, $expected];

$contents = <<<'EOD'
$baseNamespace = '\Example\Sdk\Endpoints';
EOD;
$expected = <<<'EOD'
$baseNamespace = '\Strauss\Example\Sdk\Endpoints';
EOD;
$fromTo[] = [ $contents, $expected];

$contents = <<<'EOD'
$baseNamespace = 'Example\\Sdk\\Endpoints';
EOD;
$expected = <<<'EOD'
$baseNamespace = 'Strauss\\Example\\Sdk\\Endpoints';
EOD;
$fromTo[] = [ $contents, $expected];

$contents = <<<'EOD'
$baseNamespace = 'Example\Sdk\Endpoints';
EOD;
$expected = <<<'EOD'
$baseNamespace = 'Strauss\Example\Sdk\Endpoints';
EOD;
$fromTo[] = [ $contents, $expected];

return $fromTo;
}
}

0 comments on commit 783d5c2

Please sign in to comment.