* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace Symfony\CS\Tests\Fixer\Contrib; use Symfony\CS\Tests\Fixer\AbstractFixerTestBase; class OrderedUseFixerTest extends AbstractFixerTestBase { public function testFix() { $expected = <<<'EOF' The normal use of this fixer should not change this sentence nor those statements below use Zoo\Bar; use Foo\Bar; use Foo\Zar\Baz; toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } EOF; $input = <<<'EOF' The normal use of this fixer should not change this sentence nor those statements below use Zoo\Bar; use Foo\Bar; use Foo\Zar\Baz; toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } EOF; $this->makeTest($expected, $input); } public function testFixWithMultipleNamespace() { $expected = <<<'EOF' The normal use of this fixer should not change this sentence nor those statements below use Zoo\Bar; use Foo\Bar; use Foo\Zar\Baz; toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } } namespace BlaRoo { use Foo\Zar\Baz; use SomeClass; use Symfony\Annotation\Template; use Symfony\Doctrine\Entities\Entity, Zoo\Bar; class AnnotatedClass { /** * @Template(foobar=21) * @param Entity $foo */ public function doSomething($foo) { $bar = $foo->toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } } EOF; $input = <<<'EOF' The normal use of this fixer should not change this sentence nor those statements below use Zoo\Bar; use Foo\Bar; use Foo\Zar\Baz; toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } } namespace BlaRoo { use Foo\Zar\Baz; use Zoo\Bar; use SomeClass; use Symfony\Annotation\Template, Symfony\Doctrine\Entities\Entity; class AnnotatedClass { /** * @Template(foobar=21) * @param Entity $foo */ public function doSomething($foo) { $bar = $foo->toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } } EOF; $this->makeTest($expected, $input); } public function testFixWithComment() { $expected = <<<'EOF' The normal use of this fixer should not change this sentence nor those statements below use Zoo\Bar; use Foo\Bar; use Foo\Zar\Baz; toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } EOF; $input = <<<'EOF' The normal use of this fixer should not change this sentence nor those statements below use Zoo\Bar; use Foo\Bar; use Foo\Zar\Baz; toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } EOF; $this->makeTest($expected, $input); } /** * @requires PHP 5.4 */ public function test54() { $expected = <<<'EOF' toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } EOF; $input = <<<'EOF' toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $foo) {}; } } EOF; $this->makeTest($expected, $input); } /** * @requires PHP 5.4 */ public function testFixWithTraitImports() { $expected = <<<'EOF' The normal use of this fixer should not change this sentence nor those statements below use Zoo\Bar; use Foo\Bar; use Foo\Zar\Baz; toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $baz) {}; } } EOF; $input = <<<'EOF' The normal use of this fixer should not change this sentence nor those statements below use Zoo\Bar; use Foo\Bar; use Foo\Zar\Baz; toArray(); /** @var ArrayInterface $bar */ return function () use ($bar, $baz) {}; } } EOF; $this->makeTest($expected, $input); } public function testFixWithDifferentCases() { $expected = <<<'EOF' The normal use of this fixer should not change this sentence nor those statements below use Zoo\Bar; use abc\Bar; makeTest($expected, $input); } public function testWithoutUses() { $expected = <<<'EOF' makeTest($expected); } public function testOrderWithTrailingDigit() { $expected = <<<'EOF' makeTest($expected, $input); } public function testCodeWithImportsOnly() { $expected = <<<'EOF' makeTest($expected, $input); } }