123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?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\Fixer\LanguageConstruct;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @author Vladimir Reznichenko <kalessil@gmail.com>
- *
- * @internal
- *
- * @covers \PhpCsFixer\AbstractFunctionReferenceFixer
- * @covers \PhpCsFixer\Fixer\LanguageConstruct\DirConstantFixer
- */
- final class DirConstantFixerTest extends AbstractFixerTestCase
- {
- /**
- * @param string $expected
- * @param null|string $input
- *
- * @dataProvider provideFixCases
- */
- public function testFix($expected, $input = null)
- {
- $this->doTest($expected, $input);
- }
- public function provideFixCases()
- {
- $multiLinePatternToFix = <<<'FIX'
- <?php $x =
- dirname
- (
- __FILE__
- )
- ;
- FIX;
- $multiLinePatternFixed = <<<'FIXED'
- <?php $x =
- __DIR__
- ;
- FIXED;
- return [
- ['<?php $x = "dirname";'],
- ['<?php $x = dirname(__FILE__.".dist");'],
- ['<?php $x = ClassA::dirname(__FILE__);'],
- ['<?php $x = ScopeA\\dirname(__FILE__);'],
- ['<?php $x = namespace\\dirname(__FILE__);'],
- ['<?php $x = $object->dirname(__FILE__);'],
- ['<?php $x = new \\dirname(__FILE__);'],
- ['<?php $x = new dirname(__FILE__);'],
- ['<?php $x = new ScopeB\\dirname(__FILE__);'],
- ['<?php dirnameSmth(__FILE__);'],
- ['<?php smth_dirname(__FILE__);'],
- ['<?php "SELECT ... dirname(__FILE__) ...";'],
- ['<?php "SELECT ... DIRNAME(__FILE__) ...";'],
- ['<?php "test" . "dirname" . "in concatenation";'],
- [
- '<?php $x = dirname(__DIR__);',
- '<?php $x = dirname(dirname(__FILE__));',
- ],
- [
- '<?php $x = __DIR__;',
- '<?php $x = dirname(__FILE__);',
- ],
- [
- '<?php $x = __DIR__;',
- '<?php $x = \\dirname(__FILE__);',
- ],
- [
- '<?php $x = __DIR__.".dist";',
- '<?php $x = dirname(__FILE__).".dist";',
- ],
- [
- '<?php $x = __DIR__.".dist";',
- '<?php $x = \\dirname(__FILE__).".dist";',
- ],
- [$multiLinePatternFixed, $multiLinePatternToFix],
- [
- '<?php $x = /**//**/ /** x*//**//** */__DIR__/***//*xx*/;',
- '<?php $x = /**/dirname/**/ /** x*/(/**//** */__FILE__/***/)/*xx*/;',
- ],
- [
- '<?php
- interface Test
- {
- public function dirname($a);
- }',
- ],
- [
- '<?php
- interface Test
- {
- public function &dirname($a);
- }',
- ],
- [
- "<?php echo __DIR__\n?>",
- "<?php echo dirname\n(\n__FILE__\n)\n?>",
- ],
- [
- '<?php $x =# A
- # A1
- # B
- # C
- __DIR__# D
- # E
- ;# F
- ',
- '<?php $x =# A
- \
- # A1
- dirname# B
- (# C
- __FILE__# D
- )# E
- ;# F
- ',
- ],
- ];
- }
- }
|