123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- <?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\ClassNotation;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\ClassNotation\SingleTraitInsertPerStatementFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ClassNotation\SingleTraitInsertPerStatementFixer>
- */
- final class SingleTraitInsertPerStatementFixerTest extends AbstractFixerTestCase
- {
- /**
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null): void
- {
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<string, array{0: string, 1?: string}>
- */
- public static function provideFixCases(): iterable
- {
- yield 'simple' => [
- '<?php
- final class Example
- {
- use Foo;use Bar;
- }
- ',
- '<?php
- final class Example
- {
- use Foo, Bar;
- }
- ',
- ];
- yield 'simple I' => [
- '<?php
- final class Example
- {
- use Foo;use Bar;
- }
- ',
- '<?php
- final class Example
- {
- use Foo,Bar;
- }
- ',
- ];
- yield 'simple II' => [
- '<?php
- use Foo\Bar, Foo\Bar2; // do not touch
- final class Example
- {
- use Foo;use Bar ;
- }
- ',
- '<?php
- use Foo\Bar, Foo\Bar2; // do not touch
- final class Example
- {
- use Foo, Bar ;
- }
- ',
- ];
- yield 'simple III' => [
- '<?php
- class Example
- {
- use Foo;use Bar;
- public function baz() {}
- }
- ',
- '<?php
- class Example
- {
- use Foo, Bar;
- public function baz() {}
- }
- ',
- ];
- yield 'multiple' => [
- '<?php
- final class Example
- {
- use Foo;
- use Foo00;use Bar01;
- use Foo10;use Bar11;use Bar110;
- use Foo20;use Bar20;use Bar200;use Bar201;
- }
- ',
- '<?php
- final class Example
- {
- use Foo;
- use Foo00, Bar01;
- use Foo10, Bar11, Bar110;
- use Foo20, Bar20, Bar200, Bar201;
- }
- ',
- ];
- yield 'multiple_multiline' => [
- '<?php
- final class Example
- {
- use Foo;
- use Bar;
- use Baz;
- }
- ',
- '<?php
- final class Example
- {
- use Foo,
- Bar,
- Baz;
- }
- ',
- ];
- yield 'multiple_multiline_with_comment' => [
- '<?php
- final class Example
- {
- use Foo;
- use Bar;
- // Bazz,
- use Baz;
- }
- ',
- '<?php
- final class Example
- {
- use Foo,
- Bar,
- // Bazz,
- Baz;
- }
- ',
- ];
- yield 'namespaces' => [
- '<?php
- class Z
- {
- use X\Y\Z0;use X\Y\Z0;use M;
- use X\Y\Z1;use X\Y\Z1;
- }
- ',
- '<?php
- class Z
- {
- use X\Y\Z0, X\Y\Z0, M;
- use X\Y\Z1, X\Y\Z1;
- }
- ',
- ];
- yield 'comments' => [
- '<?php
- class ZZ
- {#1
- use#2
- Z/* 2 */ #3
- #4
- ;#5
- #6
- use T#7
- #8
- ;#9
- #10
- }
- ',
- '<?php
- class ZZ
- {#1
- use#2
- Z/* 2 */ #3
- #4
- ,#5
- #6
- T#7
- #8
- ;#9
- #10
- }
- ',
- ];
- yield 'two classes. same file' => [
- '<?php
- namespace Foo;
- class Test1
- {
- use A;use B; /** use A2, B2; */
- }
- ?>
- <?php
- class Test2
- {
- use A1;use B1; # use A2, B2;
- }
- ',
- '<?php
- namespace Foo;
- class Test1
- {
- use A, B; /** use A2, B2; */
- }
- ?>
- <?php
- class Test2
- {
- use A1, B1; # use A2, B2;
- }
- ',
- ];
- yield 'do not fix group' => [
- '<?php
- class Talker {
- use A, B {
- B::smallTalk insteadof A;
- A::bigTalk insteadof B;
- }
- }',
- ];
- yield 'anonymous class' => [
- '<?php new class { use A;use B;}?>',
- '<?php new class { use A, B;}?>',
- ];
- }
- }
|