forked from coenjacobs/mozart
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Namespaces with escaped backslashes in strings are not replaced
@roberts91 coenjacobs#129
- Loading branch information
1 parent
567281d
commit 783d5c2
Showing
1 changed file
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |