123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- <?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\Alias;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @author Vladimir Reznichenko <kalessil@gmail.com>
- * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\Alias\NoAliasFunctionsFixer
- */
- final class NoAliasFunctionsFixerTest extends AbstractFixerTestCase
- {
- /**
- * @param string $expected
- * @param null|string $input
- *
- * @dataProvider provideFixCases
- */
- public function testFix($expected, $input = null)
- {
- $this->doTest($expected, $input);
- }
- public function provideFixCases()
- {
- $cases = [];
- foreach (['internalSet', 'imapSet'] as $setStaticAttributeName) {
- /** @var string[] $aliases */
- $aliases = static::getStaticAttribute(\PhpCsFixer\Fixer\Alias\NoAliasFunctionsFixer::class, $setStaticAttributeName);
- foreach ($aliases as $alias => $master) {
- // valid cases
- $cases[] = ["<?php \$smth->{$alias}(\$a);"];
- $cases[] = ["<?php {$alias}Smth(\$a);"];
- $cases[] = ["<?php smth_{$alias}(\$a);"];
- $cases[] = ["<?php new {$alias}(\$a);"];
- $cases[] = ["<?php new Smth\\{$alias}(\$a);"];
- $cases[] = ["<?php Smth\\{$alias}(\$a);"];
- $cases[] = ["<?php namespace\\{$alias}(\$a);"];
- $cases[] = ["<?php Smth::{$alias}(\$a);"];
- $cases[] = ["<?php new {$alias}\\smth(\$a);"];
- $cases[] = ["<?php {$alias}::smth(\$a);"];
- $cases[] = ["<?php {$alias}\\smth(\$a);"];
- $cases[] = ['<?php "SELECT ... '.$alias.'(\$a) ...";'];
- $cases[] = ['<?php "SELECT ... '.strtoupper($alias).'($a) ...";'];
- $cases[] = ["<?php 'test'.'{$alias}' . 'in concatenation';"];
- $cases[] = ['<?php "test" . "'.$alias.'"."in concatenation";'];
- $cases[] = [
- '<?php
- class '.ucfirst($alias).'ing
- {
- const '.$alias.' = 1;
- public function '.$alias.'($'.$alias.')
- {
- if (defined("'.$alias.'") || $'.$alias.' instanceof '.$alias.') {
- echo '.$alias.';
- }
- }
- }
- class '.$alias.' extends '.ucfirst($alias).'ing{
- const '.$alias.' = "'.$alias.'";
- }
- ',
- ];
- // cases to be fixed
- $cases[] = [
- "<?php {$master}(\$a);",
- "<?php {$alias}(\$a);",
- ];
- $cases[] = [
- "<?php \\{$master}(\$a);",
- "<?php \\{$alias}(\$a);",
- ];
- $cases[] = [
- "<?php {$master}
- (\$a);",
- "<?php {$alias}
- (\$a);",
- ];
- $cases[] = [
- "<?php /* foo */ {$master} /** bar */ (\$a);",
- "<?php /* foo */ {$alias} /** bar */ (\$a);",
- ];
- $cases[] = [
- "<?php a({$master}());",
- "<?php a({$alias}());",
- ];
- $cases[] = [
- "<?php a(\\{$master}());",
- "<?php a(\\{$alias}());",
- ];
- }
- }
- // static case to fix - in case previous generation is broken
- $cases[] = [
- '<?php is_int($a);',
- '<?php is_integer($a);',
- ];
- $cases[] = [
- '<?php $b=is_int(count(implode($b,$a)));',
- '<?php $b=is_integer(sizeof(join($b,$a)));',
- ];
- $cases[] = [
- '<?php
- interface JoinInterface
- {
- public function &join();
- }
- abstract class A
- {
- abstract public function join($a);
- public function is_integer($a)
- {
- $fputs = "is_double(\$a);\n"; // key_exists($b, $c);
- echo $fputs."\$is_writable";
- \B::close();
- Scope\is_long();
- namespace\is_long();
- $a->pos();
- new join();
- new \join();
- new ScopeB\join(mt_rand(0, 100));
- }
- }',
- ];
- return $cases;
- }
- /**
- * @param string $expected
- * @param string $input
- * @param array<string, string[]> $configuration
- *
- * @dataProvider provideFixWithConfigurationCases
- */
- public function testFixWithConfiguration($expected, $input, array $configuration)
- {
- $this->fixer->configure($configuration);
- $this->doTest($expected, $input);
- }
- public function provideFixWithConfigurationCases()
- {
- return [
- '@internal' => [
- '<?php
- $a = rtrim($b);
- $a = imap_header($imap_stream, 1);
- mbereg_search_getregs();
- ',
- '<?php
- $a = chop($b);
- $a = imap_header($imap_stream, 1);
- mbereg_search_getregs();
- ',
- ['sets' => ['@internal']],
- ],
- '@IMAP' => [
- '<?php
- $a = chop($b);
- $a = imap_headerinfo($imap_stream, 1);
- mb_ereg_search_getregs();
- ',
- '<?php
- $a = chop($b);
- $a = imap_header($imap_stream, 1);
- mb_ereg_search_getregs();
- ',
- ['sets' => ['@IMAP']],
- ],
- '@mbreg' => [
- '<?php
- $a = chop($b);
- $a = imap_header($imap_stream, 1);
- mb_ereg_search_getregs();
- mktime();
- ',
- '<?php
- $a = chop($b);
- $a = imap_header($imap_stream, 1);
- mbereg_search_getregs();
- mktime();
- ',
- ['sets' => ['@mbreg']],
- ],
- '@all' => [
- '<?php
- $a = rtrim($b);
- $a = imap_headerinfo($imap_stream, 1);
- mb_ereg_search_getregs();
- time();
- time();
- $foo = exif_read_data($filename, $sections_needed, $sub_arrays, $read_thumbnail);
- mktime($a);
- echo gmmktime(1, 2, 3, 4, 5, 6);
- ',
- '<?php
- $a = chop($b);
- $a = imap_header($imap_stream, 1);
- mbereg_search_getregs();
- mktime();
- gmmktime();
- $foo = read_exif_data($filename, $sections_needed, $sub_arrays, $read_thumbnail);
- mktime($a);
- echo gmmktime(1, 2, 3, 4, 5, 6);
- ',
- ['sets' => ['@all']],
- ],
- '@IMAP, @mbreg' => [
- '<?php
- $a = chop($b);
- $a = imap_headerinfo($imap_stream, 1);
- mb_ereg_search_getregs();
- ',
- '<?php
- $a = chop($b);
- $a = imap_header($imap_stream, 1);
- mbereg_search_getregs();
- ',
- ['sets' => ['@IMAP', '@mbreg']],
- ],
- '@time' => [
- '<?php
- time();
- time();
- MKTIME($A);
- ECHO GMMKTIME(1, 2, 3, 4, 5, 6);
- ',
- '<?php
- MKTIME();
- GMMKTIME();
- MKTIME($A);
- ECHO GMMKTIME(1, 2, 3, 4, 5, 6);
- ',
- ['sets' => ['@time']],
- ],
- '@exif' => [
- '<?php
- $foo = exif_read_data($filename, $sections_needed, $sub_arrays, $read_thumbnail);
- ',
- '<?php
- $foo = read_exif_data($filename, $sections_needed, $sub_arrays, $read_thumbnail);
- ',
- ['sets' => ['@exif']],
- ],
- ];
- }
- }
|