123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <?php
- declare(strict_types=1);
- /*
- * 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\ControlStructure;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @author Саша Стаменковић <umpirsky@gmail.com>
- *
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\ControlStructure\IncludeFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ControlStructure\IncludeFixer>
- */
- final class IncludeFixerTest extends AbstractFixerTestCase
- {
- /**
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<int|string, array{0: string, 1?: string}>
- */
- public static function provideFixCases(): iterable
- {
- yield [
- '<?php include # A
- # B
- # C
- "a"# D
- # E
- # F
- ;# G
- # H',
- '<?php include# A
- (# B
- # C
- "a"# D
- # E
- )# F
- ;# G
- # H',
- ];
- yield [
- '<?php include $a;',
- '<?php include ( $a ) ;',
- ];
- yield [
- '<?php
- require_once "test1.php";
- include_once "test2.php";
- require "test3.php";
- include "test4.php";',
- '<?php
- require_once("test1.php");
- include_once("test2.php");
- require("test3.php");
- include("test4.php");',
- ];
- yield [
- '<?php
- require_once #1
- #2
- #3
- "test1.php"#4
- #5
- #6
- ;',
- '<?php
- require_once #1
- (#2
- #3
- "test1.php"#4
- )#5
- #6
- ;',
- ];
- yield [
- '<?php foo(require "foo.php");',
- '<?php foo(require("foo.php"));',
- ];
- yield [
- '<?php $foo[include "foo.php"];',
- '<?php $foo[include("foo.php")];',
- ];
- $template = '<?php %s';
- foreach (['require', 'require_once', 'include', 'include_once'] as $statement) {
- yield [
- \sprintf($template.' "foo.php"?>', $statement),
- \sprintf($template.' ("foo.php") ?>', $statement),
- ];
- yield [
- \sprintf($template.' /**/"foo.php"// test
- ?>', $statement),
- \sprintf($template.'/**/ ("foo.php") // test
- ?>', $statement),
- ];
- yield [
- \sprintf($template.' $a;', $statement),
- \sprintf($template.'$a;', $statement),
- ];
- yield [
- \sprintf($template.' $a;', $statement),
- \sprintf($template.' $a;', $statement),
- ];
- yield [
- \sprintf($template.' $a; ', $statement),
- \sprintf($template.' $a ; ', $statement),
- ];
- yield [
- \sprintf($template." /**/'foo.php';", $statement),
- \sprintf($template."/**/'foo.php';", $statement),
- ];
- yield [
- \sprintf($template." 'foo.php';", $statement),
- \sprintf($template."'foo.php';", $statement),
- ];
- yield [
- \sprintf($template." 'foo.php';", $statement),
- \sprintf($template." 'foo.php';", $statement),
- ];
- yield [
- \sprintf($template." 'foo.php';", $statement),
- \sprintf($template."('foo.php');", $statement),
- ];
- yield [
- \sprintf($template." 'foo.php';", $statement),
- \sprintf($template."( 'foo.php');", $statement),
- ];
- yield [
- \sprintf($template." 'foo.php';", $statement),
- \sprintf($template." ( 'foo.php' );", $statement),
- ];
- yield [
- \sprintf($template." '\".__DIR__.\"/../bootstrap.php';", $statement),
- ];
- yield [
- \sprintf('<?php // %s foo', $statement),
- ];
- yield [
- \sprintf('<?php /* %s foo */', $statement),
- ];
- yield [
- \sprintf('<?php /** %s foo */', $statement),
- ];
- yield [
- \sprintf($template.'($a ? $b : $c) . $d;', $statement),
- ];
- yield [
- \sprintf($template.' ($a ? $b : $c) . $d;', $statement),
- ];
- yield [
- \sprintf('<?php exit("POST must %s \"file\"");', $statement),
- ];
- yield [
- \sprintf('<?php ClassCollectionLoader::load(%s($this->getCacheDir().\'classes.map\'), $this->getCacheDir(), $name, $this->debug, false, $extension);', $statement),
- ];
- yield [
- \sprintf('<?php $foo = (false === %s($zfLibraryPath."/Zend/Loader/StandardAutoloader.php"));', $statement),
- ];
- yield [
- \sprintf($template.' "Buzz/foo-Bar.php";', $statement),
- \sprintf($template.' ( "Buzz/foo-Bar.php" );', $statement),
- ];
- yield [
- \sprintf($template.' "$buzz/foo-Bar.php";', $statement),
- \sprintf($template.' ( "$buzz/foo-Bar.php" );', $statement),
- ];
- yield [
- \sprintf($template.' "{$buzz}/foo-Bar.php";', $statement),
- \sprintf($template.' ( "{$buzz}/foo-Bar.php" );', $statement),
- ];
- yield [
- \sprintf($template.' $foo ? "foo.php" : "bar.php";', $statement),
- \sprintf($template.'($foo ? "foo.php" : "bar.php");', $statement),
- ];
- yield [
- \sprintf($template.' $foo ? "foo.php" : "bar.php";', $statement),
- \sprintf($template.'($foo ? "foo.php" : "bar.php");', $statement),
- ];
- yield [
- \sprintf("<?php return %s __DIR__.'foo.php';", $statement),
- \sprintf("<?php return %s __DIR__.'foo.php';", $statement),
- ];
- yield [
- \sprintf("<?php \$foo = %s __DIR__.('foo.php');", $statement),
- \sprintf("<?php \$foo = %s __DIR__.('foo.php');", $statement),
- ];
- yield [
- \sprintf("<?php %s __DIR__.('foo.php');", $statement),
- \sprintf("<?php %s (__DIR__.('foo.php'));", $statement),
- ];
- yield [
- \sprintf("<?php %s __DIR__ . ('foo.php');", $statement),
- \sprintf("<?php %s (__DIR__ . ('foo.php'));", $statement),
- ];
- yield [
- \sprintf("<?php %s dirname(__FILE__).'foo.php';", $statement),
- \sprintf("<?php %s (dirname(__FILE__).'foo.php');", $statement),
- ];
- yield [
- \sprintf('<?php %s "foo/".CONSTANT."/bar.php";', $statement),
- \sprintf('<?php %s("foo/".CONSTANT."/bar.php");', $statement),
- ];
- yield [
- \sprintf('<?php %s "foo/".CONSTANT."/bar.php"; %s "foo/".CONSTANT."/bar.php";', $statement, $statement),
- \sprintf('<?php %s("foo/".CONSTANT."/bar.php"); %s("foo/".CONSTANT."/bar.php");', $statement, $statement),
- ];
- yield [
- \sprintf('<?php %s "foo/".CONSTANT."/bar.php"; $foo = "bar";', $statement),
- \sprintf('<?php %s("foo/".CONSTANT."/bar.php"); $foo = "bar";', $statement),
- ];
- yield [
- \sprintf('<?php %s "foo/".CONSTANT."/bar.php"; foo();', $statement),
- \sprintf('<?php %s("foo/".CONSTANT."/bar.php"); foo();', $statement),
- ];
- yield [
- \sprintf('<?php %s "foo/" . CONSTANT . "/bar.php";', $statement),
- \sprintf('<?php %s("foo/" . CONSTANT . "/bar.php");', $statement),
- ];
- yield [
- \sprintf('<?php %s SOME_CONST . "file.php"; %s Foo::Bar($baz);', $statement, $statement),
- \sprintf('<?php %s( SOME_CONST . "file.php" ); %s Foo::Bar($baz);', $statement, $statement),
- ];
- yield [
- \sprintf('<?php %s SOME_CONST . "file1.php"; %s Foo::Bar($baz);', $statement, $statement),
- \sprintf('<?php %s SOME_CONST . "file1.php"; %s Foo::Bar($baz);', $statement, $statement),
- ];
- yield $statement.': binary string lower case' => [
- \sprintf($template." b'foo.php';", $statement),
- \sprintf($template."(b'foo.php');", $statement),
- ];
- yield $statement.': binary string upper case' => [
- \sprintf($template." B'foo.php';", $statement),
- \sprintf($template."(B'foo.php');", $statement),
- ];
- }
- }
- }
|