* Dariusz RumiƄski * * 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; /** * @author John Paul E. Balandan, CPA * * @internal * * @covers \PhpCsFixer\Fixer\ClassNotation\OrderedTypesFixer * * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ClassNotation\OrderedTypesFixer> * * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\ClassNotation\OrderedTypesFixer */ final class OrderedTypesFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases * * @param _AutogeneratedInputConfiguration $config */ public function testFix(string $expected, ?string $input = null, ?array $config = null): void { if (null !== $config) { $this->fixer->configure($config); } $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFixCases(): iterable { yield 'catch with default, no spaces, with both leading slash' => [ 'foo(); } catch (\LogicException|\RuntimeException $e) { // $e } ', 'foo(); } catch (\RuntimeException|\LogicException $e) { // $e } ', ]; yield 'catch with default, with spaces, with both leading slash' => [ 'foo(); } catch (\LogicException|\RuntimeException $e) { // $e } ', 'foo(); } catch (\RuntimeException | \LogicException $e) { // $e } ', ]; yield 'catch with default, no spaces, with no leading slash' => [ 'save(); } catch (CacheException|SimpleCacheException $e) { // $e } ', 'save(); } catch (SimpleCacheException|CacheException $e) { // $e } ', ]; yield 'catch with default, with spaces, with one leading slash' => [ 'save(); } catch (CacheException|\RuntimeException $e) { // $e } ', 'save(); } catch (\RuntimeException | CacheException $e) { // $e } ', ]; yield 'catch with no sorting' => [ 'foo(); } catch (\RuntimeException|\LogicException $e) { // $e } ', null, ['sort_algorithm' => 'none'], ]; yield 'nothing to fix' => [ 'foo(); } catch (\LogicException $e) { // $e } ', ]; yield 'already fixed' => [ 'foo(); } catch (LogicException|RuntimeException $e) { // $e } ', ]; } /** * @dataProvider provideFix80Cases * * @param _AutogeneratedInputConfiguration $config * * @requires PHP 8.0 */ public function testFix80(string $expected, ?string $input = null, ?array $config = null): void { if (null !== $config) { $this->fixer->configure($config); } $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFix80Cases(): iterable { yield 'sort alpha, null none' => [ " 'alpha', 'null_adjustment' => 'none'], ]; yield 'sort alpha, null first' => [ " 'alpha', 'null_adjustment' => 'always_first'], ]; yield 'sort alpha, null last' => [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield 'sort none, null first' => [ " 'none', 'null_adjustment' => 'always_first'], ]; yield 'sort none, null last' => [ " 'none', 'null_adjustment' => 'always_last'], ]; yield 'sort none, null none' => [ " 'none', 'null_adjustment' => 'none'], ]; yield [ " $number;', ' $number;', ]; yield [ "baz(); } catch (Exception $e) { return $e; } ', ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ ' 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ ' $number;', ' $number;', ['sort_algorithm' => 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ 'baz(); } catch (Exception $e) { return $e; } ', null, ['sort_algorithm' => 'alpha', 'null_adjustment' => 'always_last'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ ' 'alpha', 'null_adjustment' => 'none'], ]; yield [ ' $number;', ' $number;', ['sort_algorithm' => 'alpha', 'null_adjustment' => 'none'], ]; yield [ " 'alpha', 'null_adjustment' => 'none'], ]; yield [ 'baz(); } catch (Exception $e) { return $e; } ', null, ['sort_algorithm' => 'alpha', 'null_adjustment' => 'none'], ]; yield [ " [ " true], ]; } /** * @dataProvider provideFix81Cases * * @param _AutogeneratedInputConfiguration $config * * @requires PHP 8.1 */ public function testFix81(string $expected, ?string $input = null, ?array $config = null): void { if (null !== $config) { $this->fixer->configure($config); } $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFix81Cases(): iterable { yield [ " 'always_last'], ]; yield [ " 'none'], ]; yield [ " 'none'], ]; } /** * Provisional support for PHP 8.2's Disjunctive Normal Form (DNF) Types. * * @dataProvider provideFix82Cases * * @param _AutogeneratedInputConfiguration $config * * @requires PHP 8.2 */ public function testFix82(string $expected, ?string $input = null, ?array $config = null): void { if (null !== $config) { $this->fixer->configure($config); } $this->doTest($expected, $input); } /** * @return iterable}> */ public static function provideFix82Cases(): iterable { yield [ " 'always_last'], ]; yield [ " 'none'], ]; yield [ " 'alpha'], ]; yield [ " 'alpha'], ]; yield [ " 'alpha'], ]; yield [ " 'alpha'], ]; } }