Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change transformers order, fixing untransformed T_USE
- Loading branch information
1 parent
5d82d40
commit dd80318
Showing
5 changed files
with
104 additions
and
3 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
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
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
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
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,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* Dariusz Rumiński <dariusz.ruminski@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpCsFixer\Tests\Tokenizer; | ||
|
||
use PhpCsFixer\Tests\TestCase; | ||
use PhpCsFixer\Tokenizer\CT; | ||
use PhpCsFixer\Tokenizer\Tokens; | ||
|
||
/** | ||
* @author Dave van der Brugge <dmvdbrugge@gmail.com> | ||
* | ||
* @internal | ||
* | ||
* @covers \PhpCsFixer\Tokenizer\Transformers | ||
*/ | ||
final class TransformersTest extends TestCase | ||
{ | ||
public function testTransformLoopOrder() | ||
{ | ||
$source = <<<'SOURCE' | ||
<?php | ||
class TransformTest extends TestCase | ||
{ | ||
public function testSomething() | ||
{ | ||
$a = 1; | ||
$this->assertSame('1', "{$a}"); | ||
} | ||
use TestTrait; | ||
public function testUsingTrait() | ||
{ | ||
$this->testTraitFunction(); | ||
} | ||
} | ||
SOURCE; | ||
|
||
$tokens = Tokens::fromCode($source); | ||
|
||
/* | ||
* If transform would loop over $tokens first, transformers second, both assertions fail, because when the | ||
* 'class' token is detected in the UseTransformer, the T_CURLY_CLOSE from the string variable will not have | ||
* been transformed by the CurlyBraceTransformer. The UseTransformer thus thinks the class ends at the end of | ||
* the first method instead, and not transform the use. | ||
*/ | ||
$this->assertFalse($tokens->isTokenKindFound(T_USE)); | ||
$this->assertTrue($tokens->isTokenKindFound(CT::T_USE_TRAIT)); | ||
} | ||
} |