repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit3x2MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit3x2MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit3x2MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit3x2MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP8x0MigrationRiskySetTest.php
tests/RuleSet/Sets/PHP8x0MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP8x0MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP8x0MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PhpCsFixerSetTest.php
tests/RuleSet/Sets/PhpCsFixerSetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PhpCsFixerSet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PhpCsFixerSetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP8x2MigrationSetTest.php
tests/RuleSet/Sets/PHP8x2MigrationSetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP8x2MigrationSet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP8x2MigrationSetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit3x5MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit3x5MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit3x5MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit3x5MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit5x5MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit5x5MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit5x5MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit5x5MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit9x1MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit9x1MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit9x1MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit9x1MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/AutoRiskySetTest.php
tests/RuleSet/Sets/AutoRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\AutoRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class AutoRiskySetTest extends AbstractSetTestCase { public function testCorrectResolutionTowardsOurOwnRepoConfig(): void { $set = self::getSet(); $rules = $set->getRules(); self::assertSame( [ '@PER-CS:risky' => true, '@autoPHPMigration:risky' => true, '@autoPHPUnitMigration:risky' => true, ], $rules, ); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PERCS2x0SetTest.php
tests/RuleSet/Sets/PERCS2x0SetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PERCS2x0Set * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PERCS2x0SetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit5x7MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit5x7MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit5x7MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit5x7MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP7x0MigrationRiskySetTest.php
tests/RuleSet/Sets/PHP7x0MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP7x0MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP7x0MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP7x3MigrationSetTest.php
tests/RuleSet/Sets/PHP7x3MigrationSetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP7x3MigrationSet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP7x3MigrationSetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/DoctrineAnnotationSetTest.php
tests/RuleSet/Sets/DoctrineAnnotationSetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\DoctrineAnnotationSet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class DoctrineAnnotationSetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP8x3MigrationSetTest.php
tests/RuleSet/Sets/PHP8x3MigrationSetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP8x3MigrationSet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP8x3MigrationSetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PERCS1x0RiskySetTest.php
tests/RuleSet/Sets/PERCS1x0RiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PERCS1x0RiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PERCS1x0RiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP7x4MigrationSetTest.php
tests/RuleSet/Sets/PHP7x4MigrationSetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP7x4MigrationSet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP7x4MigrationSetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit6x0MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit6x0MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit6x0MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit6x0MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit8x4MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit8x4MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit8x4MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit8x4MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/AbstractSetTestCase.php
tests/RuleSet/Sets/AbstractSetTestCase.php
<?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\RuleSet\Sets; use PhpCsFixer\ConfigurationException\InvalidForEnvFixerConfigurationException; use PhpCsFixer\FixerFactory; use PhpCsFixer\Preg; use PhpCsFixer\RuleSet\RuleSet; use PhpCsFixer\RuleSet\RuleSetDefinitionInterface; use PhpCsFixer\RuleSet\RuleSets; use PhpCsFixer\Tests\TestCase; /** * @internal * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ abstract class AbstractSetTestCase extends TestCase { public function testSet(): void { $set = self::getSet(); $setName = $set->getName(); $setDescription = $set->getDescription(); $isRiskySet = $set->isRisky(); $setRules = $set->getRules(); $factory = new FixerFactory(); $factory->registerBuiltInFixers(); self::assertSanityString($setName); self::assertSanityString($setDescription); self::assertStringEndsWith('.', $setDescription, \sprintf('Ruleset description of "%s" must end with ".", got "%s".', $setName, $setDescription)); self::assertStringNotContainsStringIgnoringCase( '`', Preg::replace( '/`[^`]+`_/', '', Preg::replace( '/``[^`]+``/', '', $setDescription, ), ), \sprintf('Ruleset description of "%s" must not contain inline code marked with backticks other than link ("`desc <link>`_") or reference ("vide ``@OtherSet``"). Got:%s> %s', $setName, "\n", $setDescription), ); if (Preg::match('/(\d+)(\d)Migration/', \get_class($set), $matches)) { self::assertStringEndsWith( \sprintf(' %d.%d compatibility.', $matches[1], $matches[2]), $setDescription, \sprintf('Set %s has incorrect description: "%s".', $setName, $setDescription), ); } self::assertRules($setRules, $factory, $setName); try { $factory->useRuleSet(new RuleSet($set->getRules())); } catch (InvalidForEnvFixerConfigurationException $e) { self::markTestSkipped(\sprintf('Cannot test set "%s" on this environment. %s', $setName, $e->getMessage())); } foreach ($factory->getFixers() as $fixer) { $fixerName = $fixer->getName(); self::assertSame($isRiskySet, $fixer->isRisky(), \sprintf('Is risky mismatch between set "%s" and rule "%s".', $setName, $fixerName)); if (isset($setRules[$fixerName])) { self::assertTrue(\is_bool($setRules[$fixerName]) || \is_array($setRules[$fixerName])); } } } protected static function assertSanityString(string $string): void { self::assertSame(trim($string), $string); self::assertNotSame('', $string); } protected static function getSet(): RuleSetDefinitionInterface { $setClassName = Preg::replace('/^(PhpCsFixer)\\\Tests(\\\.+)Test$/', '$1$2', static::class); \assert(is_a($setClassName, RuleSetDefinitionInterface::class, true)); return new $setClassName(); } /** * @param array<string, array<string, mixed>|bool> $setRules */ protected static function assertRules(array $setRules, FixerFactory $factory, string $setName): void { $sawRule = false; foreach ($setRules as $rule => $config) { self::assertIsString($rule, $setName); if (str_starts_with($rule, '@')) { self::assertFalse($sawRule, \sprintf('Ruleset "%s" should define all sets it extends first and than list by rule configuration overrides.', $setName)); RuleSets::getSetDefinition($setName); } else { $sawRule = true; self::assertTrue($factory->hasRule($rule), $rule); } } $setRulesSorted = $setRules; ksort($setRulesSorted); self::assertSame($setRulesSorted, $setRules); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PERCS2x0RiskySetTest.php
tests/RuleSet/Sets/PERCS2x0RiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PERCS2x0RiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PERCS2x0RiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PERCS1x0SetTest.php
tests/RuleSet/Sets/PERCS1x0SetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PERCS1x0Set * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PERCS1x0SetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP8x0MigrationSetTest.php
tests/RuleSet/Sets/PHP8x0MigrationSetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP8x0MigrationSet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP8x0MigrationSetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit11x0MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit11x0MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit11x0MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit11x0MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PERCS3x0RiskySetTest.php
tests/RuleSet/Sets/PERCS3x0RiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PERCS3x0RiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PERCS3x0RiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP7x4MigrationRiskySetTest.php
tests/RuleSet/Sets/PHP7x4MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP7x4MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP7x4MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit4x3MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit4x3MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit4x3MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit4x3MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit7x5MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit7x5MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit7x5MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit7x5MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP7x1MigrationSetTest.php
tests/RuleSet/Sets/PHP7x1MigrationSetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP7x1MigrationSet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP7x1MigrationSetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/SymfonyRiskySetTest.php
tests/RuleSet/Sets/SymfonyRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\SymfonyRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class SymfonyRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit5x6MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit5x6MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit5x6MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit5x6MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP8x5MigrationSetTest.php
tests/RuleSet/Sets/PHP8x5MigrationSetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP8x5MigrationSet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP8x5MigrationSetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PhpCsFixerRiskySetTest.php
tests/RuleSet/Sets/PhpCsFixerRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PhpCsFixerRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PhpCsFixerRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/AutoPHPUnitMigrationRiskySetTest.php
tests/RuleSet/Sets/AutoPHPUnitMigrationRiskySetTest.php
<?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\RuleSet\Sets; use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; use PhpCsFixer\Preg; use PhpCsFixer\RuleSet\AutomaticRuleSetDefinitionInterface; use PhpCsFixer\RuleSet\RuleSet; use PhpCsFixer\RuleSet\RuleSetDefinitionInterface; use PhpCsFixer\Tests\Test\TestCaseUtils; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\AutoPHPUnitMigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class AutoPHPUnitMigrationRiskySetTest extends AbstractSetTestCase { /** * @covers \PhpCsFixer\RuleSet\AutomaticMigrationSetTrait */ public function testCorrectResolutionTowardsOurOwnRepoConfig(): void { $set = self::getSet(); $rules = $set->getRules(); self::assertSame( ['@PHPUnit9x1Migration:risky' => true], // bump me when updating minimum supported version in composer.json $rules, ); } /** * @dataProvider provideThatSetDoNotUseNewestTargetCases */ public function testThatSetDoNotUseNewestTarget(string $setName): void { $versionInRuleName = Preg::replace('/^@PHPUnit(\d+)x(\d+)Migration:risky$/', '$1.$2', $setName); $setClassName = 'PhpCsFixer\RuleSet\Sets\\'.str_replace(['@', ':risky'], ['', 'Risky'], $setName).'Set'; $set = new $setClassName(); \assert($set instanceof RuleSetDefinitionInterface); $rulesWithTarget = array_filter( $set->getRules(), static fn ($configuration) => \is_array($configuration) && isset($configuration['target']), ); if ([] === $rulesWithTarget) { $this->addToAssertionCount(1); // no rule that is configured with 'target' return; } foreach ($rulesWithTarget as $rule => $configuration) { if (!\is_array($configuration) || !isset($configuration['target'])) { continue; } self::assertNotSame(PhpUnitTargetVersion::VERSION_NEWEST, $configuration['target']); self::assertSame($versionInRuleName, $configuration['target']); } } /** * @return iterable<string, array{0: string}> */ public static function provideThatSetDoNotUseNewestTargetCases(): iterable { $setDefinition = self::getSet(); \assert($setDefinition instanceof AutomaticRuleSetDefinitionInterface); $sets = array_keys($setDefinition->getRulesCandidates()); foreach ($sets as $set) { yield $set => [$set]; } } public function testThatHighestSetUsesHighestTargets(): void { $setDefinition = self::getSet(); \assert($setDefinition instanceof AutomaticRuleSetDefinitionInterface); $highestSet = array_key_last($setDefinition->getRulesCandidates()); $ruleSet = new RuleSet([$highestSet => true]); foreach ($ruleSet->getRules() as $rule => $configuration) { self::assertNotFalse($configuration); self::assertSame( self::getHighestConfigurationForPHPUnitFixer($rule), $configuration['target'] ?? null, \sprintf( 'Rule "%s" configuration is not the highest one.', $rule, ), ); } } private static function getHighestConfigurationForPHPUnitFixer(string $rule): ?string { $fixer = TestCaseUtils::getFixerByName($rule); if (!$fixer instanceof ConfigurableFixerInterface) { return null; } $options = $fixer->getConfigurationDefinition()->getOptions(); $targetOption = array_find( $options, static fn ($option) => 'target' === $option->getName(), ); if (null === $targetOption) { return null; } $allowedVersionValues = array_filter( $targetOption->getAllowedValues(), static fn ($value) => PhpUnitTargetVersion::VERSION_NEWEST !== $value, ); natsort($allowedVersionValues); return array_last($allowedVersionValues); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP7x1MigrationRiskySetTest.php
tests/RuleSet/Sets/PHP7x1MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP7x1MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP7x1MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit5x0MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit5x0MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit5x0MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit5x0MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PSR2SetTest.php
tests/RuleSet/Sets/PSR2SetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PSR2Set * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PSR2SetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP8x3MigrationRiskySetTest.php
tests/RuleSet/Sets/PHP8x3MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP8x3MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP8x3MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP5x6MigrationRiskySetTest.php
tests/RuleSet/Sets/PHP5x6MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP5x6MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP5x6MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHPUnit5x4MigrationRiskySetTest.php
tests/RuleSet/Sets/PHPUnit5x4MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHPUnit5x4MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHPUnit5x4MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PSR12SetTest.php
tests/RuleSet/Sets/PSR12SetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PSR12Set * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PSR12SetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PHP8x5MigrationRiskySetTest.php
tests/RuleSet/Sets/PHP8x5MigrationRiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PHP8x5MigrationRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PHP8x5MigrationRiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/PSR12RiskySetTest.php
tests/RuleSet/Sets/PSR12RiskySetTest.php
<?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\RuleSet\Sets; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\PSR12RiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class PSR12RiskySetTest extends AbstractSetTestCase {}
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/RuleSet/Sets/Internal/InternalRiskySetTest.php
tests/RuleSet/Sets/Internal/InternalRiskySetTest.php
<?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\RuleSet\Sets\Internal; use PhpCsFixer\Tests\RuleSet\Sets\AbstractSetTestCase; /** * @internal * * @covers \PhpCsFixer\RuleSet\Sets\Internal\InternalRiskySet * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class InternalRiskySetTest extends AbstractSetTestCase { public function testSet(): void { self::markTestSkipped('Skipped as contains internal rules'); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/DocBlock/TagTest.php
tests/DocBlock/TagTest.php
<?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\DocBlock; use PhpCsFixer\DocBlock\Line; use PhpCsFixer\DocBlock\Tag; use PhpCsFixer\Tests\TestCase; /** * @author Graham Campbell <hello@gjcampbell.co.uk> * * @internal * * @covers \PhpCsFixer\DocBlock\Tag * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class TagTest extends TestCase { /** * @dataProvider provideNameCases */ public function testName(string $expected, string $new, string $input): void { $tag = new Tag(new Line($input)); self::assertSame($expected, $tag->getName()); if ('other' === $expected) { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Cannot set name on unknown tag'); } $tag->setName($new); self::assertSame($new, $tag->getName()); } /** * @return iterable<int, array{string, string, string}> */ public static function provideNameCases(): iterable { yield ['param', 'var', ' * @param Foo $foo']; yield ['return', 'type', '* @return false']; yield ['thRoWs', 'throws', '*@thRoWs \Exception']; yield ['THROWSSS', 'throws', "\t@THROWSSS\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n"]; yield ['other', 'foobar', ' * @\Foo\Bar(baz = 123)']; yield ['expectedException', 'baz', ' * @expectedException Exception']; yield ['property-read', 'property-write', ' * @property-read integer $daysInMonth number of days in the given month']; yield ['method', 'foo', ' * @method']; yield ['method', 'hi', ' * @method string getString()']; yield ['other', 'hello', ' * @method("GET")']; } /** * @dataProvider provideValidCases */ public function testValid(bool $expected, string $input): void { $tag = new Tag(new Line($input)); self::assertSame($expected, $tag->valid()); } /** * @return iterable<int, array{bool, string}> */ public static function provideValidCases(): iterable { yield [true, ' * @param Foo $foo']; yield [true, '* @return false']; yield [true, '*@throws \Exception']; yield [true, ' * @method']; yield [true, ' * @method string getString()']; yield [true, ' * @property-read integer $daysInMonth number of days in the given month']; yield [false, ' * @method("GET")']; yield [false, '*@thRoWs \InvalidArgumentException']; yield [false, "\t@THROWSSS\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n"]; yield [false, ' * @\Foo\Bar(baz = 123)']; yield [false, ' * @expectedException Exception']; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/DocBlock/TagComparatorTest.php
tests/DocBlock/TagComparatorTest.php
<?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\DocBlock; use PhpCsFixer\DocBlock\Line; use PhpCsFixer\DocBlock\Tag; use PhpCsFixer\DocBlock\TagComparator; use PhpCsFixer\Tests\TestCase; /** * @author Graham Campbell <hello@gjcampbell.co.uk> * @author Jakub Kwaśniewski <jakub@zero-85.pl> * * @internal * * @covers \PhpCsFixer\DocBlock\TagComparator * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class TagComparatorTest extends TestCase { /** * @dataProvider provideComparatorTogetherCases * * @group legacy */ public function testComparatorTogether(string $first, string $second, bool $expected): void { $tag1 = new Tag(new Line('* @'.$first)); $tag2 = new Tag(new Line('* @'.$second)); $this->expectDeprecation('Method PhpCsFixer\DocBlock\TagComparator::shouldBeTogether is deprecated and will be removed in version 4.0.'); self::assertSame($expected, TagComparator::shouldBeTogether($tag1, $tag2)); } /** * @return iterable<int, array{string, string, bool}> */ public static function provideComparatorTogetherCases(): iterable { yield ['return', 'return', true]; yield ['param', 'param', true]; yield ['return', 'param', false]; yield ['var', 'foo', false]; yield ['api', 'deprecated', false]; yield ['author', 'copyright', true]; yield ['author', 'since', false]; yield ['link', 'see', true]; yield ['category', 'package', true]; } /** * @dataProvider provideComparatorTogetherWithDefinedGroupsCases * * @param list<list<string>> $groups * * @group legacy */ public function testComparatorTogetherWithDefinedGroups(array $groups, string $first, string $second, bool $expected): void { $tag1 = new Tag(new Line('* @'.$first)); $tag2 = new Tag(new Line('* @'.$second)); $this->expectDeprecation('Method PhpCsFixer\DocBlock\TagComparator::shouldBeTogether is deprecated and will be removed in version 4.0.'); self::assertSame( $expected, TagComparator::shouldBeTogether($tag1, $tag2, $groups), ); } /** * @return iterable<int, array{list<list<string>>, string, string, bool}> */ public static function provideComparatorTogetherWithDefinedGroupsCases(): iterable { yield [[['param', 'return']], 'return', 'return', true]; yield [[], 'param', 'return', false]; yield [[['param', 'return']], 'return', 'param', true]; yield [[['param', 'return']], 'var', 'foo', false]; yield [[['param', 'return']], 'api', 'deprecated', false]; yield [[['param', 'return']], 'author', 'copyright', false]; yield [[['param', 'return'], ['author', 'since']], 'author', 'since', true]; yield [[...TagComparator::DEFAULT_GROUPS, ['param', 'return']], 'link', 'see', true]; yield [[['param', 'return']], 'category', 'package', false]; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/DocBlock/ShortDescriptionTest.php
tests/DocBlock/ShortDescriptionTest.php
<?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\DocBlock; use PhpCsFixer\DocBlock\DocBlock; use PhpCsFixer\DocBlock\ShortDescription; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\DocBlock\ShortDescription * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ShortDescriptionTest extends TestCase { /** * @dataProvider provideGetEndCases */ public function testGetEnd(?int $expected, string $input): void { $doc = new DocBlock($input); $shortDescription = new ShortDescription($doc); self::assertSame($expected, $shortDescription->getEnd()); } /** * @return iterable<int, array{null|int, string}> */ public static function provideGetEndCases(): iterable { yield [1, '/** * Test docblock. * * @param string $hello * @param bool $test Description * extends over many lines * * @param adkjbadjasbdand $asdnjkasd * * @throws \Exception asdnjkasd * asdasdasdasdasdasdasdasd * kasdkasdkbasdasdasdjhbasdhbasjdbjasbdjhb * * @return void */']; yield [2, '/** * This is a multi-line * short description. */']; yield [3, '/** * * * There might be extra blank lines. * * * And here is description... */']; yield [null, '/** */']; yield [null, "/**\n * @test\n*/"]; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/DocBlock/TypeExpressionTest.php
tests/DocBlock/TypeExpressionTest.php
<?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\DocBlock; use PhpCsFixer\DocBlock\TypeExpression; use PhpCsFixer\Preg; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceAnalysis; use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceUseAnalysis; /** * @covers \PhpCsFixer\DocBlock\TypeExpression * * @internal * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class TypeExpressionTest extends TestCase { /** * @param null|list<string> $expectedTypes * * @dataProvider provideGetConstTypesCases * @dataProvider provideGetTypesCases */ public function testGetTypes(string $typesExpression, ?array $expectedTypes = null): void { if (null === $expectedTypes) { $expectedTypes = [$typesExpression]; } $expression = $this->parseTypeExpression($typesExpression, null, []); self::assertSame($expectedTypes, $expression->getTypes()); $unionTestNs = '__UnionTest__'; $unionExpression = $this->parseTypeExpression( $unionTestNs.'\A|'.$typesExpression.'|'.$unionTestNs.'\Z', null, [], ); if (!$expression->isCompositeType() || $expression->isUnionType()) { self::assertSame( [$unionTestNs.'\A', ...$expectedTypes, $unionTestNs.'\Z'], [...$unionExpression->getTypes()], ); } } /** * @return iterable<int, array{string}> */ public static function provideGetConstTypesCases(): iterable { foreach ([ 'null', 'true', 'FALSE', '123', '+123', '-123', '0b0110101', '0o777', '0x7Fb4', '-0O777', '-0X7Fb4', '123_456', '0b01_01_01', '-0X7_Fb_4', '18_446_744_073_709_551_616', // 64-bit unsigned long + 1, larger than PHP_INT_MAX '123.4', '.123', '123.', '123e4', '123E4', '12.3e4', '+123.5', '-123.', '-123.4', '-.123', '-123e-4', '-12.3e-4', '-1_2.3_4e5_6', '123E+80', '8.2023437675747321', // greater precision than 64-bit double '-0.0', '\'\'', '\'foo\'', '\'\\\\\'', '\'\\\'\'', ] as $type) { yield [$type]; } } /** * @return iterable<int, array{0: string, 1?: null|list<string>}> */ public static function provideGetTypesCases(): iterable { yield ['int']; yield ['Foo5']; yield ['🚀_kůň']; yield ['positive-int']; yield ['?int']; yield ['? int']; yield ['int[]']; yield ['Foo[][]']; yield ['Foo [ ] []']; yield ['int[]|null', ['int[]', 'null']]; yield ['int[]|null|?int|array', ['int[]', 'null', '?int', 'array']]; yield ['null|Foo\Bar|\Baz\Bax|int[]', ['null', 'Foo\Bar', '\Baz\Bax', 'int[]']]; yield ['gen<int>']; yield ['int|gen<int>', ['int', 'gen<int>']]; yield ['\int|\gen<\int, \bool>', ['\int', '\gen<\int, \bool>']]; yield ['gen<int, int>']; yield ['gen<int, bool|string>']; yield ['gen<int, string[]>']; yield ['gen<int, gener<string, bool>>']; yield ['gen<int, gener<string, null|bool>>']; yield ['gen<int>[][]']; yield ['non-empty-array<int>']; yield ['null|gen<int, gener<string, bool>>|int|string[]', ['null', 'gen<int, gener<string, bool>>', 'int', 'string[]']]; yield ['null|gen<int, gener<string, bool>>|int|array<int, string>|string[]', ['null', 'gen<int, gener<string, bool>>', 'int', 'array<int, string>', 'string[]']]; yield ['this']; yield ['@this']; yield ['$SELF|int', ['$SELF', 'int']]; yield ['array<string|int, string>']; yield ['Collection<Foo<Bar>, Foo<Baz>>']; yield ['int | string', ['int', 'string']]; yield ['Foo::*']; yield ['Foo::A']; yield ['Foo::A|Foo::B', ['Foo::A', 'Foo::B']]; yield ['Foo::A*']; yield ['Foo::*0*_Bar']; yield ['?Foo::*[]']; yield ['array<Foo::A*>|null', ['array<Foo::A*>', 'null']]; yield ['null|true|false|1|-1|1.5|-1.5|.5|1.|\'a\'|"b"', ['null', 'true', 'false', '1', '-1', '1.5', '-1.5', '.5', '1.', "'a'", '"b"']]; yield ['int | "a" | A<B<C, D>, E<F::*|G[]>>', ['int', '"a"', 'A<B<C, D>, E<F::*|G[]>>']]; yield ['class-string<Foo>']; yield ['A&B', ['A', 'B']]; yield ['A & B', ['A', 'B']]; yield ['array{}']; yield ['object{ }']; yield ['array{1: bool, 2: bool}']; yield ['array{a: int|string, b?: bool}']; yield ['array{\'a\': "a", "b"?: \'b\'}']; yield ['array { a : int | string , b ? : A<B, C> }']; yield ['array{bool, int}']; yield ['array{bool,}']; yield ['list{int, bool}']; yield ['object{ bool, foo2: int }']; yield ['ArRAY{ 1 }']; yield ['lIst{ 1 }']; yield ['OBJECT { x: 1 }']; yield ['array{a: int, b: int, with-dash: int}']; yield ['array{...}']; yield ['array{...<string>}']; yield ['array{bool, ...<int, string>}']; yield ['array{bool, ...}']; yield ['array{bool, ...<string>}']; yield ['array{a: bool,... }']; yield ['array{a: bool,...<string> }']; yield ["array{\n a: Foo,\n b: Bar\n}"]; yield ["array{\n Foo,\n Bar,\n}"]; yield ['list{int, ...<string>}']; yield ['callable']; yield ['callable(string)']; yield ['? callable(string): bool']; yield ['CAllable(string): bool']; yield ['callable(string,): bool']; yield ['callable(array<int, string>, array<int, Foo>): bool']; yield ['array<int, callable(string): bool>']; yield ['callable(string): callable(int)']; yield ['callable(string) : callable(int) : bool']; yield ['TheCollection<callable(Foo, Bar,Baz): Foo[]>|string[]|null', ['TheCollection<callable(Foo, Bar,Baz): Foo[]>', 'string[]', 'null']]; yield ['Closure()']; yield ['Closure(string)']; yield ['\closure(string): void']; yield [\Closure::class]; yield ['\Closure()']; yield ['\Closure(string)']; yield ['\Closure(string, bool)']; yield ['\Closure(string|int, bool)']; yield ['\Closure(string):bool']; yield ['\Closure(string): bool']; yield ['\Closure(string|int, bool): bool']; yield ['\Closure(float|int): (bool|int)']; yield ['Closure<T>(): T']; yield ['Closure<Tx, Ty>(): array{x: Tx, y: Ty}']; yield ['Closure<Tx, Ty>(): array{x: Tx, y: Ty, ...<Closure(): void>}']; yield ['array < int , callable ( string ) : bool >']; yield ['Closure<T of Foo>(T): T']; yield ['Closure< T1 of Foo, T2 AS Foo >(T1): T2']; yield ['Closure<T = Foo>(T): T']; yield ['Closure<T1=int, T2 of Foo = Foo2>(T1): T2']; yield ['Closure<T of string = \'\'>(T): T']; yield ['Closure<Closure_can_be_regular_class>']; yield ['Closure(int $a)']; yield ['Closure(int $a): bool']; yield ['Closure(int $a, array<Closure(int ...$args): Item<X>>): bool']; yield ['Closure_can_be_aliased()']; yield ['Closure_can_be_aliased(): (u|v)']; yield ['(int)']; yield ['(int|\Exception)']; yield ['($foo is int ? false : true)']; yield ['($foo🚀3 is int ? false : true)']; yield ['\'a\\\'s"\\\\\n\r\t\'|"b\"s\'\\\\\n\r\t"', ['\'a\\\'s"\\\\\n\r\t\'', '"b\"s\'\\\\\n\r\t"']]; yield ['string'.str_repeat('[]', 128)]; yield [str_repeat('array<', 32).'string'.str_repeat('>', 32)]; yield [self::makeLongArrayShapeType()]; yield ['Foo<int, covariant Bar>']; yield ['Foo<contravariant int, Bar>']; yield ['Foo<Bar<contravariant Baz>>']; yield ['Foo<int>|covariant Bar', ['Foo<int>', 'covariant Bar']]; } /** * @dataProvider provideParseInvalidExceptionCases */ public function testParseInvalidException(string $value): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('Unable to parse phpdoc type'); new TypeExpression($value, null, []); } /** * @return iterable<array{string}> */ public static function provideParseInvalidExceptionCases(): iterable { yield ['']; yield ['0_class_cannot_start_with_number']; yield ['$0_variable_cannot_start_with_number']; yield ['class cannot contain space']; yield ['\\\class_with_double_backslash']; yield ['class\\\with_double_backslash']; yield ['class_with_end_backslash\\']; yield ['class/with_slash']; yield ['class--with_double_dash']; yield ['class.with_dot']; yield ['class,with_comma']; yield ['class@with_at_sign']; yield ['class:with_colon']; yield ['class#with_hash']; yield ['class//with_double_slash']; yield ['class$with_dollar']; yield ['class;with_semicolon']; yield ['class=with_equal_sign']; yield ['class+with_plus']; yield ['class?with_question_mark']; yield ['class*with_star']; yield ['class%with_percent']; yield ['(unclosed_parenthesis']; yield [')unclosed_parenthesis']; yield ['unclosed_parenthesis(']; yield ['((unclosed_parenthesis)']; yield ['|vertical_bar_start']; yield ['&ampersand_start']; yield ['~tilde_start']; yield ['vertical_bar_end|']; yield ['ampersand_end&']; yield ['tilde_end~']; yield ['class||double_vertical_bar']; yield ['class&&double_ampersand']; yield ['class~~double_tilde']; yield ['array<>']; yield ['array<']; yield ['array<<']; yield ['array>']; yield ['array<<>']; yield ['array<>>']; yield ['array{']; yield ['array{ $this: 5 }']; yield ['array{...<>}']; yield ['array{bool, ...<>}']; yield ['array{bool, ...<int,>}']; yield ['array{bool, ...<,int>}']; yield ['array{bool, ...<int, int, int>}']; yield ['array{bool...<int>}']; yield ['array{,...<int>}']; yield ['array{...<int>,}']; yield ['g<,>']; yield ['g<,no_leading_comma>']; yield ['10__000']; yield ['[ array_syntax_is_invalid ]']; yield ['\' unclosed string']; yield ['\' unclosed string \\\'']; yield 'generic with no arguments' => ['f<>']; yield 'generic Closure with no arguments' => ['Closure<>(): void']; yield 'generic Closure with non-identifier template argument' => ['Closure<A|B>(): void']; yield [substr(self::makeLongArrayShapeType(), 0, -1)]; } public function testHugeType(): void { $nFlat = 2_000; $types = []; for ($i = 0; $i < $nFlat; ++$i) { $types[] = '\X\Foo'.$i; } $str = implode('|', $types); $expression = new TypeExpression($str, null, []); self::assertSame($types, $expression->getTypes()); for ($i = 0; $i < 100; ++$i) { $str = 'array'.(1 === $i % 2 ? '{' : '<').$str.(1 === $i % 2 ? '}' : '>'); } $typeLeft = '\Closure(A|B): void'; $typeRight = '\Closure('.$typeLeft.'): void'; $expression = new TypeExpression($typeLeft.'|('.$str.')|'.$typeRight, null, []); self::assertSame([$typeLeft, '('.$str.')', $typeRight], $expression->getTypes()); } /** * @dataProvider provideGetTypesGlueCases */ public function testGetTypesGlue(?string $expectedTypesGlue, string $typesExpression): void { $expression = new TypeExpression($typesExpression, null, []); self::assertSame($expectedTypesGlue, $expression->getTypesGlue()); } /** * @return iterable<int, array{0: null|'&'|'|', 1: string}> */ public static function provideGetTypesGlueCases(): iterable { yield [null, 'string']; yield ['|', 'bool|string']; yield ['&', 'Foo&Bar']; } /** * @dataProvider provideIsCompositeTypeCases */ public function testIsCompositeType(bool $expectedIsCompositeType, string $typeExpression): void { $expression = new TypeExpression($typeExpression, null, []); self::assertSame($expectedIsCompositeType, $expression->isCompositeType()); } /** * @return iterable<int, array{0: bool, 1: string}> */ public static function provideIsCompositeTypeCases(): iterable { yield [false, 'string']; yield [false, 'iterable<Foo>']; yield [true, 'iterable&stringable']; yield [true, 'bool|string']; yield [true, 'Foo|(Bar&Baz)']; } /** * @dataProvider provideIsUnionTypeCases */ public function testIsUnionType(bool $expectedIsUnionType, string $typeExpression): void { $expression = new TypeExpression($typeExpression, null, []); self::assertSame($expectedIsUnionType, $expression->isUnionType()); } /** * @return iterable<int, array{0: bool, 1: string}> */ public static function provideIsUnionTypeCases(): iterable { yield [false, 'string']; yield [false, 'iterable&stringable']; yield [true, 'bool|string']; yield [true, 'int|string|null']; yield [true, 'int|?string']; yield [true, 'int|null']; yield [false, '?int']; yield [true, 'Foo|Bar']; } /** * @dataProvider provideIsIntersectionTypeCases */ public function testIsIntersectionType(bool $expectedIsIntersectionType, string $typeExpression): void { $expression = new TypeExpression($typeExpression, null, []); self::assertSame($expectedIsIntersectionType, $expression->isIntersectionType()); } /** * @return iterable<int, array{0: bool, 1: string}> */ public static function provideIsIntersectionTypeCases(): iterable { yield [false, 'string']; yield [false, 'string|int']; yield [true, 'Foo&Bar']; yield [true, 'Foo&Bar&?Baz']; yield [true, '\iterable&\Stringable']; } /** * @param list<NamespaceUseAnalysis> $namespaceUses * * @dataProvider provideGetCommonTypeCases */ public function testGetCommonType(string $typesExpression, ?string $expectedCommonType, ?NamespaceAnalysis $namespace = null, array $namespaceUses = []): void { $expression = new TypeExpression($typesExpression, $namespace, $namespaceUses); self::assertSame($expectedCommonType, $expression->getCommonType()); } /** * @return iterable<int, array{0: string, 1: null|string, 2?: null|NamespaceAnalysis, 3?: list<NamespaceUseAnalysis>}> */ public static function provideGetCommonTypeCases(): iterable { $globalNamespace = new NamespaceAnalysis('', '', 0, 999, 0, 999); $appNamespace = new NamespaceAnalysis('App', 'App', 0, 999, 0, 999); $useTraversable = new NamespaceUseAnalysis(NamespaceUseAnalysis::TYPE_CLASS, \Traversable::class, \Traversable::class, false, false, 0, 0); $useObjectAsTraversable = new NamespaceUseAnalysis(NamespaceUseAnalysis::TYPE_CLASS, 'Foo', \Traversable::class, false, false, 0, 0); yield ['true', 'bool']; yield ['false', 'bool']; yield ['bool', 'bool']; yield ['int', 'int']; yield ['float', 'float']; yield ['string', 'string']; yield ['array', 'array']; yield ['object', 'object']; yield ['self', 'self']; yield ['static', 'static']; yield ['bool[]', 'array']; yield ['int[]', 'array']; yield ['float[]', 'array']; yield ['string[]', 'array']; yield ['array[]', 'array']; yield ['bool[][]', 'array']; yield ['int[][]', 'array']; yield ['float[][]', 'array']; yield ['string[][]', 'array']; yield ['array[][]', 'array']; yield ['bool [ ]', 'array']; yield ['bool [ ][ ]', 'array']; yield ['array|iterable', 'iterable']; yield ['iterable|array', 'iterable']; yield ['array|Traversable', 'iterable']; yield ['array|\Traversable', 'iterable']; yield ['array|Traversable', 'iterable', $globalNamespace]; yield ['iterable|Traversable', 'iterable']; yield ['array<string>', 'array']; yield ['array<int, string>', 'array']; yield ['array < string >', 'array']; yield ['list<int>', 'array']; yield ['iterable<string>', 'iterable']; yield ['iterable<int, string>', 'iterable']; yield ['\Traversable<string>', '\Traversable']; yield ['Traversable<int, string>', 'Traversable']; yield ['Collection<string>', 'Collection']; yield ['Collection<int, string>', 'Collection']; yield ['array{string}', 'array']; yield ['array { 1: string, \Closure(): void }', 'array']; yield ['Closure(): void', \Closure::class]; yield ['array<int, string>|iterable<int, string>', 'iterable']; yield ['int[]|string[]', 'array']; yield ['int|null', 'int']; yield ['null|int', 'int']; yield ['?int', 'int']; yield ['?array<Foo>', 'array']; yield ['?list<Foo>', 'array']; yield ['void', 'void']; yield ['never', 'never']; yield ['array|Traversable', 'iterable', null, [$useTraversable]]; yield ['array|Traversable', 'iterable', $globalNamespace, [$useTraversable]]; yield ['array|Traversable', 'iterable', $appNamespace, [$useTraversable]]; yield ['self|static', 'self']; yield ['array|Traversable', null, null, [$useObjectAsTraversable]]; yield ['array|Traversable', null, $globalNamespace, [$useObjectAsTraversable]]; yield ['array|Traversable', null, $appNamespace, [$useObjectAsTraversable]]; yield ['bool|int', null]; yield ['string|bool', null]; yield ['array<int, string>|Collection<int, string>', null]; } /** * @dataProvider provideAllowsNullCases */ public function testAllowsNull(string $typesExpression, bool $expectNullAllowed): void { $expression = new TypeExpression($typesExpression, null, []); self::assertSame($expectNullAllowed, $expression->allowsNull()); } /** * @return iterable<int, array{string, bool}> */ public static function provideAllowsNullCases(): iterable { yield ['null', true]; yield ['mixed', true]; yield ['null|mixed', true]; yield ['int|bool|null', true]; yield ['int|bool|mixed', true]; yield ['int', false]; yield ['bool', false]; yield ['string', false]; yield ['?int', true]; yield ['?\Closure(): void', true]; } public function testMapTypes(): void { $typeExpression = new TypeExpression('Foo|Bar|($v is \Closure(X, Y): Z ? U : (V&W))', null, []); $addLeadingSlash = static function (TypeExpression $type) { $value = $type->toString(); if (!str_starts_with($value, '\\') && !str_starts_with($value, '(')) { return new TypeExpression('\\'.$value, null, []); } return $type; }; $removeLeadingSlash = static function (TypeExpression $type) { $value = $type->toString(); if (str_starts_with($value, '\\')) { return new TypeExpression(substr($value, 1), null, []); } return $type; }; $callLog = []; $typeExpression->mapTypes(static function (TypeExpression $type) use (&$callLog) { $callLog[] = $type->toString(); if ('Y' === $type->toString()) { return new TypeExpression('_y_', null, []); } return $type; }); self::assertSame([ 'Foo', 'Bar', '\Closure', 'X', 'Y', 'Z', '\Closure(X, _y_): Z', 'U', 'V', 'W', 'V&W', '(V&W)', '($v is \Closure(X, _y_): Z ? U : (V&W))', 'Foo|Bar|($v is \Closure(X, _y_): Z ? U : (V&W))', ], $callLog); $typeExpression = $typeExpression->mapTypes($addLeadingSlash); $this->checkInnerTypeExpressionsStartIndex($typeExpression); self::assertSame('\Foo|\Bar|($v is \Closure(\X, \Y): \Z ? \U : (\V&\W))', $typeExpression->toString()); $typeExpression = $typeExpression->mapTypes($addLeadingSlash); $this->checkInnerTypeExpressionsStartIndex($typeExpression); self::assertSame('\Foo|\Bar|($v is \Closure(\X, \Y): \Z ? \U : (\V&\W))', $typeExpression->toString()); $typeExpression = $typeExpression->mapTypes($removeLeadingSlash); $this->checkInnerTypeExpressionsStartIndex($typeExpression); self::assertSame('Foo|Bar|($v is Closure(X, Y): Z ? U : (V&W))', $typeExpression->toString()); $typeExpression = $typeExpression->mapTypes($removeLeadingSlash); $this->checkInnerTypeExpressionsStartIndex($typeExpression); self::assertSame('Foo|Bar|($v is Closure(X, Y): Z ? U : (V&W))', $typeExpression->toString()); $typeExpression = $typeExpression->mapTypes($addLeadingSlash); $this->checkInnerTypeExpressionsStartIndex($typeExpression); self::assertSame('\Foo|\Bar|($v is \Closure(\X, \Y): \Z ? \U : (\V&\W))', $typeExpression->toString()); } public function testWalkTypes(): void { $typeExpression = new TypeExpression('Foo|Bar|($v is \Closure(X, Y): Z ? U : (V&W))', null, []); $callLog = []; $typeExpression->walkTypes(static function (TypeExpression $type) use (&$callLog): void { $callLog[] = $type->toString(); }); self::assertSame([ 'Foo', 'Bar', '\Closure', 'X', 'Y', 'Z', '\Closure(X, Y): Z', 'U', 'V', 'W', 'V&W', '(V&W)', '($v is \Closure(X, Y): Z ? U : (V&W))', 'Foo|Bar|($v is \Closure(X, Y): Z ? U : (V&W))', ], $callLog); } /** * @dataProvider provideSortTypesCases */ public function testSortTypes(string $typesExpression, string $expectResult): void { $sortCaseFx = static fn (TypeExpression $a, TypeExpression $b): int => strcasecmp($a->toString(), $b->toString()); $sortCrc32Fx = static fn (TypeExpression $a, TypeExpression $b): int => crc32($a->toString()) <=> crc32($b->toString()); $expression = $this->parseTypeExpression($typesExpression, null, []); $expression = $expression->sortTypes($sortCaseFx); $this->checkInnerTypeExpressionsStartIndex($expression); self::assertSame($expectResult, $expression->toString()); $expression = $expression->sortTypes($sortCrc32Fx); $this->checkInnerTypeExpressionsStartIndex($expression); $expression = $expression->sortTypes($sortCaseFx); $this->checkInnerTypeExpressionsStartIndex($expression); self::assertSame($expectResult, $expression->toString()); } /** * @return iterable<string, array{string, string}> */ public static function provideSortTypesCases(): iterable { yield 'not a union type' => [ 'int', 'int', ]; yield 'simple' => [ 'int|bool', 'bool|int', ]; yield 'multiple union' => [ 'C___|D____|B__|A', 'A|B__|C___|D____', ]; yield 'multiple intersect' => [ 'C___&D____&B__&A', 'A&B__&C___&D____', ]; yield 'simple in generic' => [ 'array<int|bool>', 'array<bool|int>', ]; yield 'generic with multiple types' => [ 'array<int|bool, string|float>', 'array<bool|int, float|string>', ]; yield 'generic with trailing comma' => [ 'array<int|bool,>', 'array<bool|int,>', ]; yield 'simple in array shape with int key' => [ 'array{0: int|bool}', 'array{0: bool|int}', ]; yield 'simple in array shape with string key' => [ 'array{"foo": int|bool}', 'array{"foo": bool|int}', ]; yield 'simple in array shape with multiple keys' => [ 'array{0: int|bool, "foo": int|bool}', 'array{0: bool|int, "foo": bool|int}', ]; yield 'simple in array shape with implicit key' => [ 'array{int|bool}', 'array{bool|int}', ]; yield 'simple in array shape with trailing comma' => [ 'array{int|bool,}', 'array{bool|int,}', ]; yield 'simple in array shape with multiple types with trailing comma' => [ 'array{int|bool, Foo|Bar, }', 'array{bool|int, Bar|Foo, }', ]; yield 'simple in array shape' => [ 'list{int, Foo|Bar}', 'list{int, Bar|Foo}', ]; yield 'array shape with multiple colons - array shape' => [ 'array{array{x:int|bool}, a:array{x:int|bool}}', 'array{array{x:bool|int}, a:array{x:bool|int}}', ]; yield 'array shape with multiple colons - callable' => [ 'array{array{x:int|bool}, int|bool, callable(): void}', 'array{array{x:bool|int}, bool|int, callable(): void}', ]; yield 'unsealed array shape' => [ 'array{bool, ...<B|A>}', 'array{bool, ...<A|B>}', ]; yield 'unsealed array shape with key and value type' => [ 'array{bool, ...<B|A, D&C>}', 'array{bool, ...<A|B, C&D>}', ]; yield 'simple in callable argument' => [ 'callable(int|bool)', 'callable(bool|int)', ]; yield 'callable with multiple arguments' => [ 'callable(int|bool, null|array)', 'callable(bool|int, array|null)', ]; yield 'simple in callable return type' => [ 'callable(): (string|float)', 'callable(): (float|string)', ]; yield 'callable with union return type and within union itself' => [ 'callable(): (string|float)|bool', 'bool|callable(): (float|string)', ]; yield 'callable with multiple named arguments' => [ 'callable(int|bool $b, null|array $a)', 'callable(bool|int $b, array|null $a)', ]; yield 'callable with complex arguments' => [ 'callable(B|A&, D|Closure(): void..., array{}$foo=, $this $foo=): array{}', 'callable(A|B&, Closure(): void|D..., array{}$foo=, $this $foo=): array{}', ]; yield 'callable with trailing comma' => [ 'Closure( Y|X , ): B|A', 'A|Closure( X|Y , ): B', ]; yield 'simple in Closure argument' => [ 'Closure(int|bool)', 'Closure(bool|int)', ]; yield 'Closure with multiple arguments' => [ 'Closure(int|bool, null|array)', 'Closure(bool|int, array|null)', ]; yield 'simple in Closure argument with trailing comma' => [ 'Closure(int|bool,)', 'Closure(bool|int,)', ]; yield 'simple in Closure argument multiple arguments with trailing comma' => [ 'Closure(int|bool, null|array,)', 'Closure(bool|int, array|null,)', ]; yield 'simple in Closure return type' => [ 'Closure(): (string|float)', 'Closure(): (float|string)', ]; yield 'Closure with union return type and within union itself' => [ 'Closure(): (string|float)|bool', 'bool|Closure(): (float|string)', ]; yield 'with multiple nesting levels' => [ 'array{0: Foo<int|bool>|Bar<callable(string|float|array<int|bool>): (Foo|Bar)>}', 'array{0: Bar<callable(array<bool|int>|float|string): (Bar|Foo)>|Foo<bool|int>}', ]; yield 'with multiple nesting levels and callable within union' => [ 'array{0: Foo<int|bool>|Bar<callable(string|float|array<int|bool>): (Foo|Bar)|Baz>}', 'array{0: Bar<Baz|callable(array<bool|int>|float|string): (Bar|Foo)>|Foo<bool|int>}', ]; yield 'complex type with Closure with $this' => [ 'array<string, string|array{ string|\Closure(mixed, string, $this): (int|float) }>|false', 'array<string, array{ \Closure(mixed, string, $this): (float|int)|string }|string>|false', ]; yield 'generic Closure' => [ 'Closure<B, A>(y|x, U<p|o>|B|A): (Y|B|X)', 'Closure<B, A>(x|y, A|B|U<o|p>): (B|X|Y)', ]; yield 'generic Closure with bound template' => [ 'Closure<B of J|I, C, A of V|U, D of object>(B|A): array{B, A, B, C, D}', 'Closure<B of I|J, C, A of U|V, D of object>(A|B): array{B, A, B, C, D}', ]; yield 'generic Closure with template with default' => [ 'Closure<T = B&A>(T): void', 'Closure<T = A&B>(T): void', ]; yield 'nullable generic' => [ '?array<Foo|Bar>', '?array<Bar|Foo>', ]; yield 'nullable callable' => [ '?callable(Foo|Bar): (Foo|Bar)', '?callable(Bar|Foo): (Bar|Foo)', ]; // This union type makes no sense in general (it should be `Bar|callable|null`) // but let's ensure nullable types are also sorted. yield 'nullable callable with union return type and within union itself' => [ '?callable(Foo|Bar): (Foo|Bar)|?Bar', '?Bar|?callable(Bar|Foo): (Bar|Foo)', ]; yield 'nullable array shape' => [ '?array{0: Foo|Bar}', '?array{0: Bar|Foo}', ]; yield 'simple types alternation' => [ 'array<Foo&Bar>', 'array<Bar&Foo>', ]; yield 'nesty stuff' => [ 'array<Level11&array<Level2|array<Level31&Level32>>>', 'array<array<array<Level31&Level32>|Level2>&Level11>', ]; yield 'parenthesized' => [ '(Foo|Bar)', '(Bar|Foo)', ]; yield 'parenthesized intersect' => [ '(Foo&Bar)', '(Bar&Foo)', ]; yield 'parenthesized in closure return type' => [ 'Closure(Y|X): (string|float)', 'Closure(X|Y): (float|string)', ]; yield 'conditional with variable' => [ '($x is (CFoo|(CBaz&CBar)) ? (TFoo|(TBaz&TBar)) : (FFoo|(FBaz&FBar)))', '($x is ((CBar&CBaz)|CFoo) ? ((TBar&TBaz)|TFoo) : ((FBar&FBaz)|FFoo))', ]; yield 'conditional with type' => [ '((Foo|Bar) is x ? y : z)', '((Bar|Foo) is x ? y : z)', ]; yield 'conditional in conditional' => [ '((Foo|Bar) is x ? ($x is (CFoo|CBar) ? (TFoo|TBar) : (FFoo|FBar)) : z)', '((Bar|Foo) is x ? ($x is (CBar|CFoo) ? (TBar|TFoo) : (FBar|FFoo)) : z)', ]; yield 'large numbers' => [ '18_446_744_073_709_551_616|-8.2023437675747321e-18_446_744_073_709_551_616', '-8.2023437675747321e-18_446_744_073_709_551_616|18_446_744_073_709_551_616', ]; yield 'mixed 2x | and & glue' => [
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
true
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/DocBlock/DocBlockTest.php
tests/DocBlock/DocBlockTest.php
<?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\DocBlock; use PhpCsFixer\DocBlock\DocBlock; use PhpCsFixer\Tests\TestCase; /** * @author Graham Campbell <hello@gjcampbell.co.uk> * * @internal * * @covers \PhpCsFixer\DocBlock\DocBlock * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class DocBlockTest extends TestCase { /** * This represents the content an entire docblock. */ private static string $sample = '/** * Test docblock. * * @param string $hello * @param bool $test Description * extends over many lines * * @param adkjbadjasbdand $asdnjkasd * * @throws \Exception asdnjkasd * asdasdasdasdasdasdasdasd * kasdkasdkbasdasdasdjhbasdhbasjdbjasbdjhb * * @return void */'; public function testContent(): void { $doc = new DocBlock(self::$sample); self::assertSame(self::$sample, $doc->getContent()); self::assertSame(self::$sample, (string) $doc); } public function testEmptyContent(): void { $doc = new DocBlock(''); self::assertSame('', $doc->getContent()); } public function testGetLines(): void { $doc = new DocBlock(self::$sample); $lines = $doc->getLines(); self::assertCount(15, $lines); foreach ($lines as $index => $line) { self::assertSame($doc->getLine($index), $line); } self::assertEmpty($doc->getLine(15)); } public function testGetAnnotations(): void { $doc = new DocBlock(self::$sample); $annotations = $doc->getAnnotations(); self::assertCount(5, $annotations); foreach ($annotations as $index => $annotation) { self::assertSame($doc->getAnnotation($index), $annotation); } self::assertEmpty($doc->getAnnotation(5)); } public function testGetAnnotationsOfTypeParam(): void { $doc = new DocBlock(self::$sample); $annotations = $doc->getAnnotationsOfType('param'); self::assertCount(3, $annotations); $first = ' * @param string $hello '; $second = ' * @param bool $test Description * extends over many lines '; $third = ' * @param adkjbadjasbdand $asdnjkasd '; self::assertSame($first, $annotations[0]->getContent()); self::assertSame($second, $annotations[1]->getContent()); self::assertSame($third, $annotations[2]->getContent()); } public function testGetAnnotationsOfTypeThrows(): void { $doc = new DocBlock(self::$sample); $annotations = $doc->getAnnotationsOfType('throws'); self::assertCount(1, $annotations); $content = ' * @throws \Exception asdnjkasd * asdasdasdasdasdasdasdasd * kasdkasdkbasdasdasdjhbasdhbasjdbjasbdjhb '; self::assertSame($content, $annotations[0]->getContent()); } public function testGetAnnotationsOfTypeReturn(): void { $doc = new DocBlock(self::$sample); $annotations = $doc->getAnnotationsOfType('return'); self::assertCount(1, $annotations); $content = ' * @return void '; self::assertSame($content, $annotations[0]->getContent()); } public function testGetAnnotationsOfTypeFoo(): void { $doc = new DocBlock(self::$sample); $annotations = $doc->getAnnotationsOfType('foo'); self::assertCount(0, $annotations); } public function testIsMultiLine(): void { $doc = new DocBlock(self::$sample); self::assertTrue($doc->isMultiLine()); } /** * @dataProvider provideMakeMultiLineCases */ public function testMakeMultiLine(string $inputDocBlock, ?string $outputDocBlock = null, string $indent = '', string $newLine = "\n"): void { $doc = new DocBlock($inputDocBlock); $doc->makeMultiLine($indent, $newLine); if (null === $outputDocBlock) { $outputDocBlock = $inputDocBlock; } self::assertSame($outputDocBlock, $doc->getContent()); } /** * @return iterable<string, array{0: string, 1?: string, 2?: string, 3?: string}> */ public static function provideMakeMultiLineCases(): iterable { yield 'It keeps a multi line doc block as is' => [ "/**\n * Hello\n */", ]; yield 'It keeps a multi line doc block as is with multiple annotations' => [ "/**\n * @foo\n *@bar\n */", ]; yield 'It keeps a multi line doc block with indentation' => [ "/**\n\t *@foo\n\t */", ]; yield 'It Converts a single line to multi line with no indentation' => [ '/** Hello */', "/**\n * Hello\n */", ]; yield 'It Converts a single line to multi line with correct indentation' => [ '/** Hello */', "/**\n * Hello\n */", ' ', ]; yield 'It Converts a single line to multi line with correct indentation and Line ending' => [ '/** Hello */', "/**\r\n * Hello\r\n */", ' ', "\r\n", ]; } /** * @dataProvider provideMakeSingleLineCases */ public function testMakeSingleLine(string $inputDocBlock, ?string $outputDocBlock = null): void { $doc = new DocBlock($inputDocBlock); $doc->makeSingleLine(); if (null === $outputDocBlock) { $outputDocBlock = $inputDocBlock; } self::assertSame($outputDocBlock, $doc->getContent()); } /** * @return iterable<string, array{0: string, 1?: string}> */ public static function provideMakeSingleLineCases(): iterable { yield 'It keeps a single line doc block as is' => [ '/** Hello */', ]; yield 'It converts a multi line doc block to a single line' => [ "/**\n * Hello\n */", '/** Hello */', ]; yield 'It converts a multi line doc block to a single line with annotation' => [ "/**\n * @foo\n */", '/** @foo */', ]; yield 'It converts a multi line doc block to a single line multiple empty lines' => [ "/**\n * @foo\n *\n *\n *\n * */", '/** @foo */', ]; yield 'It changes an empty doc block to single line' => [ "/**\n *\n */", '/** */', ]; yield 'It does not change a multi line doc block if it can\'t' => [ self::$sample, ]; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/DocBlock/LineTest.php
tests/DocBlock/LineTest.php
<?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\DocBlock; use PhpCsFixer\DocBlock\DocBlock; use PhpCsFixer\DocBlock\Line; use PhpCsFixer\Tests\TestCase; /** * @author Graham Campbell <hello@gjcampbell.co.uk> * * @internal * * @covers \PhpCsFixer\DocBlock\Line * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class LineTest extends TestCase { /** * This represents the content an entire docblock. */ private static string $sample = '/** * Test docblock. * * @param string $hello * @param bool $test Description * extends over many lines * * @param adkjbadjasbdand $asdnjkasd * * @throws \Exception asdnjkasd * asdasdasdasdasdasdasdasd * kasdkasdkbasdasdasdjhbasdhbasjdbjasbdjhb * * @return void */'; /** * This represents the content of each line. * * @var list<string> */ private static array $content = [ "/**\n", " * Test docblock.\n", " *\n", " * @param string \$hello\n", " * @param bool \$test Description\n", " * extends over many lines\n", " *\n", " * @param adkjbadjasbdand \$asdnjkasd\n", " *\n", " * @throws \\Exception asdnjkasd\n", " * asdasdasdasdasdasdasdasd\n", " * kasdkasdkbasdasdasdjhbasdhbasjdbjasbdjhb\n", " *\n", " * @return void\n", ' */', ]; /** * This represents the if each line is "useful". * * @var list<bool> */ private static array $useful = [ false, true, false, true, true, true, false, true, false, true, true, true, false, true, false, ]; /** * This represents the if each line "contains a tag". * * @var list<bool> */ private static array $tag = [ false, false, false, true, true, false, false, true, false, true, false, false, false, true, false, ]; /** * @dataProvider provideLinesCases */ public function testPosAndContent(int $pos, string $content): void { $doc = new DocBlock(self::$sample); $line = $doc->getLine($pos); self::assertSame($content, $line->getContent()); self::assertSame($content, (string) $line); } /** * @dataProvider provideLinesCases */ public function testStartOrEndPos(int $pos, string $content): void { $doc = new DocBlock(self::$sample); $line = $doc->getLine($pos); self::assertSame(0 === $pos, $line->isTheStart()); self::assertSame(14 === $pos, $line->isTheEnd()); } /** * @return iterable<int, array{int, string}> */ public static function provideLinesCases(): iterable { foreach (self::$content as $index => $content) { yield [$index, $content]; } } /** * @dataProvider provideUsefulCases */ public function testUseful(int $pos, bool $useful): void { $doc = new DocBlock(self::$sample); $line = $doc->getLine($pos); self::assertSame($useful, $line->containsUsefulContent()); } /** * @return iterable<int, array{int, bool}> */ public static function provideUsefulCases(): iterable { foreach (self::$useful as $index => $useful) { yield [$index, $useful]; } } /** * @dataProvider provideTagCases */ public function testTag(int $pos, bool $tag): void { $doc = new DocBlock(self::$sample); $line = $doc->getLine($pos); self::assertSame($tag, $line->containsATag()); } /** * @return iterable<int, array{int, bool}> */ public static function provideTagCases(): iterable { foreach (self::$tag as $index => $tag) { yield [$index, $tag]; } } public function testSetContent(): void { $line = new Line(" * @param \$foo Hi!\n"); self::assertSame(" * @param \$foo Hi!\n", $line->getContent()); $line->addBlank(); self::assertSame(" * @param \$foo Hi!\n *\n", $line->getContent()); $line->setContent("\t * test\r\n"); self::assertSame("\t * test\r\n", $line->getContent()); $line->addBlank(); self::assertSame("\t * test\r\n\t *\r\n", $line->getContent()); $line->remove(); self::assertSame('', $line->getContent()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/DocBlock/AnnotationTest.php
tests/DocBlock/AnnotationTest.php
<?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\DocBlock; use PhpCsFixer\DocBlock\Annotation; use PhpCsFixer\DocBlock\DocBlock; use PhpCsFixer\DocBlock\Line; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceAnalysis; use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceUseAnalysis; /** * @author Graham Campbell <hello@gjcampbell.co.uk> * @author Dariusz Rumiński <dariusz.ruminski@gmail.com> * * @internal * * @covers \PhpCsFixer\DocBlock\Annotation * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class AnnotationTest extends TestCase { /** * This represents the content an entire docblock. */ private const SAMPLE = '/** * Test docblock. * * @param string $hello * @param bool $test Description * extends over many lines * * @param adkjbadjasbdand $asdnjkasd * * @throws \Exception asdnjkasd * * asdasdasdasdasdasdasdasd * kasdkasdkbasdasdasdjhbasdhbasjdbjasbdjhb * * @return void */'; /** * This represents the content of each annotation. * * @var list<string> */ private const CONTENT = [ " * @param string \$hello\n", " * @param bool \$test Description\n * extends over many lines\n", " * @param adkjbadjasbdand \$asdnjkasd\n", " * @throws \\Exception asdnjkasd\n *\n * asdasdasdasdasdasdasdasd\n * kasdkasdkbasdasdasdjhbasdhbasjdbjasbdjhb\n", " * @return void\n", ]; /** * This represents the start indexes of each annotation. * * @var list<int> */ private const START = [3, 4, 7, 9, 14]; /** * This represents the start indexes of each annotation. * * @var list<int> */ private const END = [3, 5, 7, 12, 14]; /** * This represents the tag type of each annotation. * * @var list<string> */ private static array $tags = ['param', 'param', 'param', 'throws', 'return']; /** * @dataProvider provideGetContentCases */ public function testGetContent(int $index, string $content): void { $doc = new DocBlock(self::SAMPLE); $annotation = $doc->getAnnotation($index); self::assertSame($content, $annotation->getContent()); self::assertSame($content, (string) $annotation); } /** * @return iterable<int, array{int, string}> */ public static function provideGetContentCases(): iterable { foreach (self::CONTENT as $index => $content) { yield [$index, $content]; } } /** * @dataProvider provideStartCases */ public function testStart(int $index, int $start): void { $doc = new DocBlock(self::SAMPLE); $annotation = $doc->getAnnotation($index); self::assertSame($start, $annotation->getStart()); } /** * @return iterable<int, array{int, int}> */ public static function provideStartCases(): iterable { foreach (self::START as $index => $start) { yield [$index, $start]; } } /** * @dataProvider provideEndCases */ public function testEnd(int $index, int $end): void { $doc = new DocBlock(self::SAMPLE); $annotation = $doc->getAnnotation($index); self::assertSame($end, $annotation->getEnd()); } /** * @return iterable<int, array{int, int}> */ public static function provideEndCases(): iterable { foreach (self::END as $index => $end) { yield [$index, $end]; } } /** * @dataProvider provideGetTagCases */ public function testGetTag(int $index, string $tag): void { $doc = new DocBlock(self::SAMPLE); $annotation = $doc->getAnnotation($index); self::assertSame($tag, $annotation->getTag()->getName()); } /** * @return iterable<int, array{int, string}> */ public static function provideGetTagCases(): iterable { foreach (self::$tags as $index => $tag) { yield [$index, $tag]; } } /** * @dataProvider provideRemoveCases */ public function testRemove(int $index, int $start, int $end): void { $doc = new DocBlock(self::SAMPLE); $annotation = $doc->getAnnotation($index); $annotation->remove(); self::assertSame('', $annotation->getContent()); self::assertSame('', $doc->getLine($start)->getContent()); self::assertSame('', $doc->getLine($end)->getContent()); } /** * @return iterable<int, array{int, int, int}> */ public static function provideRemoveCases(): iterable { foreach (self::START as $index => $start) { yield [$index, $start, self::END[$index]]; } } /** * @dataProvider provideRemoveEdgeCasesCases */ public function testRemoveEdgeCases(string $expected, string $input): void { $doc = new DocBlock($input); $annotation = $doc->getAnnotation(0); $annotation->remove(); self::assertSame($expected, $doc->getContent()); } /** * @return iterable<int, array{string, string}> */ public static function provideRemoveEdgeCasesCases(): iterable { // Single line yield ['', '/** @return null*/']; yield ['', '/** @return null */']; yield ['', '/** @return null */']; // Multi line, annotation on start line yield [ '/** */', '/** @return null */', ]; yield [ '/** */', '/** @return null '.' */', ]; // Multi line, annotation on end line yield [ '/** */', '/** * @return null*/', ]; yield [ '/** */', '/** * @return null */', ]; } /** * @param list<string> $expected * * @dataProvider provideTypeParsingCases */ public function testTypeParsing(array $expected, string $input): void { $tag = new Annotation([new Line($input)]); self::assertSame($expected, $tag->getTypes()); } /** * @return iterable<int, array{list<string>, string}> */ public static function provideTypeParsingCases(): iterable { yield [ ['int'], ' * @method int method()', ]; yield [ ['int[]'], " * @return int[]\r", ]; yield [ ['int[]'], " * @return int[]\r\n", ]; yield [ ['Foo[][]'], ' * @method Foo[][] method()', ]; yield [ ['int[]'], ' * @method int[] method()', ]; yield [ ['int[]', 'null'], ' * @method int[]|null method()', ]; yield [ ['int[]', 'null', '?int', 'array'], ' * @method int[]|null|?int|array method()', ]; yield [ ['null', 'Foo\Bar', '\Baz\Bax', 'int[]'], ' * @method null|Foo\Bar|\Baz\Bax|int[] method()', ]; yield [ ['gen<int>'], ' * @method gen<int> method()', ]; yield [ ['int', 'gen<int>'], ' * @method int|gen<int> method()', ]; yield [ ['\int', '\gen<\int, \bool>'], ' * @method \int|\gen<\int, \bool> method()', ]; yield [ ['gen<int, int>'], ' * @method gen<int, int> method()', ]; yield [ ['gen<int, bool|string>'], ' * @method gen<int, bool|string> method()', ]; yield [ ['gen<int, string[]>'], ' * @method gen<int, string[]> method() <> a', ]; yield [ ['gen<int, gener<string, bool>>'], ' * @method gen<int, gener<string, bool>> method() foo <a >', ]; yield [ ['gen<int, gener<string, null|bool>>'], ' * @method gen<int, gener<string, null|bool>> method()', ]; yield [ ['null', 'gen<int, gener<string, bool>>', 'int', 'string[]'], ' * @method null|gen<int, gener<string, bool>>|int|string[] method() foo <a >', ]; yield [ ['null', 'gen<int, gener<string, bool>>', 'int', 'array<int, string>', 'string[]'], ' * @method null|gen<int, gener<string, bool>>|int|array<int, string>|string[] method() foo <a >', ]; yield [ ['this'], '/** @return this */', ]; yield [ ['@this'], '/** @return @this */', ]; yield [ ['$SELF', 'int'], '/** @return $SELF|int */', ]; yield [ ['array<string|int, string>'], '/** @var array<string|int, string>', ]; yield [ ['int'], " * @return int\n", ]; yield [ ['int'], " * @return int\r\n", ]; yield [ ['Collection<Foo<Bar>, Foo<Baz>>'], '/** @var Collection<Foo<Bar>, Foo<Baz>>', ]; yield [ ['int', 'string'], '/** @var int | string', ]; yield [ ['Foo::*'], '/** @var Foo::*', ]; yield [ ['Foo::A'], '/** @var Foo::A', ]; yield [ ['Foo::A', 'Foo::B'], '/** @var Foo::A|Foo::B', ]; yield [ ['Foo::A*'], '/** @var Foo::A*', ]; yield [ ['array<Foo::A*>', 'null'], '/** @var array<Foo::A*>|null', ]; yield [ ['null', 'true', 'false', '1', '-1', '1.5', '-1.5', '.5', '1.', "'a'", '"b"'], '/** @var null|true|false|1|-1|1.5|-1.5|.5|1.|\'a\'|"b"', ]; yield [ ['int', '"a"', 'A<B<C, D>, E<F::*|G[]>>'], '/** @param int | "a" | A<B<C, D>, E<F::*|G[]>> $foo */', ]; yield [ ['class-string<Foo>'], '/** @var class-string<Foo> */', ]; yield [ ['A', 'B'], '/** @var A&B */', ]; yield [ ['A', 'B'], '/** @var A & B */', ]; yield [ ['array{1: bool, 2: bool}'], '/** @var array{1: bool, 2: bool} */', ]; yield [ ['array{a: int|string, b?: bool}'], '/** @var array{a: int|string, b?: bool} */', ]; yield [ ['array{\'a\': "a", "b"?: \'b\'}'], '/** @var array{\'a\': "a", "b"?: \'b\'} */', ]; yield [ ['array { a : int | string , b ? : A<B, C> }'], '/** @var array { a : int | string , b ? : A<B, C> } */', ]; yield [ ["array{\n a: int,\n b: string\n}"], "/** @var array{\n a: int,\n b: string\n} */", ]; yield [ ['callable(string)'], '/** @param callable(string) $function', ]; yield [ ['callable(string): bool'], '/** @param callable(string): bool $function', ]; yield [ ['callable(array<int, string>, array<int, Foo>): bool'], '/** @param callable(array<int, string>, array<int, Foo>): bool $function', ]; yield [ ['array<int, callable(string): bool>'], '/** @param array<int, callable(string): bool> $function', ]; yield [ ['callable(string): callable(int)'], '/** @param callable(string): callable(int) $function', ]; yield [ ['callable(string) : callable(int) : bool'], '/** @param callable(string) : callable(int) : bool $function', ]; yield [ ['TheCollection<callable(Foo, Bar,Baz): Foo[]>', 'string[]', 'null'], '* @param TheCollection<callable(Foo, Bar,Baz): Foo[]>|string[]|null $x', ]; yield [ ['Closure(string)'], '/** @param Closure(string) $function', ]; yield [ ['closure()'], '/** @param closure() $function', ]; yield [ ['array < int , callable ( string ) : bool >'], '/** @param array < int , callable ( string ) : bool > $function', ]; } /** * @param list<string> $expected * @param list<string> $new * * @dataProvider provideTypesCases */ public function testTypes(array $expected, array $new, string $input, string $output): void { $line = new Line($input); $tag = new Annotation([$line]); self::assertSame($expected, $tag->getTypes()); $tag->setTypes($new); self::assertSame($new, $tag->getTypes()); self::assertSame($output, $line->getContent()); } /** * @return iterable<int, array{list<string>, list<string>, string, string}> */ public static function provideTypesCases(): iterable { yield [['Foo', 'null'], ['Bar[]'], ' * @param Foo|null $foo', ' * @param Bar[] $foo']; yield [['false'], ['bool'], '* @return false', '* @return bool']; yield [['RUNTIMEEEEeXCEPTION'], [\Throwable::class], "* \t@throws\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n", "* \t@throws\t \t Throwable\t\t\t\t\t\t\t\n\n\n"]; yield [['RUNTIMEEEEeXCEPTION'], [\Throwable::class], "*\t@throws\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n", "*\t@throws\t \t Throwable\t\t\t\t\t\t\t\n\n\n"]; yield [['RUNTIMEEEEeXCEPTION'], [\Throwable::class], "*@throws\t \t RUNTIMEEEEeXCEPTION\t\t\t\t\t\t\t\n\n\n", "*@throws\t \t Throwable\t\t\t\t\t\t\t\n\n\n"]; yield [['string'], ['string', 'null'], ' * @method string getString()', ' * @method string|null getString()']; yield [['Foo', 'Bar'], ['Bar', 'Foo'], ' * @param Foo&Bar $x', ' * @param Bar&Foo $x']; } /** * @param list<string> $expected * * @dataProvider provideNormalizedTypesCases */ public function testNormalizedTypes(array $expected, string $input): void { $line = new Line($input); $tag = new Annotation([$line]); self::assertSame($expected, $tag->getNormalizedTypes()); } /** * @return iterable<int, array{list<string>, string}> */ public static function provideNormalizedTypesCases(): iterable { yield [['null', 'string'], '* @param StRiNg|NuLl $foo']; yield [['void'], '* @return Void']; yield [['bar', 'baz', 'foo', 'null', 'qux'], '* @return Foo|Bar|Baz|Qux|null']; yield [['bool', 'int'], '* @param bool|int $foo']; yield [['bool', 'int'], '* @param bool&int $foo']; yield [['bool', 'int'], '* @param bool|int ...$foo']; yield [['bool', 'int'], '* @param bool|int &$foo']; yield [['bool', 'int'], '* @param bool|int &...$foo']; yield [['bool', 'int'], '* @param bool|int$foo']; yield [['bool', 'int'], '* @param bool|int&$foo']; yield [['bool', 'int'], '* @param bool|int&...$foo']; yield [['bar&baz', 'foo'], '* @param Foo|Bar&Baz&$param']; yield [['bar&baz', 'foo'], '* @param Baz&Bar|Foo&$param']; } public function testGetTypesOnBadTag(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('This tag does not support types'); $tag = new Annotation([new Line(' * @deprecated since Symfony 1.2')]); $tag->getTypes(); } public function testSetTypesOnBadTag(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('This tag does not support types'); $tag = new Annotation([new Line(' * @author Chuck Norris')]); $tag->setTypes(['string']); } public function testGetTagsWithTypes(): void { $tags = Annotation::getTagsWithTypes(); foreach ($tags as $tag) { self::assertIsString($tag); self::assertNotEmpty($tag); } } /** * @param list<NamespaceUseAnalysis> $namespaceUses * * @dataProvider provideGetTypeExpressionCases */ public function testGetTypeExpression(string $line, ?NamespaceAnalysis $namespace, array $namespaceUses, ?string $expectedCommonType): void { $annotation = new Annotation([new Line($line)], $namespace, $namespaceUses); $result = $annotation->getTypeExpression(); self::assertSame($expectedCommonType, $result->getCommonType()); } /** * @return iterable<int, array{string, null|NamespaceAnalysis, list<NamespaceUseAnalysis>, null|string}> */ public static function provideGetTypeExpressionCases(): iterable { $appNamespace = new NamespaceAnalysis('App', 'App', 0, 999, 0, 999); $useTraversable = new NamespaceUseAnalysis(NamespaceUseAnalysis::TYPE_CLASS, \Traversable::class, \Traversable::class, false, false, 0, 999); yield ['* @param array|Traversable $foo', null, [], 'iterable']; yield ['* @param array|Traversable $foo', $appNamespace, [], null]; yield ['* @param array|Traversable $foo', $appNamespace, [$useTraversable], 'iterable']; } /** * @dataProvider provideGetVariableNameCases */ public function testGetVariableName(string $line, ?string $expectedVariableName): void { $annotation = new Annotation([new Line($line)]); self::assertSame($expectedVariableName, $annotation->getVariableName()); } /** * @return iterable<int, array{string, null|string}> */ public static function provideGetVariableNameCases(): iterable { yield ['* @param int $foo', '$foo']; yield ['* @param int $foo some description', '$foo']; yield ['/** @param int $foo*/', '$foo']; yield ['* @param int', null]; yield ['* @var int $foo', '$foo']; yield ['* @var int $foo some description', '$foo']; yield ['/** @var int $foo*/', '$foo']; yield ['* @var int', null]; yield ['* @param $foo', '$foo']; yield ['* @param &$foo', '$foo']; yield ['* @param & $foo', '$foo']; yield ['* @param int&$foo', '$foo']; yield ['* @param int& $foo', '$foo']; yield ['* @param int &$foo', '$foo']; yield ['* @param int & $foo', '$foo']; yield ['* @param int ...$foo', '$foo']; yield ['* @param int ... $foo', '$foo']; yield ['* @param int&...$foo', '$foo']; yield ['* @param int &...$foo', '$foo']; yield ['* @param int & ...$foo', '$foo']; yield ['* @param int & ... $foo', '$foo']; yield ['* @param ?int $foo=null invalid description', '$foo']; yield ['* @param int $počet Special chars in variable name', '$počet']; yield [" * @param array{\n * a: Foo,\n * b: Bar\n * } \$x", '$x']; } public function testGetVariableNameForMultiline(): void { $docBlock = new DocBlock( <<<'PHP' <?php /** * @param array{ * a: Foo, * b: Bar * } $x */ PHP, ); $annotation = $docBlock->getAnnotation(0); self::assertSame('$x', $annotation->getVariableName()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Error/ErrorTest.php
tests/Error/ErrorTest.php
<?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\Error; use PhpCsFixer\Error\Error; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Error\Error * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ErrorTest extends TestCase { public function testConstructorSetsValues(): void { $type = 1; $filePath = 'foo.php'; $error = new Error( $type, $filePath, ); self::assertSame($type, $error->getType()); self::assertSame($filePath, $error->getFilePath()); self::assertNull($error->getSource()); self::assertSame([], $error->getAppliedFixers()); self::assertNull($error->getDiff()); } public function testConstructorSetsValues2(): void { $type = 2; $filePath = __FILE__; $source = new \Exception(); $appliedFixers = ['some_rule']; $diff = '__diff__'; $error = new Error( $type, $filePath, $source, $appliedFixers, $diff, ); self::assertSame($type, $error->getType()); self::assertSame($filePath, $error->getFilePath()); self::assertSame($source, $error->getSource()); self::assertSame($appliedFixers, $error->getAppliedFixers()); self::assertSame($diff, $error->getDiff()); } public function testErrorCanBeSerialised(): void { $type = 2; $filePath = __FILE__; $source = new \Exception(); $appliedFixers = ['some_rule']; $diff = '__diff__'; $error = new Error( $type, $filePath, $source, $appliedFixers, $diff, ); $serialisedError = $error->jsonSerialize(); self::assertSame($type, $serialisedError['type']); self::assertSame($filePath, $serialisedError['filePath']); self::assertSame($source->getMessage(), $serialisedError['source']['message']); self::assertSame($source->getLine(), $serialisedError['source']['line']); self::assertSame($source->getFile(), $serialisedError['source']['file']); self::assertSame($source->getCode(), $serialisedError['source']['code']); self::assertSame($appliedFixers, $serialisedError['appliedFixers']); self::assertSame($diff, $serialisedError['diff']); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Error/SourceExceptionFactoryTest.php
tests/Error/SourceExceptionFactoryTest.php
<?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\Error; use PhpCsFixer\Error\SourceExceptionFactory; use PhpCsFixer\Linter\LintingException; use PhpCsFixer\Runner\Parallel\WorkerException; use PhpCsFixer\Tests\TestCase; /** * @covers \PhpCsFixer\Error\SourceExceptionFactory * * @internal * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class SourceExceptionFactoryTest extends TestCase { public function testFromArrayWithInstantiableException(): void { $exception = SourceExceptionFactory::fromArray([ 'class' => LintingException::class, 'message' => 'foo', 'code' => 1, 'file' => 'foo.php', 'line' => 1, ]); self::assertInstanceOf(LintingException::class, $exception); self::assertSame('foo', $exception->getMessage()); self::assertSame(1, $exception->getCode()); self::assertSame('foo.php', $exception->getFile()); self::assertSame(1, $exception->getLine()); } public function testFromArrayWithInstantiableError(): void { $error = SourceExceptionFactory::fromArray([ 'class' => \ParseError::class, 'message' => 'foo', 'code' => 1, 'file' => 'foo.php', 'line' => 1, ]); self::assertInstanceOf(\ParseError::class, $error); self::assertSame('foo', $error->getMessage()); self::assertSame(1, $error->getCode()); self::assertSame('foo.php', $error->getFile()); self::assertSame(1, $error->getLine()); } public function testFromArrayWithNonInstantiableException(): void { $exception = SourceExceptionFactory::fromArray([ 'class' => WorkerException::class, 'message' => 'foo', 'code' => 1, 'file' => 'foo.php', 'line' => 1, ]); self::assertInstanceOf(\RuntimeException::class, $exception); self::assertSame('[PhpCsFixer\Runner\Parallel\WorkerException] foo', $exception->getMessage()); self::assertSame(1, $exception->getCode()); self::assertSame('foo.php', $exception->getFile()); self::assertSame(1, $exception->getLine()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Error/ErrorsManagerTest.php
tests/Error/ErrorsManagerTest.php
<?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\Error; use PhpCsFixer\Error\Error; use PhpCsFixer\Error\ErrorsManager; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Error\ErrorsManager * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ErrorsManagerTest extends TestCase { public function testDefaults(): void { $errorsManager = new ErrorsManager(); self::assertTrue($errorsManager->isEmpty()); self::assertEmpty($errorsManager->getInvalidErrors()); self::assertEmpty($errorsManager->getExceptionErrors()); self::assertEmpty($errorsManager->getLintErrors()); } public function testThatCanReportAndRetrieveInvalidErrors(): void { $error = new Error( Error::TYPE_INVALID, 'foo.php', ); $errorsManager = new ErrorsManager(); $errorsManager->report($error); self::assertFalse($errorsManager->isEmpty()); $errors = $errorsManager->getInvalidErrors(); self::assertCount(1, $errors); self::assertSame($error, array_shift($errors)); self::assertCount(0, $errorsManager->getExceptionErrors()); self::assertCount(0, $errorsManager->getLintErrors()); } public function testThatCanReportAndRetrieveExceptionErrors(): void { $error = new Error( Error::TYPE_EXCEPTION, 'foo.php', ); $errorsManager = new ErrorsManager(); $errorsManager->report($error); self::assertFalse($errorsManager->isEmpty()); $errors = $errorsManager->getExceptionErrors(); self::assertCount(1, $errors); self::assertSame($error, array_shift($errors)); self::assertCount(0, $errorsManager->getInvalidErrors()); self::assertCount(0, $errorsManager->getLintErrors()); } public function testThatCanReportAndRetrieveInvalidFileErrors(): void { $error = new Error( Error::TYPE_LINT, 'foo.php', ); $errorsManager = new ErrorsManager(); $errorsManager->report($error); self::assertFalse($errorsManager->isEmpty()); $errors = $errorsManager->getLintErrors(); self::assertCount(1, $errors); self::assertSame($error, array_shift($errors)); self::assertCount(0, $errorsManager->getInvalidErrors()); self::assertCount(0, $errorsManager->getExceptionErrors()); } public function testThatCanReportAndRetrieveErrorsForSpecificPath(): void { $errorsManager = new ErrorsManager(); // All kind of errors for the same path $errorsManager->report(new Error(Error::TYPE_LINT, 'foo.php')); $errorsManager->report(new Error(Error::TYPE_EXCEPTION, 'foo.php')); $errorsManager->report(new Error(Error::TYPE_INVALID, 'foo.php')); // Additional errors for a different path $errorsManager->report(new Error(Error::TYPE_INVALID, 'bar.php')); $errorsManager->report(new Error(Error::TYPE_LINT, 'baz.php')); self::assertFalse($errorsManager->isEmpty()); $errors = $errorsManager->forPath('foo.php'); self::assertCount(3, $errors); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/FixerConfiguration/AllowedValueSubsetTest.php
tests/FixerConfiguration/AllowedValueSubsetTest.php
<?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\FixerConfiguration; use PhpCsFixer\FixerConfiguration\AllowedValueSubset; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\FixerConfiguration\AllowedValueSubset * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class AllowedValueSubsetTest extends TestCase { /** * @param non-empty-list<string> $expected * @param non-empty-list<string> $input * * @dataProvider provideGetAllowedValuesAreSortedCases */ public function testGetAllowedValuesAreSorted(array $expected, array $input): void { $subset = new AllowedValueSubset($input); self::assertSame($expected, $subset->getAllowedValues()); } /** * @return iterable<int, array{list<string>, list<string>}> */ public static function provideGetAllowedValuesAreSortedCases(): iterable { yield [ ['bar', 'foo'], ['foo', 'bar'], ]; yield [ ['bar', 'Foo'], ['Foo', 'bar'], ]; } /** * @param mixed $inputValue * * @dataProvider provideInvokeCases */ public function testInvoke($inputValue, bool $expectedResult): void { $subset = new AllowedValueSubset(['foo', 'bar']); self::assertSame($expectedResult, $subset($inputValue)); } /** * @return iterable<int, array{mixed, bool}> */ public static function provideInvokeCases(): iterable { yield [ ['foo', 'bar'], true, ]; yield [ ['bar', 'foo'], true, ]; yield [ ['foo'], true, ]; yield [ ['bar'], true, ]; yield [ [], true, ]; yield [ ['foo', 'bar', 'baz'], false, ]; yield [ ['baz'], false, ]; yield [ 1, false, ]; yield [ 1.2, false, ]; yield [ 'foo', false, ]; yield [ new \stdClass(), false, ]; yield [ true, false, ]; yield [ null, false, ]; } public function testGetAllowedValues(): void { $values = ['bar', 'foo']; $subset = new AllowedValueSubset($values); self::assertSame($values, $subset->getAllowedValues()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/FixerConfiguration/AliasedFixerOptionTest.php
tests/FixerConfiguration/AliasedFixerOptionTest.php
<?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\FixerConfiguration; use PhpCsFixer\FixerConfiguration\AliasedFixerOption; use PhpCsFixer\FixerConfiguration\FixerOption; use PhpCsFixer\Tests\TestCase; /** * @author ntzm * * @internal * * @covers \PhpCsFixer\FixerConfiguration\AliasedFixerOption * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class AliasedFixerOptionTest extends TestCase { /** * @dataProvider provideGetNameCases */ public function testGetName(string $name): void { $option = new AliasedFixerOption(new FixerOption($name, 'Bar.'), 'baz'); self::assertSame($name, $option->getName()); } /** * @return iterable<int, array{string}> */ public static function provideGetNameCases(): iterable { yield ['foo']; yield ['bar']; } /** * @dataProvider provideGetDescriptionCases */ public function testGetDescription(string $description): void { $option = new AliasedFixerOption(new FixerOption('foo', $description), 'baz'); self::assertSame($description, $option->getDescription()); } /** * @return iterable<int, array{string}> */ public static function provideGetDescriptionCases(): iterable { yield ['Foo.']; yield ['Bar.']; } /** * @dataProvider provideHasDefaultCases */ public function testHasDefault(bool $hasDefault, AliasedFixerOption $input): void { self::assertSame($hasDefault, $input->hasDefault()); } /** * @return iterable<int, array{bool, AliasedFixerOption}> */ public static function provideHasDefaultCases(): iterable { yield [ false, new AliasedFixerOption(new FixerOption('foo', 'Bar.'), 'baz'), ]; yield [ true, new AliasedFixerOption(new FixerOption('foo', 'Bar.', false, 'baz'), 'baz'), ]; } /** * @dataProvider provideGetDefaultCases */ public function testGetDefault(string $default): void { $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.', false, $default), 'baz'); self::assertSame($default, $option->getDefault()); } /** * @return iterable<int, array{string}> */ public static function provideGetDefaultCases(): iterable { yield ['baz']; yield ['foo']; } public function testGetUndefinedDefault(): void { $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.'), 'baz'); $this->expectException(\LogicException::class); $this->expectExceptionMessage('No default value defined.'); $option->getDefault(); } /** * @param null|list<string> $allowedTypes * * @dataProvider provideGetAllowedTypesCases */ public function testGetAllowedTypes(?array $allowedTypes): void { $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.', true, null, $allowedTypes), 'baz'); self::assertSame($allowedTypes, $option->getAllowedTypes()); } /** * @return iterable<int, array{null|list<string>}> */ public static function provideGetAllowedTypesCases(): iterable { yield [null]; yield [['bool']]; yield [['bool', 'string']]; } /** * @param null|non-empty-list<null|(callable(mixed): bool)|scalar> $allowedValues * * @dataProvider provideGetAllowedValuesCases */ public function testGetAllowedValues(?array $allowedValues): void { $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.', true, null, null, $allowedValues), 'baz'); self::assertSame($allowedValues, $option->getAllowedValues()); } /** * @return iterable<int, array{null|non-empty-list<null|(callable(mixed): bool)|scalar>}> */ public static function provideGetAllowedValuesCases(): iterable { yield [null]; yield [['baz']]; yield [['baz', 'qux']]; } public function testGetAllowedValuesClosure(): void { $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.', true, null, null, [static fn () => true]), 'baz'); $allowedTypes = $option->getAllowedValues(); self::assertIsArray($allowedTypes); self::assertCount(1, $allowedTypes); self::assertArrayHasKey(0, $allowedTypes); self::assertInstanceOf(\Closure::class, $allowedTypes[0]); } public function testGetNormalizers(): void { $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.'), 'baz'); self::assertNull($option->getNormalizer()); $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.', true, null, null, null, static fn () => null), 'baz'); self::assertInstanceOf(\Closure::class, $option->getNormalizer()); } /** * @dataProvider provideGetAliasCases */ public function testGetAlias(string $alias): void { $options = new AliasedFixerOption(new FixerOption('foo', 'Bar', true, null, null, null, null), $alias); self::assertSame($alias, $options->getAlias()); } /** * @return iterable<int, array{string}> */ public static function provideGetAliasCases(): iterable { yield ['bar']; yield ['baz']; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/FixerConfiguration/DeprecatedFixerOptionTest.php
tests/FixerConfiguration/DeprecatedFixerOptionTest.php
<?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\FixerConfiguration; use PhpCsFixer\FixerConfiguration\DeprecatedFixerOption; use PhpCsFixer\FixerConfiguration\FixerOption; use PhpCsFixer\FixerConfiguration\FixerOptionInterface; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\FixerConfiguration\DeprecatedFixerOption * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class DeprecatedFixerOptionTest extends TestCase { public function testGetName(): void { $option = new DeprecatedFixerOption( new FixerOption('foo', 'Foo.'), 'deprecated', ); self::assertSame('foo', $option->getName()); } public function testGetDescription(): void { $option = new DeprecatedFixerOption( new FixerOption('foo', 'Foo.'), 'deprecated', ); self::assertSame('Foo.', $option->getDescription()); } /** * @dataProvider provideHasDefaultCases */ public function testHasDefault(bool $isRequired): void { $option = new DeprecatedFixerOption( new FixerOption('foo', 'Foo.', $isRequired), 'deprecated', ); self::assertSame(!$isRequired, $option->hasDefault()); } /** * @return iterable<int, array{bool}> */ public static function provideHasDefaultCases(): iterable { yield [true]; yield [false]; } /** * @param mixed $default * * @dataProvider provideGetDefaultCases */ public function testGetDefault($default): void { $option = new DeprecatedFixerOption( new FixerOption('foo', 'Foo.', false, $default), 'deprecated', ); self::assertSame($default, $option->getDefault()); } /** * @return iterable<int, array{bool|string}> */ public static function provideGetDefaultCases(): iterable { yield ['foo']; yield [true]; } public function testGetAllowedTypes(): void { $allowedTypes = ['string', 'bool']; $option = new DeprecatedFixerOption( new FixerOption('foo', 'Foo.', true, null, $allowedTypes), 'deprecated', ); self::assertSame($allowedTypes, $option->getAllowedTypes()); } public function testGetAllowedValues(): void { $allowedValues = ['string', 'bool']; $option = new DeprecatedFixerOption( new FixerOption('foo', 'Foo.', true, null, [], $allowedValues), 'deprecated', ); self::assertSame($allowedValues, $option->getAllowedValues()); } public function testGetNormalizer(): void { $normalizer = static fn () => null; $option = new DeprecatedFixerOption( $this->createFixerOptionDouble($normalizer), 'deprecated', ); self::assertSame($normalizer, $option->getNormalizer()); } public function testGetDeprecationMessage(): void { $option = new DeprecatedFixerOption( new FixerOption('foo', 'Foo.'), 'Use option "bar" instead.', ); self::assertSame('Use option "bar" instead.', $option->getDeprecationMessage()); } private function createFixerOptionDouble(\Closure $normalizer): FixerOptionInterface { return new class($normalizer) implements FixerOptionInterface { private \Closure $normalizer; public function __construct(\Closure $normalizer) { $this->normalizer = $normalizer; } public function getName(): string { throw new \LogicException('Not implemented.'); } public function getDescription(): string { throw new \LogicException('Not implemented.'); } public function hasDefault(): bool { throw new \LogicException('Not implemented.'); } /** * @return mixed * * @throws \LogicException when no default value is defined */ public function getDefault() { throw new \LogicException('Not implemented.'); } public function getAllowedTypes(): ?array { throw new \LogicException('Not implemented.'); } public function getAllowedValues(): ?array { throw new \LogicException('Not implemented.'); } public function getNormalizer(): \Closure { return $this->normalizer; } }; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/FixerConfiguration/FixerConfigurationResolverTest.php
tests/FixerConfiguration/FixerConfigurationResolverTest.php
<?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\FixerConfiguration; use PhpCsFixer\FixerConfiguration\AliasedFixerOption; use PhpCsFixer\FixerConfiguration\AllowedValueSubset; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerOption; use PhpCsFixer\FixerConfiguration\FixerOptionSorter; use PhpCsFixer\Tests\TestCase; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; use Symfony\Component\OptionsResolver\Options; /** * @internal * * @group legacy * * @covers \PhpCsFixer\FixerConfiguration\FixerConfigurationResolver * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class FixerConfigurationResolverTest extends TestCase { public function testWithoutOptions(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Options cannot be empty.'); new FixerConfigurationResolver([]); } public function testWithDuplicatesOptions(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('The "foo" option is defined multiple times.'); new FixerConfigurationResolver([ new FixerOption('foo', 'Bar-1.'), new FixerOption('foo', 'Bar-2.'), ]); } public function testWithDuplicateAliasOptions(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('The "foo" option is defined multiple times.'); new FixerConfigurationResolver([ new AliasedFixerOption(new FixerOption('foo', 'Bar-1.'), 'baz'), new FixerOption('foo', 'Bar-2.'), ]); } public function testGetOptions(): void { $options = [ new FixerOption('foo', 'Bar.'), new FixerOption('baz', 'Qux.'), ]; $configuration = new FixerConfigurationResolver($options); $fixerOptionSorter = new FixerOptionSorter(); $expected = $fixerOptionSorter->sort($options); self::assertSame($expected, $configuration->getOptions()); } public function testResolve(): void { $configuration = new FixerConfigurationResolver([ new FixerOption('foo', 'Bar.'), ]); self::assertSame( ['foo' => 'bar'], $configuration->resolve(['foo' => 'bar']), ); } public function testResolveWithMissingRequiredOption(): void { $configuration = new FixerConfigurationResolver([ new FixerOption('foo', 'Bar.'), ]); $this->expectException(MissingOptionsException::class); $configuration->resolve([]); } public function testResolveWithDefault(): void { $configuration = new FixerConfigurationResolver([ new FixerOption('foo', 'Bar.', false, 'baz'), ]); self::assertSame( ['foo' => 'baz'], $configuration->resolve([]), ); } public function testResolveWithAllowedTypes(): void { $configuration = new FixerConfigurationResolver([ new FixerOption('foo', 'Bar.', true, null, ['int']), ]); self::assertSame( ['foo' => 1], $configuration->resolve(['foo' => 1]), ); $this->expectException(InvalidOptionsException::class); $configuration->resolve(['foo' => '1']); } public function testResolveWithAllowedValues(): void { $configuration = new FixerConfigurationResolver([ new FixerOption('foo', 'Bar.', true, null, null, [true, false]), ]); self::assertSame( ['foo' => true], $configuration->resolve(['foo' => true]), ); $this->expectException(InvalidOptionsException::class); $configuration->resolve(['foo' => 1]); } public function testResolveWithAllowedValuesSubset(): void { $configuration = new FixerConfigurationResolver([ new FixerOption('foo', 'Bar.', true, null, null, [new AllowedValueSubset(['foo', 'bar'])]), ]); self::assertSame( ['foo' => ['bar']], $configuration->resolve(['foo' => ['bar']]), ); $this->expectException(InvalidOptionsException::class); $configuration->resolve(['foo' => ['baz']]); } public function testResolveWithUndefinedOption(): void { $configuration = new FixerConfigurationResolver([ new FixerOption('bar', 'Bar.'), ]); $this->expectException(UndefinedOptionsException::class); $configuration->resolve(['foo' => 'foooo']); } public function testResolveWithNormalizers(): void { $configuration = new FixerConfigurationResolver([ new FixerOption('foo', 'Bar.', true, null, null, null, static fn (Options $options, string $value): int => (int) $value), ]); self::assertSame( ['foo' => 1], $configuration->resolve(['foo' => '1']), ); $exception = new InvalidOptionsException(''); $configuration = new FixerConfigurationResolver([ new FixerOption('foo', 'Bar.', true, null, null, null, static function (Options $options, $value) use ($exception): void { throw $exception; }), ]); $caught = null; try { $configuration->resolve(['foo' => '1']); } catch (InvalidOptionsException $caught) { } self::assertSame($exception, $caught); } public function testResolveWithAliasedDuplicateConfig(): void { $configuration = new FixerConfigurationResolver([ new AliasedFixerOption(new FixerOption('bar', 'Bar.'), 'baz'), ]); $this->expectException(InvalidOptionsException::class); $this->expectExceptionMessage('Aliased option "bar"/"baz" is passed multiple times'); $configuration->resolve([ 'bar' => '1', 'baz' => '2', ]); } public function testResolveWithDeprecatedAlias(): void { $this->expectDeprecation('Option "baz" is deprecated, use "bar" instead.'); $configuration = new FixerConfigurationResolver([ new AliasedFixerOption(new FixerOption('bar', 'Bar.'), 'baz'), ]); $configuration->resolve([ 'baz' => '1', ]); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/FixerConfiguration/AliasedFixerOptionBuilderTest.php
tests/FixerConfiguration/AliasedFixerOptionBuilderTest.php
<?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\FixerConfiguration; use PhpCsFixer\FixerConfiguration\AliasedFixerOptionBuilder; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\Tests\TestCase; /** * @author ntzm * * @internal * * @covers \PhpCsFixer\FixerConfiguration\AliasedFixerOptionBuilder * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class AliasedFixerOptionBuilderTest extends TestCase { public function testSetDefault(): void { $builder = new AliasedFixerOptionBuilder(new FixerOptionBuilder('foo', 'Bar.'), 'baz'); self::assertSame($builder, $builder->setDefault('baz')); } public function testSetAllowedTypes(): void { $builder = new AliasedFixerOptionBuilder(new FixerOptionBuilder('foo', 'Bar.'), 'baz'); self::assertSame($builder, $builder->setAllowedTypes(['bool'])); } public function testSetAllowedValues(): void { $builder = new AliasedFixerOptionBuilder(new FixerOptionBuilder('foo', 'Bar.'), 'baz'); self::assertSame($builder, $builder->setAllowedValues(['baz'])); } public function testSetNormalizer(): void { $builder = new AliasedFixerOptionBuilder(new FixerOptionBuilder('foo', 'Bar.'), 'baz'); self::assertSame($builder, $builder->setNormalizer(static fn () => null)); } public function testGetOption(): void { $builder = new AliasedFixerOptionBuilder(new FixerOptionBuilder('foo', 'Bar.'), 'baz'); $option = $builder ->setDefault('baz') ->setAllowedTypes(['bool']) ->setAllowedValues([true, false]) ->setNormalizer(static fn () => null) ->getOption() ; self::assertSame('foo', $option->getName()); self::assertSame('Bar.', $option->getDescription()); self::assertTrue($option->hasDefault()); self::assertSame('baz', $option->getDefault()); self::assertSame(['bool'], $option->getAllowedTypes()); self::assertSame([true, false], $option->getAllowedValues()); self::assertInstanceOf(\Closure::class, $option->getNormalizer()); self::assertSame('baz', $option->getAlias()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/FixerConfiguration/FixerOptionSorterTest.php
tests/FixerConfiguration/FixerOptionSorterTest.php
<?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\FixerConfiguration; use PhpCsFixer\FixerConfiguration\FixerOption; use PhpCsFixer\FixerConfiguration\FixerOptionSorter; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\FixerConfiguration\FixerOptionSorter * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class FixerOptionSorterTest extends TestCase { public function testSortAcceptsEmptyArray(): void { $unsorted = []; $sorter = new FixerOptionSorter(); $expected = []; self::assertSame($expected, $sorter->sort($unsorted)); } public function testSortSortsArrayOfOptionsByName(): void { $fooOption = new FixerOption('foo', 'Bar.'); $bazOption = new FixerOption('baz', 'Qux.'); $unsorted = [ $fooOption, $bazOption, ]; $sorter = new FixerOptionSorter(); $expected = [ $bazOption, $fooOption, ]; self::assertSame($expected, $sorter->sort($unsorted)); } public function testSortAcceptsEmptyIterable(): void { $unsorted = new \ArrayIterator(); $sorter = new FixerOptionSorter(); $expected = []; self::assertSame($expected, $sorter->sort($unsorted)); } public function testSortSortsIterableOfOptionsByName(): void { $fooOption = new FixerOption('foo', 'Bar.'); $bazOption = new FixerOption('baz', 'Qux.'); $unsorted = new \ArrayIterator([ $fooOption, $bazOption, ]); $sorter = new FixerOptionSorter(); $expected = [ $bazOption, $fooOption, ]; self::assertSame($expected, $sorter->sort($unsorted)); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/FixerConfiguration/FixerOptionBuilderTest.php
tests/FixerConfiguration/FixerOptionBuilderTest.php
<?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\FixerConfiguration; use PhpCsFixer\FixerConfiguration\DeprecatedFixerOption; use PhpCsFixer\FixerConfiguration\FixerOption; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\FixerConfiguration\FixerOptionBuilder * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class FixerOptionBuilderTest extends TestCase { public function testSetDefault(): void { $builder = new FixerOptionBuilder('foo', 'Bar.'); self::assertSame($builder, $builder->setDefault('baz')); } public function testSetAllowedTypes(): void { $builder = new FixerOptionBuilder('foo', 'Bar.'); self::assertSame($builder, $builder->setAllowedTypes(['bool'])); } public function testSetAllowedValues(): void { $builder = new FixerOptionBuilder('foo', 'Bar.'); self::assertSame($builder, $builder->setAllowedValues(['baz'])); } public function testSetNormalizer(): void { $builder = new FixerOptionBuilder('foo', 'Bar.'); self::assertSame($builder, $builder->setNormalizer(static fn () => null)); } public function testGetOption(): void { $builder = new FixerOptionBuilder('foo', 'Bar.'); $regularOption = $builder ->setDefault('baz') ->setAllowedTypes(['bool']) ->setAllowedValues([true, false]) ->setNormalizer(static fn () => null) ->getOption() ; self::assertInstanceOf(FixerOption::class, $regularOption); $deprecationOption = $builder ->setDefault('baz') ->setAllowedTypes(['bool']) ->setAllowedValues([true, false]) ->setNormalizer(static fn () => null) ->setDeprecationMessage('Deprecation message') ->getOption() ; self::assertInstanceOf(DeprecatedFixerOption::class, $deprecationOption); foreach ([$regularOption, $deprecationOption] as $option) { self::assertSame('foo', $option->getName()); self::assertSame('Bar.', $option->getDescription()); self::assertTrue($option->hasDefault()); self::assertSame('baz', $option->getDefault()); self::assertSame(['bool'], $option->getAllowedTypes()); self::assertSame([true, false], $option->getAllowedValues()); self::assertInstanceOf(\Closure::class, $option->getNormalizer()); } } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/FixerConfiguration/FixerOptionTest.php
tests/FixerConfiguration/FixerOptionTest.php
<?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\FixerConfiguration; use PhpCsFixer\FixerConfiguration\FixerOption; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\FixerConfiguration\FixerOption * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class FixerOptionTest extends TestCase { public function testGetName(): void { $option = new FixerOption('foo', 'Bar.'); self::assertSame('foo', $option->getName()); } public function testGetDescription(): void { $option = new FixerOption('foo', 'Bar.'); self::assertSame('Bar.', $option->getDescription()); } public function testHasDefault(): void { $option = new FixerOption('foo', 'Bar.'); self::assertFalse($option->hasDefault()); $option = new FixerOption('foo', 'Bar.', false, 'baz'); self::assertTrue($option->hasDefault()); } public function testGetDefault(): void { $option = new FixerOption('foo', 'Bar.', false, 'baz'); self::assertSame('baz', $option->getDefault()); } public function testGetUndefinedDefault(): void { $option = new FixerOption('foo', 'Bar.'); $this->expectException(\LogicException::class); $this->expectExceptionMessage('No default value defined.'); $option->getDefault(); } public function testGetAllowedTypes(): void { $option = new FixerOption('foo', 'Bar.'); self::assertNull($option->getAllowedTypes()); $option = new FixerOption('foo', 'Bar.', true, null, ['bool']); self::assertSame(['bool'], $option->getAllowedTypes()); $option = new FixerOption('foo', 'Bar.', true, null, ['bool', 'string']); self::assertSame(['bool', 'string'], $option->getAllowedTypes()); } public function testGetAllowedValues(): void { $option = new FixerOption('foo', 'Bar.'); self::assertNull($option->getAllowedValues()); $option = new FixerOption('foo', 'Bar.', true, null, null, ['baz']); self::assertSame(['baz'], $option->getAllowedValues()); $option = new FixerOption('foo', 'Bar.', true, null, null, ['baz', 'qux']); self::assertSame(['baz', 'qux'], $option->getAllowedValues()); $option = new FixerOption('foo', 'Bar.', true, null, null, [static fn () => true]); $allowedTypes = $option->getAllowedValues(); self::assertIsArray($allowedTypes); self::assertCount(1, $allowedTypes); self::assertArrayHasKey(0, $allowedTypes); self::assertInstanceOf(\Closure::class, $allowedTypes[0]); } public function testGetNormalizers(): void { $option = new FixerOption('foo', 'Bar.'); self::assertNull($option->getNormalizer()); $option = new FixerOption('foo', 'Bar.', true, null, null, null, static fn () => null); self::assertInstanceOf(\Closure::class, $option->getNormalizer()); } public function testRequiredWithDefaultValue(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Required options cannot have a default value.'); new FixerOption('foo', 'Bar.', true, false); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/FixerConfiguration/InvalidOptionsForEnvExceptionTest.php
tests/FixerConfiguration/InvalidOptionsForEnvExceptionTest.php
<?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\FixerConfiguration; use PhpCsFixer\FixerConfiguration\InvalidOptionsForEnvException; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\FixerConfiguration\InvalidOptionsForEnvException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class InvalidOptionsForEnvExceptionTest extends TestCase { public function testInvalidOptionsForEnvException(): void { $exception = new InvalidOptionsForEnvException('foo', 123); self::assertSame('foo', $exception->getMessage()); self::assertSame(123, $exception->getCode()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/FileFilterIteratorTest.php
tests/Runner/FileFilterIteratorTest.php
<?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\Runner; use PhpCsFixer\Cache\CacheManagerInterface; use PhpCsFixer\Runner\Event\FileProcessed; use PhpCsFixer\Runner\FileFilterIterator; use PhpCsFixer\Tests\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; /** * @internal * * @covers \PhpCsFixer\Runner\FileFilterIterator * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class FileFilterIteratorTest extends TestCase { /** * @dataProvider provideAcceptCases */ public function testAccept(int $repeat): void { $file = __FILE__; $events = []; $eventDispatcher = new EventDispatcher(); $eventDispatcher->addListener( FileProcessed::NAME, static function (FileProcessed $event) use (&$events): void { $events[] = $event; }, ); $fileInfo = new \SplFileInfo($file); $filter = new FileFilterIterator( new \ArrayIterator(array_fill(0, $repeat, $fileInfo)), $eventDispatcher, $this->createCacheManagerDouble(true), ); self::assertCount(0, $events); $files = iterator_to_array($filter); self::assertCount(1, $files); self::assertSame($fileInfo, reset($files)); } /** * @return iterable<int, array{int}> */ public static function provideAcceptCases(): iterable { yield [1]; yield [2]; yield [3]; } public function testEmitSkipEventWhenCacheNeedFixingFalse(): void { $file = __FILE__; $events = []; $eventDispatcher = new EventDispatcher(); $eventDispatcher->addListener( FileProcessed::NAME, static function (FileProcessed $event) use (&$events): void { $events[] = $event; }, ); $filter = new FileFilterIterator( new \ArrayIterator([new \SplFileInfo($file)]), $eventDispatcher, $this->createCacheManagerDouble(false), ); self::assertCount(0, $filter); self::assertCount(1, $events); /** @var FileProcessed $event */ $event = reset($events); self::assertInstanceOf(FileProcessed::class, $event); self::assertSame(FileProcessed::STATUS_SKIPPED, $event->getStatus()); } public function testIgnoreEmptyFile(): void { $file = __DIR__.'/../Fixtures/empty.php'; $events = []; $eventDispatcher = new EventDispatcher(); $eventDispatcher->addListener( FileProcessed::NAME, static function (FileProcessed $event) use (&$events): void { $events[] = $event; }, ); $filter = new FileFilterIterator( new \ArrayIterator([new \SplFileInfo($file)]), $eventDispatcher, $this->createCacheManagerDouble(true), ); self::assertCount(0, $filter); self::assertCount(1, $events); /** @var FileProcessed $event */ $event = reset($events); self::assertInstanceOf(FileProcessed::class, $event); self::assertSame(FileProcessed::STATUS_SKIPPED, $event->getStatus()); } public function testIgnore(): void { $eventDispatcher = new EventDispatcher(); $eventDispatcher->addListener( FileProcessed::NAME, static function (): void { throw new \Exception('No event expected.'); }, ); $filter = new FileFilterIterator( new \ArrayIterator([ new \SplFileInfo(__DIR__), new \SplFileInfo('__INVALID__'), ]), $eventDispatcher, $this->createCacheManagerDouble(true), ); self::assertCount(0, $filter); } public function testWithoutDispatcher(): void { $file = __FILE__; $filter = new FileFilterIterator( new \ArrayIterator([new \SplFileInfo($file)]), null, $this->createCacheManagerDouble(false), ); self::assertCount(0, $filter); } public function testInvalidIterator(): void { $filter = new FileFilterIterator( new \ArrayIterator([__FILE__]), // @phpstan-ignore-line we want this check for contexts without static analysis null, $this->createCacheManagerDouble(true), ); $this->expectException( \RuntimeException::class, ); $this->expectExceptionMessageMatches( '#^Expected instance of "\\\SplFileInfo", got "string"\.$#', ); iterator_to_array($filter); } /** * @requires OS Linux|Darwin */ public function testFileIsAcceptedAfterFilteredAsSymlink(): void { $link = __DIR__.'/../Fixtures/Test/FileFilterIteratorTest/FileFilterIteratorTest.php.link'; self::assertTrue(is_link($link), 'Fixture data is no longer correct for this test.'); self::assertSame(__FILE__, realpath($link), 'Fixture data is no longer correct for this test.'); $file = new \SplFileInfo(__FILE__); $link = new \SplFileInfo($link); $filter = new FileFilterIterator( new \ArrayIterator([$link, $file]), null, $this->createCacheManagerDouble(true), ); $files = iterator_to_array($filter); self::assertCount(1, $files); self::assertSame($file, reset($files)); } private function createCacheManagerDouble(bool $needFixing): CacheManagerInterface { return new class($needFixing) implements CacheManagerInterface { private bool $needFixing; public function __construct(bool $needFixing) { $this->needFixing = $needFixing; } public function needFixing(string $file, string $fileContent): bool { return $this->needFixing; } public function setFile(string $file, string $fileContent): void { throw new \LogicException('Not implemented.'); } public function setFileHash(string $file, string $hash): void { throw new \LogicException('Not implemented.'); } }; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/LintingFileIteratorTest.php
tests/Runner/LintingFileIteratorTest.php
<?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\Runner; use PhpCsFixer\Linter\LinterInterface; use PhpCsFixer\Linter\LintingResultInterface; use PhpCsFixer\Runner\LintingFileIterator; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Runner\LintingFileIterator * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class LintingFileIteratorTest extends TestCase { public function testFileLintingIteratorEmpty(): void { $iterator = new \ArrayIterator([]); $lintingFileIterator = new LintingFileIterator( $iterator, $this->createLinterDouble(), ); self::assertNull($lintingFileIterator->current()); self::assertNull($lintingFileIterator->currentLintingResult()); self::assertSame($iterator, $lintingFileIterator->getInnerIterator()); self::assertFalse($lintingFileIterator->valid()); } public function testFileLintingIterator(): void { $file = new \SplFileInfo(__FILE__); $lintingResult = new class implements LintingResultInterface { public function check(): void { throw new \LogicException('Not implemented.'); } }; $iterator = new \ArrayIterator([$file]); $lintingFileIterator = new LintingFileIterator( $iterator, $this->createLinterDouble($lintingResult), ); // test when not touched current is null self::assertNull($lintingFileIterator->currentLintingResult()); // test iterating $this->lintingFileIteratorIterationTest($lintingFileIterator, $file, $lintingResult); // rewind and test again $lintingFileIterator->rewind(); $this->lintingFileIteratorIterationTest($lintingFileIterator, $file, $lintingResult); } private function lintingFileIteratorIterationTest( LintingFileIterator $lintingFileIterator, \SplFileInfo $file, LintingResultInterface $lintingResultInterface ): void { $iterations = 0; foreach ($lintingFileIterator as $lintedFile) { self::assertSame($file, $lintedFile); self::assertSame($lintingResultInterface, $lintingFileIterator->currentLintingResult()); ++$iterations; } self::assertSame(1, $iterations); $lintingFileIterator->next(); self::assertNull($lintingFileIterator->currentLintingResult()); } private function createLinterDouble(?LintingResultInterface $lintingResult = null): LinterInterface { return new class($lintingResult) implements LinterInterface { private ?LintingResultInterface $lintingResult; public function __construct(?LintingResultInterface $lintingResult) { $this->lintingResult = $lintingResult; } public function isAsync(): bool { throw new \LogicException('Not implemented.'); } public function lintFile(string $path): LintingResultInterface { return $this->lintingResult; } public function lintSource(string $source): LintingResultInterface { throw new \LogicException('Not implemented.'); } }; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/RunnerConfigTest.php
tests/Runner/RunnerConfigTest.php
<?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\Runner; use PhpCsFixer\Runner\Parallel\ParallelConfig; use PhpCsFixer\Runner\RunnerConfig; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Runner\RunnerConfig * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class RunnerConfigTest extends TestCase { /** * @dataProvider provideGettersReturnCorrectDataCases */ public function testGettersReturnCorrectData( bool $isDryRun, bool $stopOnViolation, ParallelConfig $parallelConfig, ?string $configFile = null ): void { $config = new RunnerConfig($isDryRun, $stopOnViolation, $parallelConfig, $configFile); self::assertSame($isDryRun, $config->isDryRun()); self::assertSame($stopOnViolation, $config->shouldStopOnViolation()); self::assertSame($parallelConfig, $config->getParallelConfig()); self::assertSame($configFile, $config->getConfigFile()); } /** * @return iterable<string, array{0: bool, 1: bool, 2: ParallelConfig, 3?: null|string}> */ public static function provideGettersReturnCorrectDataCases(): iterable { yield 'null config file' => [ false, false, new ParallelConfig(1, 2, 3), null, ]; yield 'config file provided' => [ false, false, new ParallelConfig(1, 2, 3), __DIR__.'/../../../.php-cs-fixer.dist.php', ]; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/FileCachingLintingFileIteratorTest.php
tests/Runner/FileCachingLintingFileIteratorTest.php
<?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\Runner; use PhpCsFixer\Linter\LinterInterface; use PhpCsFixer\Linter\LintingResultInterface; use PhpCsFixer\Runner\FileCachingLintingFileIterator; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Runner\FileCachingLintingFileIterator * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class FileCachingLintingFileIteratorTest extends TestCase { public function testLintingEmpty(): void { $iterator = new \ArrayIterator([]); $fileCachingLintingIterator = new FileCachingLintingFileIterator( $iterator, $this->createLinterDouble(), ); self::assertNull($fileCachingLintingIterator->current()); self::assertSame($iterator, $fileCachingLintingIterator->getInnerIterator()); self::assertFalse($fileCachingLintingIterator->valid()); } public function testLintingNonEmpty(): void { $files = [ new \SplFileInfo(__FILE__), new \SplFileInfo(__FILE__), new \SplFileInfo(__FILE__), ]; $lintingResult = new class implements LintingResultInterface { public function check(): void { throw new \LogicException('Not implemented.'); } }; $iterator = new \ArrayIterator($files); $fileCachingLintingIterator = new FileCachingLintingFileIterator( $iterator, $this->createLinterDouble($lintingResult), ); self::assertLintingIteratorIteration($fileCachingLintingIterator, $lintingResult, ...$files); $fileCachingLintingIterator->rewind(); self::assertLintingIteratorIteration($fileCachingLintingIterator, $lintingResult, ...$files); } private static function assertLintingIteratorIteration( FileCachingLintingFileIterator $fileCachingLintingIterator, LintingResultInterface $lintingResultInterface, \SplFileInfo ...$files ): void { $iterations = 0; foreach ($fileCachingLintingIterator as $index => $lintedFile) { self::assertSame($lintingResultInterface, $fileCachingLintingIterator->currentLintingResult()); \assert(\array_key_exists($index, $files)); self::assertSame($files[$index], $lintedFile); ++$iterations; } self::assertSame(\count($files), $iterations); } private function createLinterDouble(?LintingResultInterface $lintingResult = null): LinterInterface { return new class($lintingResult) implements LinterInterface { private ?LintingResultInterface $lintingResult; public function __construct(?LintingResultInterface $lintingResult) { $this->lintingResult = $lintingResult; } public function isAsync(): bool { throw new \LogicException('Not implemented.'); } public function lintFile(string $path): LintingResultInterface { return $this->lintingResult; } public function lintSource(string $source): LintingResultInterface { throw new \LogicException('Not implemented.'); } }; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/RunnerTest.php
tests/Runner/RunnerTest.php
<?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\Runner; use PhpCsFixer\Cache\Directory; use PhpCsFixer\Cache\NullCacheManager; use PhpCsFixer\Config\RuleCustomisationPolicyInterface; use PhpCsFixer\Console\Command\FixCommand; use PhpCsFixer\Console\ConfigurationResolver; use PhpCsFixer\Differ\DifferInterface; use PhpCsFixer\Differ\NullDiffer; use PhpCsFixer\Error\Error; use PhpCsFixer\Error\ErrorsManager; use PhpCsFixer\Fixer; use PhpCsFixer\Fixer\FixerInterface; use PhpCsFixer\Linter\Linter; use PhpCsFixer\Linter\LinterInterface; use PhpCsFixer\Linter\LintingException; use PhpCsFixer\Linter\LintingResultInterface; use PhpCsFixer\Runner\Event\AnalysisStarted; use PhpCsFixer\Runner\Parallel\ParallelConfig; use PhpCsFixer\Runner\Runner; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\ToolInfo; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Finder\Finder; /** * @internal * * @covers \PhpCsFixer\Runner\Runner * * @phpstan-import-type _RuleCustomisationPolicyCallback from RuleCustomisationPolicyInterface * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class RunnerTest extends TestCase { /** * @covers \PhpCsFixer\Runner\Runner::fix * @covers \PhpCsFixer\Runner\Runner::fixFile */ public function testThatFixSuccessfully(): void { $linter = $this->createLinterDouble(); $fixers = [ new Fixer\ClassNotation\ModifierKeywordsFixer(), new Fixer\Import\NoUnusedImportsFixer(), // will be ignored cause of test keyword in namespace ]; $expectedChangedInfo = [ 'appliedFixers' => ['modifier_keywords'], 'diff' => '', ]; $path = __DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'FixerTest'.\DIRECTORY_SEPARATOR.'fix'; $runner = new Runner( Finder::create()->in($path), $fixers, new NullDiffer(), null, new ErrorsManager(), $linter, true, new NullCacheManager(), new Directory($path), false, ); $changed = $runner->fix(); self::assertCount(2, $changed); self::assertSame($expectedChangedInfo, array_pop($changed)); self::assertSame($expectedChangedInfo, array_pop($changed)); $path = __DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'FixerTest'.\DIRECTORY_SEPARATOR.'fix'; $runner = new Runner( Finder::create()->in($path), $fixers, new NullDiffer(), null, new ErrorsManager(), $linter, true, new NullCacheManager(), new Directory($path), true, ); $changed = $runner->fix(); self::assertCount(1, $changed); self::assertSame($expectedChangedInfo, array_pop($changed)); } /** * @covers \PhpCsFixer\Runner\Runner::fix * @covers \PhpCsFixer\Runner\Runner::fixFile * @covers \PhpCsFixer\Runner\Runner::fixSequential */ public function testThatSequentialFixOfInvalidFileReportsToErrorManager(): void { $errorsManager = new ErrorsManager(); $path = realpath(__DIR__.\DIRECTORY_SEPARATOR.'..').\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'FixerTest'.\DIRECTORY_SEPARATOR.'invalid'; $runner = new Runner( Finder::create()->in($path), [ new Fixer\ClassNotation\ModifierKeywordsFixer(), new Fixer\Import\NoUnusedImportsFixer(), // will be ignored cause of test keyword in namespace ], new NullDiffer(), null, $errorsManager, new Linter(), true, new NullCacheManager(), ); $changed = $runner->fix(); $pathToInvalidFile = $path.\DIRECTORY_SEPARATOR.'somefile.php'; self::assertCount(0, $changed); $errors = $errorsManager->getInvalidErrors(); self::assertCount(1, $errors); $error = $errors[0]; self::assertSame(Error::TYPE_INVALID, $error->getType()); self::assertSame($pathToInvalidFile, $error->getFilePath()); } /** * @covers \PhpCsFixer\Runner\Runner::fix * @covers \PhpCsFixer\Runner\Runner::fixFile * @covers \PhpCsFixer\Runner\Runner::fixParallel */ public function testThatParallelFixOfInvalidFileReportsToErrorManager(): void { $errorsManager = new ErrorsManager(); $path = realpath(__DIR__.\DIRECTORY_SEPARATOR.'..').\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'FixerTest'.\DIRECTORY_SEPARATOR.'invalid'; $runner = new Runner( Finder::create()->in($path), [ new Fixer\ClassNotation\ModifierKeywordsFixer(), new Fixer\Import\NoUnusedImportsFixer(), // will be ignored cause of test keyword in namespace ], new NullDiffer(), null, $errorsManager, new Linter(), true, new NullCacheManager(), null, false, new ParallelConfig(2, 1, 50), new ArrayInput(['--config' => ConfigurationResolver::IGNORE_CONFIG_FILE], (new FixCommand(new ToolInfo()))->getDefinition()), ); $changed = $runner->fix(); $pathToInvalidFile = $path.\DIRECTORY_SEPARATOR.'somefile.php'; self::assertCount(0, $changed); $errors = $errorsManager->getInvalidErrors(); self::assertCount(1, $errors); $error = $errors[0]; self::assertInstanceOf(LintingException::class, $error->getSource()); self::assertSame(Error::TYPE_INVALID, $error->getType()); self::assertSame($pathToInvalidFile, $error->getFilePath()); } /** * @param list<string> $paths * * @covers \PhpCsFixer\Runner\Runner::fix * @covers \PhpCsFixer\Runner\Runner::fixParallel * @covers \PhpCsFixer\Runner\Runner::fixSequential * * @dataProvider provideRunnerUsesProperAnalysisModeCases */ public function testRunnerUsesProperAnalysisMode( ParallelConfig $parallelConfig, array $paths, string $expectedMode ): void { $runner = new Runner( Finder::create()->in($paths), [ new Fixer\ClassNotation\ModifierKeywordsFixer(), new Fixer\Import\NoUnusedImportsFixer(), // will be ignored cause of test keyword in namespace ], new NullDiffer(), $eventDispatcher = new EventDispatcher(), new ErrorsManager(), new Linter(), true, new NullCacheManager(), null, false, $parallelConfig, new ArrayInput(['--config' => ConfigurationResolver::IGNORE_CONFIG_FILE], (new FixCommand(new ToolInfo()))->getDefinition()), ); $eventDispatcher->addListener(AnalysisStarted::NAME, static function (AnalysisStarted $event) use ($expectedMode): void { self::assertSame($expectedMode, $event->getMode()); }); $runner->fix(); } /** * @return iterable<string, array{0: ParallelConfig, 1: list<string>}> */ public static function provideRunnerUsesProperAnalysisModeCases(): iterable { $fixturesBasePath = realpath(__DIR__.\DIRECTORY_SEPARATOR.'..').\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'FixerTest'.\DIRECTORY_SEPARATOR; yield 'single CPU = sequential even though file chunk is lower than actual files count' => [ new ParallelConfig(1, 1), [$fixturesBasePath.'fix'], 'sequential', ]; yield 'less files to fix than configured file chunk = sequential even though multiple CPUs enabled' => [ new ParallelConfig(5, 10), [$fixturesBasePath.'fix'], 'sequential', ]; yield 'multiple CPUs, more files to fix than file chunk size = parallel' => [ new ParallelConfig(2, 1), [$fixturesBasePath.'fix'], 'parallel', ]; } /** * @requires OS Darwin|Windows * * @TODO v4 do not switch on parallel execution by default while this test is not passing on Linux. * * @covers \PhpCsFixer\Runner\Runner::fix * @covers \PhpCsFixer\Runner\Runner::fixFile * @covers \PhpCsFixer\Runner\Runner::fixParallel * * @dataProvider provideParallelFixStopsOnFirstViolationIfSuchOptionIsEnabledCases */ public function testParallelFixStopsOnFirstViolationIfSuchOptionIsEnabled(bool $stopOnViolation, int $expectedChanges): void { $errorsManager = new ErrorsManager(); $path = realpath(__DIR__.\DIRECTORY_SEPARATOR.'..').\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'FixerTest'.\DIRECTORY_SEPARATOR.'fix'; $runner = new Runner( Finder::create()->in($path), [ new Fixer\ClassNotation\ModifierKeywordsFixer(), new Fixer\Import\NoUnusedImportsFixer(), // will be ignored cause of test keyword in namespace ], new NullDiffer(), null, $errorsManager, new Linter(), true, new NullCacheManager(), null, $stopOnViolation, new ParallelConfig(2, 1, 3), new ArrayInput(['--config' => ConfigurationResolver::IGNORE_CONFIG_FILE], (new FixCommand(new ToolInfo()))->getDefinition()), ); self::assertCount($expectedChanges, $runner->fix()); } /** * @return iterable<string, array{0: bool, 1: int}> */ public static function provideParallelFixStopsOnFirstViolationIfSuchOptionIsEnabledCases(): iterable { yield 'do NOT stop on violation' => [false, 2]; yield 'stop on violation' => [true, 1]; } /** * @covers \PhpCsFixer\Runner\Runner::fix * @covers \PhpCsFixer\Runner\Runner::fixFile */ public function testThatDiffedFileIsPassedToDiffer(): void { $differ = $this->createDifferDouble(); $path = __DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'FixerTest'.\DIRECTORY_SEPARATOR.'fix'; $fixers = [ new Fixer\ClassNotation\ModifierKeywordsFixer(), ]; $runner = new Runner( Finder::create()->in($path), $fixers, $differ, null, new ErrorsManager(), new Linter(), true, new NullCacheManager(), new Directory($path), true, ); $runner->fix(); self::assertSame( $path, \Closure::bind( static fn ($differ): string => $differ->passedFile->getPath(), null, \get_class($differ), )($differ), ); } public function testRuleIgnoredByTag(): void { $fixers = [ new Fixer\Basic\NumericLiteralSeparatorFixer(), new Fixer\FunctionNotation\NativeFunctionInvocationFixer(), ]; $path = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'FixerTest'.\DIRECTORY_SEPARATOR.'rule-ignored-by-tag'; $runner = new Runner( Finder::create()->in($path), $fixers, new NullDiffer(), null, new ErrorsManager(), new Linter(), true, new NullCacheManager(), new Directory($path), false, ); $changed = $runner->fix(); self::assertCount(2, $changed); self::assertArrayHasKey('A-without-ignore-tag.php', $changed); self::assertSame( ['numeric_literal_separator', 'native_function_invocation'], $changed['A-without-ignore-tag.php']['appliedFixers'], ); self::assertArrayHasKey('B-with-ignore-tag.php', $changed); self::assertSame( ['native_function_invocation'], $changed['B-with-ignore-tag.php']['appliedFixers'], ); } /** * @param non-empty-string $path * @param _RuleCustomisationPolicyCallback $arraySyntaxCustomiser * @param ?list<array{type: int, filePath: string, sourceMessage: ?string}> $expectedErrors * @param list<string> $expectedFixedFiles * * @covers \PhpCsFixer\Runner\Runner::fix * @covers \PhpCsFixer\Runner\Runner::fixFile * * @dataProvider provideRuleCustomisationPolicyCases */ public function testRuleCustomisationPolicy(string $path, \Closure $arraySyntaxCustomiser, ?array $expectedErrors, array $expectedFixedFiles): void { $arraySyntaxFixer = new Fixer\ArrayNotation\ArraySyntaxFixer(); $arraySyntaxFixer->configure(['syntax' => 'short']); $policy = new class implements RuleCustomisationPolicyInterface { public \Closure $arraySyntaxCustomiser; public function getPolicyVersionForCache(): string { return __METHOD__.__LINE__; } public function getRuleCustomisers(): array { return [ 'array_syntax' => fn (\SplFileInfo $file) => ($this->arraySyntaxCustomiser)($file), ]; } }; $policy->arraySyntaxCustomiser = $arraySyntaxCustomiser; $errorsManager = new ErrorsManager(); $fixedFiles = self::runRunnerWithPolicy($path, [$arraySyntaxFixer], $policy, $errorsManager); self::assertSame($expectedFixedFiles, $fixedFiles); $actualErrors = array_map( static fn (Error $error): array => [ 'type' => $error->getType(), 'filePath' => $error->getFilePath(), 'sourceMessage' => null === $error->getSource() ? null : $error->getSource()->getMessage(), ], $errorsManager->getAllErrors(), ); self::assertEqualsCanonicalizing( $expectedErrors ?? [], $actualErrors, 'Errors do not match expected.', ); } /** * @return iterable<string, array{non-empty-string, _RuleCustomisationPolicyCallback, ?list<array{type: int, filePath: string, sourceMessage: ?string}>, list<string>}> */ public static function provideRuleCustomisationPolicyCases(): iterable { $path = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'FixerTest'.\DIRECTORY_SEPARATOR.'rule-customisation'; yield "Test when the policy doesn't change a fixer" => [ $path, static fn (\SplFileInfo $file) => true, null, // A: fixed, B: fixed, C: fixed, D: already ok ['A.php', 'B.php', 'C.php'], ]; yield 'Test when the policy disables a fixer for a specific file' => [ $path, static fn (\SplFileInfo $file) => 'B.php' === $file->getBasename() ? false : true, null, // A: fixed, B: skipped, C: fixed, D: already ok ['A.php', 'C.php'], ]; yield 'Test when the policy changes a fixer for specific files' => [ $path, static function (\SplFileInfo $file) { if (\in_array($file->getBasename(), ['B.php', 'D.php'], true)) { $fixer = new Fixer\ArrayNotation\ArraySyntaxFixer(); $fixer->configure(['syntax' => 'long']); return $fixer; } return true; }, null, // A: fixed, B: ok for new configuration, C: fixed, D: fixed with new configuration ['A.php', 'C.php', 'D.php'], ]; yield 'Test when the policy changes the fixer class (not allowed)' => [ $path, static fn (\SplFileInfo $file) => 'B.php' === $file->getBasename() ? new Fixer\Whitespace\LineEndingFixer() : true, [ [ 'type' => Error::TYPE_EXCEPTION, 'filePath' => $path.\DIRECTORY_SEPARATOR.'B.php', 'sourceMessage' => \sprintf( 'The fixer returned by the Rule Customisation Policy must be of the same class as the original fixer (expected `%s`, got `%s`).', Fixer\ArrayNotation\ArraySyntaxFixer::class, Fixer\Whitespace\LineEndingFixer::class, ), ], ], // A: fixed, B: exception thrown, C: fixed, D: already ok ['A.php', 'C.php'], ]; } public function testRuleCustomisationPolicyWithMissingFixers(): void { $policy = new class implements RuleCustomisationPolicyInterface { public function getPolicyVersionForCache(): string { return __METHOD__.__LINE__; } public function getRuleCustomisers(): array { return [ 'array_syntax' => static fn (\SplFileInfo $file) => true, 'line_ending' => static fn (\SplFileInfo $file) => true, ]; } }; self::expectException(\RuntimeException::class); self::expectExceptionMessageMatches('/\bline_ending\b/'); self::runRunnerWithPolicy(__DIR__, [new Fixer\ArrayNotation\ArraySyntaxFixer()], $policy, new ErrorsManager()); } /** * @dataProvider provideRuleCustomisationPolicyWithWrongCustomisersCases * * @param array<non-empty-string,_RuleCustomisationPolicyCallback> $customisers */ public function testRuleCustomisationPolicyWithWrongCustomisers(array $customisers, string $error): void { $policy = new /** * @phpstan-import-type _RuleCustomisationPolicyCallback from RuleCustomisationPolicyInterface */ class($customisers) implements RuleCustomisationPolicyInterface { /** * @var array<non-empty-string,_RuleCustomisationPolicyCallback> */ private array $customisers; /** * @param array<non-empty-string,_RuleCustomisationPolicyCallback> $customisers */ public function __construct(array $customisers) { $this->customisers = $customisers; } public function getPolicyVersionForCache(): string { return __METHOD__.__LINE__; } public function getRuleCustomisers(): array { return $this->customisers; } }; self::expectException(\RuntimeException::class); self::expectExceptionMessageMatches($error); self::runRunnerWithPolicy(__DIR__, [new Fixer\ArrayNotation\ArraySyntaxFixer()], $policy, new ErrorsManager()); } /** * @return iterable<string, array{array<non-empty-string, _RuleCustomisationPolicyCallback>, non-empty-string}> */ public static function provideRuleCustomisationPolicyWithWrongCustomisersCases(): iterable { // @phpstan-ignore-next-line generator.valueType yield 'empty rule-key' => [ [ '' => static fn (\SplFileInfo $file) => true, ], '/\(no name provided\)/', ]; yield 'set as rule-key' => [ [ '@auto' => static fn (\SplFileInfo $file) => true, ], '/@auto \(can exclude only rules, not sets\)/', ]; } private function createDifferDouble(): DifferInterface { return new class implements DifferInterface { public ?\SplFileInfo $passedFile = null; public function diff(string $old, string $new, ?\SplFileInfo $file = null): string { $this->passedFile = $file; return 'some-diff'; } }; } private function createLinterDouble(): LinterInterface { return new class implements LinterInterface { public function isAsync(): bool { return false; } public function lintFile(string $path): LintingResultInterface { return new class implements LintingResultInterface { public function check(): void {} }; } public function lintSource(string $source): LintingResultInterface { return new class implements LintingResultInterface { public function check(): void {} }; } }; } /** * @param non-empty-string $path * @param list<FixerInterface> $fixers * * @return list<string> the names of the fixed files */ private static function runRunnerWithPolicy(string $path, array $fixers, RuleCustomisationPolicyInterface $policy, ErrorsManager $errorsManager): array { $runner = new Runner( // $fileIterator Finder::create()->in($path), // $fixers $fixers, // $differ new NullDiffer(), // $eventDispatcher null, // $errorsManager $errorsManager, // $linter new Linter(), // $isDryRun true, // $cacheManager new NullCacheManager(), // $directory new Directory($path), // $stopOnViolation false, // $parallelConfig null, // $input null, // $configFile null, // $ruleCustomisationPolicy $policy, ); $fixInfo = $runner->fix(); $fixedFiles = array_keys($fixInfo); sort($fixedFiles, \SORT_STRING); return $fixedFiles; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Event/AnalysisStartedTest.php
tests/Runner/Event/AnalysisStartedTest.php
<?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\Runner\Event; use PhpCsFixer\Runner\Event\AnalysisStarted; use PhpCsFixer\Tests\TestCase; /** * @covers \PhpCsFixer\Runner\Event\AnalysisStarted * * @internal * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class AnalysisStartedTest extends TestCase { public function testAnalysisStartedEvent(): void { $event = new AnalysisStarted(AnalysisStarted::MODE_SEQUENTIAL, true); self::assertSame('sequential', $event->getMode()); self::assertTrue($event->isDryRun()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Event/FileProcessedTest.php
tests/Runner/Event/FileProcessedTest.php
<?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\Runner\Event; use PhpCsFixer\Runner\Event\FileProcessed; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Runner\Event\FileProcessed * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class FileProcessedTest extends TestCase { public function testFileProcessedEvent(): void { $status = FileProcessed::STATUS_NO_CHANGES; $event = new FileProcessed($status); self::assertSame($status, $event->getStatus()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Parallel/ParallelisationExceptionTest.php
tests/Runner/Parallel/ParallelisationExceptionTest.php
<?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\Runner\Parallel; use PhpCsFixer\Runner\Parallel\ParallelisationException; use PhpCsFixer\Runner\Parallel\ProcessIdentifier; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Runner\Parallel\ParallelisationException * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ParallelisationExceptionTest extends TestCase { public function testCreateForUnknownIdentifier(): void { $identifier = ProcessIdentifier::fromRaw('php-cs-fixer_parallel_foo'); $exception = ParallelisationException::forUnknownIdentifier($identifier); self::assertSame('Unknown process identifier: php-cs-fixer_parallel_foo', $exception->getMessage()); self::assertSame(0, $exception->getCode()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Parallel/ParallelConfigFactoryTest.php
tests/Runner/Parallel/ParallelConfigFactoryTest.php
<?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\Runner\Parallel; use Fidry\CpuCoreCounter\CpuCoreCounter; use Fidry\CpuCoreCounter\Finder\DummyCpuCoreFinder; use PhpCsFixer\Runner\Parallel\ParallelConfig; use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Runner\Parallel\ParallelConfigFactory * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ParallelConfigFactoryTest extends TestCase { protected function tearDown(): void { $this->mockCpuCount(null); parent::tearDown(); } public function testSequentialConfigHasExactlyOneProcess(): void { $config = ParallelConfigFactory::sequential(); self::assertSame(1, $config->getMaxProcesses()); } /** * @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7777#discussion_r1591623367 */ public function testDetectConfigurationWithoutParams(): void { $this->mockCpuCount(7); $config = ParallelConfigFactory::detect(); self::assertSame(6, $config->getMaxProcesses()); self::assertSame(ParallelConfig::DEFAULT_FILES_PER_PROCESS, $config->getFilesPerProcess()); self::assertSame(ParallelConfig::DEFAULT_PROCESS_TIMEOUT, $config->getProcessTimeout()); } public function testDetectConfigurationWithParams(): void { $this->mockCpuCount(7); $config1 = ParallelConfigFactory::detect(22, 2_200, 5); self::assertSame(5, $config1->getMaxProcesses()); self::assertSame(22, $config1->getFilesPerProcess()); self::assertSame(2_200, $config1->getProcessTimeout()); $config2 = ParallelConfigFactory::detect(22, 2_200, 6); self::assertSame(6, $config2->getMaxProcesses()); $config3 = ParallelConfigFactory::detect(22, 2_200, 10); self::assertSame(6, $config3->getMaxProcesses()); } public function testDetectConfigurationWithDefaultValue(): void { $config = ParallelConfigFactory::detect(null, 60); self::assertSame(ParallelConfig::DEFAULT_FILES_PER_PROCESS, $config->getFilesPerProcess()); self::assertSame(60, $config->getProcessTimeout()); } /** * @requires PHP 8.0 */ public function testDetectConfigurationWithNamedArgs(): void { $this->mockCpuCount(7); // First argument omitted, second one provided via named argument $config1 = \call_user_func_array([ParallelConfigFactory::class, 'detect'], ['processTimeout' => 300]); self::assertSame(ParallelConfig::DEFAULT_FILES_PER_PROCESS, $config1->getFilesPerProcess()); self::assertSame(300, $config1->getProcessTimeout()); // Flipped order of arguments using named arguments syntax $config2 = \call_user_func_array([ParallelConfigFactory::class, 'detect'], [ 'maxProcesses' => 1, 'processTimeout' => 300, 'filesPerProcess' => 5, ]); self::assertSame(1, $config2->getMaxProcesses()); self::assertSame(5, $config2->getFilesPerProcess()); self::assertSame(300, $config2->getProcessTimeout()); // Only first argument provided, but via named argument $config3 = \call_user_func_array([ParallelConfigFactory::class, 'detect'], ['filesPerProcess' => 7]); self::assertSame(7, $config3->getFilesPerProcess()); self::assertSame(ParallelConfig::DEFAULT_PROCESS_TIMEOUT, $config3->getProcessTimeout()); // Only third argument provided, but via named argument $config3 = \call_user_func_array([ParallelConfigFactory::class, 'detect'], ['maxProcesses' => 1]); self::assertSame(1, $config3->getMaxProcesses()); self::assertSame(ParallelConfig::DEFAULT_FILES_PER_PROCESS, $config3->getFilesPerProcess()); self::assertSame(ParallelConfig::DEFAULT_PROCESS_TIMEOUT, $config3->getProcessTimeout()); } /** * @param null|positive-int $count */ private function mockCpuCount(?int $count): void { \Closure::bind(static function () use ($count): void { ParallelConfigFactory::$cpuDetector = null !== $count ? new CpuCoreCounter([ new DummyCpuCoreFinder($count), ]) : null; }, null, ParallelConfigFactory::class)(); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Parallel/ParallelConfigTest.php
tests/Runner/Parallel/ParallelConfigTest.php
<?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\Runner\Parallel; use PhpCsFixer\Runner\Parallel\ParallelConfig; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Runner\Parallel\ParallelConfig * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ParallelConfigTest extends TestCase { /** * @dataProvider provideExceptionIsThrownOnNegativeValuesCases */ public function testExceptionIsThrownOnNegativeValues( int $maxProcesses, int $filesPerProcess, int $processTimeout ): void { $this->expectException(\InvalidArgumentException::class); // @phpstan-ignore-next-line False-positive, we pass negative values to the constructor on purpose. new ParallelConfig($maxProcesses, $filesPerProcess, $processTimeout); } /** * @return iterable<int, array{0: int, 1: int, 2: int}> */ public static function provideExceptionIsThrownOnNegativeValuesCases(): iterable { yield [-1, 1, 1]; yield [1, -1, 1]; yield [1, 1, -1]; } public function testGettersAreReturningProperValues(): void { $config = new ParallelConfig(2, 10, 120); self::assertSame(2, $config->getMaxProcesses()); self::assertSame(10, $config->getFilesPerProcess()); self::assertSame(120, $config->getProcessTimeout()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Parallel/ProcessPoolTest.php
tests/Runner/Parallel/ProcessPoolTest.php
<?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\Runner\Parallel; use PhpCsFixer\Console\Command\FixCommand; use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; use PhpCsFixer\Runner\Parallel\ParallelisationException; use PhpCsFixer\Runner\Parallel\Process; use PhpCsFixer\Runner\Parallel\ProcessFactory; use PhpCsFixer\Runner\Parallel\ProcessIdentifier; use PhpCsFixer\Runner\Parallel\ProcessPool; use PhpCsFixer\Runner\RunnerConfig; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\ToolInfo; use React\EventLoop\StreamSelectLoop; use React\Socket\ServerInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArrayInput; /** * @internal * * @covers \PhpCsFixer\Runner\Parallel\ProcessPool * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ProcessPoolTest extends TestCase { public bool $serverClosed = false; private ArrayInput $arrayInput; private ProcessFactory $processFactory; protected function setUp(): void { parent::setUp(); $fixCommand = new FixCommand(new ToolInfo()); $application = new Application(); $application->addCommands([$fixCommand]); // In order to have full list of options supported by the command (e.g. `--verbose`) $fixCommand->mergeApplicationDefinition(false); // @phpstan-ignore method.internal $this->arrayInput = new ArrayInput([], $fixCommand->getDefinition()); $this->processFactory = new ProcessFactory(); } public function testGetProcessWithInvalidIdentifier(): void { self::expectException(ParallelisationException::class); $this->getProcessPool()->getProcess(ProcessIdentifier::create()); } public function testGetProcessWithValidIdentifier(): void { $identifier = ProcessIdentifier::create(); $processPool = $this->getProcessPool(); $process = $this->createProcess($identifier); $processPool->addProcess($identifier, $process); self::assertSame($process, $processPool->getProcess($identifier)); } public function testEndProcessIfKnownWithUnknownIdentifier(): void { $identifier1 = ProcessIdentifier::create(); $identifier2 = ProcessIdentifier::create(); $processPool = $this->getProcessPool(); $process = $this->createProcess($identifier1); $processPool->addProcess($identifier1, $process); // This is unregistered process, so it does nothing $processPool->endProcessIfKnown($identifier2); self::assertFalse($this->serverClosed); } public function testEndProcessIfKnownWithKnownIdentifier(): void { $identifier = ProcessIdentifier::create(); $processPool = $this->getProcessPool(); $process = $this->createProcess($identifier); $processPool->addProcess($identifier, $process); $processPool->endProcessIfKnown($identifier); self::assertTrue($this->serverClosed); } public function testEndAll(): void { $callbackExecuted = false; $processPool = $this->getProcessPool(static function () use (&$callbackExecuted): void { $callbackExecuted = true; }); $identifier1 = ProcessIdentifier::create(); $process1 = $this->createProcess($identifier1); $processPool->addProcess($identifier1, $process1); $identifier2 = ProcessIdentifier::create(); $process2 = $this->createProcess($identifier2); $processPool->addProcess($identifier2, $process2); $processPool->endAll(); self::assertTrue($this->serverClosed); self::assertTrue($callbackExecuted, 'Callback was not executed on server close.'); } private function createProcess(ProcessIdentifier $identifier): Process { return $this->processFactory->create( new StreamSelectLoop(), $this->arrayInput, new RunnerConfig( true, false, ParallelConfigFactory::sequential(), ), $identifier, 10_000, ); } private function getProcessPool(?callable $onServerClose = null): ProcessPool { $this->serverClosed = false; $test = $this; return new ProcessPool( new class($test) implements ServerInterface { private ProcessPoolTest $test; public function __construct(ProcessPoolTest $test) { $this->test = $test; } public function close(): void { $this->test->serverClosed = true; } public function getAddress(): ?string { return null; } public function pause(): void {} public function resume(): void {} /** @phpstan-ignore-next-line */ public function on($event, $listener): void {} /** @phpstan-ignore-next-line */ public function once($event, $listener): void {} /** @phpstan-ignore-next-line */ public function removeListener($event, $listener): void {} /** @phpstan-ignore-next-line */ public function removeAllListeners($event = null): void {} /** @phpstan-ignore-next-line */ public function listeners($event = null): void {} /** @phpstan-ignore-next-line */ public function emit($event, array $arguments = []): void {} }, $onServerClose, ); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Parallel/ProcessIdentifierTest.php
tests/Runner/Parallel/ProcessIdentifierTest.php
<?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\Runner\Parallel; use PhpCsFixer\Runner\Parallel\ParallelisationException; use PhpCsFixer\Runner\Parallel\ProcessIdentifier; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Runner\Parallel\ProcessIdentifier * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ProcessIdentifierTest extends TestCase { public function testCreateIdentifier(): void { $identifier = ProcessIdentifier::create(); self::assertStringStartsWith('php-cs-fixer_parallel_', $identifier->toString()); } /** * @dataProvider provideFromRawCases */ public function testFromRaw(string $rawIdentifier, bool $valid): void { if (!$valid) { self::expectException(ParallelisationException::class); } $identifier = ProcessIdentifier::fromRaw($rawIdentifier); self::assertSame($rawIdentifier, $identifier->toString()); } /** * @return iterable<int, array{0: string, 1: bool}> */ public static function provideFromRawCases(): iterable { yield ['php-cs-fixer_parallel_foo', true]; yield ['invalid', false]; } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Parallel/WorkerExceptionTest.php
tests/Runner/Parallel/WorkerExceptionTest.php
<?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\Runner\Parallel; use PhpCsFixer\Runner\Parallel\WorkerException; use PhpCsFixer\Tests\TestCase; /** * @covers \PhpCsFixer\Runner\Parallel\WorkerException * * @internal * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class WorkerExceptionTest extends TestCase { public function testFromRaw(): void { $exception = WorkerException::fromRaw([ 'class' => \RuntimeException::class, 'message' => 'foo', 'file' => 'foo.php', 'line' => 1, 'code' => 1, 'trace' => '#0 bar', ]); self::assertSame('[RuntimeException] foo', $exception->getMessage()); self::assertSame('foo.php', $exception->getFile()); self::assertSame(1, $exception->getLine()); self::assertSame(1, $exception->getCode()); self::assertSame('## foo.php(1)'.\PHP_EOL.'#0 bar', $exception->getOriginalTraceAsString()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Parallel/ProcessFactoryTest.php
tests/Runner/Parallel/ProcessFactoryTest.php
<?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\Runner\Parallel; use PhpCsFixer\Console\Command\FixCommand; use PhpCsFixer\Preg; use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; use PhpCsFixer\Runner\Parallel\Process; use PhpCsFixer\Runner\Parallel\ProcessFactory; use PhpCsFixer\Runner\Parallel\ProcessIdentifier; use PhpCsFixer\Runner\RunnerConfig; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\ToolInfo; use React\EventLoop\StreamSelectLoop; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputDefinition; /** * @author Greg Korba <greg@codito.dev> * * @internal * * @covers \PhpCsFixer\Runner\Parallel\ProcessFactory * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ProcessFactoryTest extends TestCase { public const IS_WINDOWS = '\\' === \DIRECTORY_SEPARATOR; private InputDefinition $inputDefinition; protected function setUp(): void { parent::setUp(); $fixCommand = new FixCommand(new ToolInfo()); $application = new Application(); $application->addCommands([$fixCommand]); // In order to have full list of options supported by the command (e.g. `--verbose`) $fixCommand->mergeApplicationDefinition(false); // @phpstan-ignore method.internal $this->inputDefinition = $fixCommand->getDefinition(); } /** * This test is not executed on Windows because process pipes are not supported there, due to their blocking nature * on this particular OS. The cause of this lays in `react/child-process` component, but it's related only to tests, * as parallel runner works properly on Windows too. Feel free to fiddle with it and add testing support for Windows. * * @requires OS Linux|Darwin * * @param array<string, string> $input * * @dataProvider provideCreateCases */ public function testCreate(array $input, RunnerConfig $config, string $expectedAdditionalArgs): void { $factory = new ProcessFactory(); $identifier = ProcessIdentifier::create(); $process = $factory->create(new StreamSelectLoop(), new ArrayInput($input, $this->inputDefinition), $config, $identifier, 1_234); $command = \Closure::bind(static fn (Process $process): string => $process->command, null, Process::class)($process); // PHP binary and Fixer executable are not fixed, so we need to remove them from the command $command = Preg::replace('/^(.*php-cs-fixer[\'"]? )+(.+)/', '$2', $command); self::assertSame( \sprintf( 'worker --port=1234 --identifier=%s%s', self::IS_WINDOWS ? '"'.$identifier->toString().'"' : '\''.$identifier->toString().'\'', '' !== $expectedAdditionalArgs ? ' '.$expectedAdditionalArgs : '', ), $command, ); $timeoutSeconds = \Closure::bind(static fn (Process $process): int => $process->timeoutSeconds, null, Process::class)($process); self::assertSame($config->getParallelConfig()->getProcessTimeout(), $timeoutSeconds); } /** * @return iterable<string, array{0: array<string, mixed>, 1: RunnerConfig, 2: string}> */ public static function provideCreateCases(): iterable { yield 'dry run with misc options' => [ [ '--config' => 'conf.php', '--diff' => true, '--using-cache' => 'yes', '--stop-on-violation' => true, ], self::createRunnerConfig(true), self::IS_WINDOWS ? '--dry-run --diff --stop-on-violation --config="conf.php" --using-cache="yes"' : '--dry-run --diff --stop-on-violation --config=\'conf.php\' --using-cache=\'yes\'', ]; } /** * @param array<string, string> $input * * @dataProvider provideGetCommandArgsCases */ public function testGetCommandArgs(array $input, RunnerConfig $config, string $expectedAdditionalArgs): void { $factory = new ProcessFactory(); $identifier = ProcessIdentifier::create(); $commandByArgs = $factory->getCommandArgs(1_234, $identifier, new ArrayInput($input, $this->inputDefinition), $config); $command = implode(' ', $commandByArgs); // PHP binary and Fixer executable are not fixed, so we need to remove them from the command $command = Preg::replace('/^(.*php-cs-fixer[\'"]? )+(.+)/', '$2', $command); self::assertSame( \sprintf( 'worker --port=1234 --identifier=%s%s', self::IS_WINDOWS ? '"'.$identifier->toString().'"' : '\''.$identifier->toString().'\'', '' !== $expectedAdditionalArgs ? ' '.$expectedAdditionalArgs : '', ), $command, ); } /** * @return iterable<string, array{0: array<string, mixed>, 1: RunnerConfig, 2: string}> */ public static function provideGetCommandArgsCases(): iterable { yield 'no additional params' => [[], self::createRunnerConfig(false), '']; yield 'dry run' => [[], self::createRunnerConfig(true), '--dry-run']; yield 'diff enabled' => [['--diff' => true], self::createRunnerConfig(false), '--diff']; yield 'stop-on-violation enabled' => [['--stop-on-violation' => true], self::createRunnerConfig(false), '--stop-on-violation']; yield 'allow risky' => [ ['--allow-risky' => 'yes'], self::createRunnerConfig(false), self::IS_WINDOWS ? '--allow-risky="yes"' : '--allow-risky=\'yes\'', ]; yield 'config' => [ ['--config' => 'foo.php'], self::createRunnerConfig(false), self::IS_WINDOWS ? '--config="foo.php"' : '--config=\'foo.php\'', ]; yield 'using-cache' => [ ['--using-cache' => 'no'], self::createRunnerConfig(false), self::IS_WINDOWS ? '--using-cache="no"' : '--using-cache=\'no\'', ]; yield 'cache-file' => [ ['--cache-file' => 'cache.json'], self::createRunnerConfig(false), self::IS_WINDOWS ? '--cache-file="cache.json"' : '--cache-file=\'cache.json\'', ]; yield 'dry run with other options' => [ [ '--config' => 'conf.php', '--diff' => true, '--using-cache' => 'yes', '--stop-on-violation' => true, ], self::createRunnerConfig(true), self::IS_WINDOWS ? '--dry-run --diff --stop-on-violation --config="conf.php" --using-cache="yes"' : '--dry-run --diff --stop-on-violation --config=\'conf.php\' --using-cache=\'yes\'', ]; yield 'rules' => [ ['--rules' => '@PhpCsFixer'], self::createRunnerConfig(false), self::IS_WINDOWS ? '--rules="@PhpCsFixer"' : '--rules=\'@PhpCsFixer\'', ]; yield 'rules (complex)' => [ ['--rules' => '{"array_syntax":{"syntax":"short"},"binary_operator_spaces":{"operators":{"=>":"single_space"}}}'], self::createRunnerConfig(false), self::IS_WINDOWS ? '--rules="{\"array_syntax\":{\"syntax\":\"short\"},\"binary_operator_spaces\":{\"operators\":{\"=>\":\"single_space\"}}}"' : '--rules=\'{"array_syntax":{"syntax":"short"},"binary_operator_spaces":{"operators":{"=>":"single_space"}}}\'', ]; } private static function createRunnerConfig(bool $dryRun): RunnerConfig { return new RunnerConfig($dryRun, false, ParallelConfigFactory::sequential()); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Parallel/ProcessUtilsTest.php
tests/Runner/Parallel/ProcessUtilsTest.php
<?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\Runner\Parallel; use PhpCsFixer\Tests\TestCase; /** * @internal * * @covers \PhpCsFixer\Runner\Parallel\ProcessUtils * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ProcessUtilsTest extends TestCase { public function testEscapeArgument(): void { self::markTestSkipped('The `escapeArgument` method is copy-pasted from Symfony codebase. Is tested indirectly on testing Parallel flow under Windows.'); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
PHP-CS-Fixer/PHP-CS-Fixer
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/63b024eaaf8a48445494964bd21a6c38c788f40f/tests/Runner/Parallel/ProcessTest.php
tests/Runner/Parallel/ProcessTest.php
<?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\Runner\Parallel; use PhpCsFixer\Runner\Parallel\ParallelisationException; use PhpCsFixer\Runner\Parallel\Process; use PhpCsFixer\Tests\TestCase; use React\EventLoop\StreamSelectLoop; /** * @internal * * @covers \PhpCsFixer\Runner\Parallel\Process * * @no-named-arguments Parameter names are not covered by the backward compatibility promise. */ final class ProcessTest extends TestCase { public function testRequestCantBeInvokedBeforeStart(): void { self::expectException(ParallelisationException::class); $process = new Process('php -v', new StreamSelectLoop(), 123); $process->request([]); } }
php
MIT
63b024eaaf8a48445494964bd21a6c38c788f40f
2026-01-04T15:02:54.911792Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/functions.php
functions.php
<?php use Roots\Acorn\Application; /* |-------------------------------------------------------------------------- | Register The Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader for | our theme. We will simply require it into the script here so that we | don't have to worry about manually loading any of our classes later on. | */ if (! file_exists($composer = __DIR__.'/vendor/autoload.php')) { wp_die(__('Error locating autoloader. Please run <code>composer install</code>.', 'sage')); } require $composer; /* |-------------------------------------------------------------------------- | Register The Bootloader |-------------------------------------------------------------------------- | | The first thing we will do is schedule a new Acorn application container | to boot when WordPress is finished loading the theme. The application | serves as the "glue" for all the components of Laravel and is | the IoC container for the system binding all of the various parts. | */ Application::configure() ->withProviders([ App\Providers\ThemeServiceProvider::class, ]) ->boot(); /* |-------------------------------------------------------------------------- | Register Sage Theme Files |-------------------------------------------------------------------------- | | Out of the box, Sage ships with categorically named theme files | containing common functionality and setup to be bootstrapped with your | theme. Simply add (or remove) files from the array below to change what | is registered alongside Sage. | */ collect(['setup', 'filters']) ->each(function ($file) { if (! locate_template($file = "app/{$file}.php", true, true)) { wp_die( /* translators: %s is replaced with the relative file path */ sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file) ); } });
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/index.php
index.php
<?php echo view(app('sage.view'), app('sage.data'))->render();
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/app/setup.php
app/setup.php
<?php /** * Theme setup. */ namespace App; use Illuminate\Support\Facades\Vite; /** * Inject styles into the block editor. * * @return array */ add_filter('block_editor_settings_all', function ($settings) { $style = Vite::asset('resources/css/editor.css'); $settings['styles'][] = [ 'css' => "@import url('{$style}')", ]; return $settings; }); /** * Inject scripts into the block editor. * * @return void */ add_filter('admin_head', function () { if (! get_current_screen()?->is_block_editor()) { return; } $dependencies = json_decode(Vite::content('editor.deps.json')); foreach ($dependencies as $dependency) { if (! wp_script_is($dependency)) { wp_enqueue_script($dependency); } } echo Vite::withEntryPoints([ 'resources/js/editor.js', ])->toHtml(); }); /** * Use the generated theme.json file. * * @return string */ add_filter('theme_file_path', function ($path, $file) { return $file === 'theme.json' ? public_path('build/assets/theme.json') : $path; }, 10, 2); /** * Register the initial theme setup. * * @return void */ add_action('after_setup_theme', function () { /** * Disable full-site editing support. * * @link https://wptavern.com/gutenberg-10-5-embeds-pdfs-adds-verse-block-color-options-and-introduces-new-patterns */ remove_theme_support('block-templates'); /** * Register the navigation menus. * * @link https://developer.wordpress.org/reference/functions/register_nav_menus/ */ register_nav_menus([ 'primary_navigation' => __('Primary Navigation', 'sage'), ]); /** * Disable the default block patterns. * * @link https://developer.wordpress.org/block-editor/developers/themes/theme-support/#disabling-the-default-block-patterns */ remove_theme_support('core-block-patterns'); /** * Enable plugins to manage the document title. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#title-tag */ add_theme_support('title-tag'); /** * Enable post thumbnail support. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support('post-thumbnails'); /** * Enable responsive embed support. * * @link https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#responsive-embedded-content */ add_theme_support('responsive-embeds'); /** * Enable HTML5 markup support. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#html5 */ add_theme_support('html5', [ 'caption', 'comment-form', 'comment-list', 'gallery', 'search-form', 'script', 'style', ]); /** * Enable selective refresh for widgets in customizer. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#customize-selective-refresh-widgets */ add_theme_support('customize-selective-refresh-widgets'); }, 20); /** * Register the theme sidebars. * * @return void */ add_action('widgets_init', function () { $config = [ 'before_widget' => '<section class="widget %1$s %2$s">', 'after_widget' => '</section>', 'before_title' => '<h3>', 'after_title' => '</h3>', ]; register_sidebar([ 'name' => __('Primary', 'sage'), 'id' => 'sidebar-primary', ] + $config); register_sidebar([ 'name' => __('Footer', 'sage'), 'id' => 'sidebar-footer', ] + $config); });
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/app/filters.php
app/filters.php
<?php /** * Theme filters. */ namespace App; /** * Add "… Continued" to the excerpt. * * @return string */ add_filter('excerpt_more', function () { return sprintf(' &hellip; <a href="%s">%s</a>', get_permalink(), __('Continued', 'sage')); });
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/app/Providers/ThemeServiceProvider.php
app/Providers/ThemeServiceProvider.php
<?php namespace App\Providers; use Roots\Acorn\Sage\SageServiceProvider; class ThemeServiceProvider extends SageServiceProvider { /** * Register any application services. * * @return void */ public function register() { parent::register(); } /** * Bootstrap any application services. * * @return void */ public function boot() { parent::boot(); } }
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/app/View/Composers/App.php
app/View/Composers/App.php
<?php namespace App\View\Composers; use Roots\Acorn\View\Composer; class App extends Composer { /** * List of views served by this composer. * * @var array */ protected static $views = [ '*', ]; /** * Retrieve the site name. */ public function siteName(): string { return get_bloginfo('name', 'display'); } }
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/app/View/Composers/Comments.php
app/View/Composers/Comments.php
<?php namespace App\View\Composers; use Roots\Acorn\View\Composer; class Comments extends Composer { /** * List of views served by this composer. * * @var array */ protected static $views = [ 'partials.comments', ]; /** * The comment title. */ public function title(): string { return sprintf( /* translators: %1$s is replaced with the number of comments and %2$s with the post title */ _nx('%1$s response to &ldquo;%2$s&rdquo;', '%1$s responses to &ldquo;%2$s&rdquo;', get_comments_number(), 'comments title', 'sage'), get_comments_number() === 1 ? _x('One', 'comments title', 'sage') : number_format_i18n(get_comments_number()), get_the_title() ); } /** * Retrieve the comments. */ public function responses(): ?string { if (! have_comments()) { return null; } return wp_list_comments([ 'style' => 'ol', 'short_ping' => true, 'echo' => false, ]); } /** * The previous comments link. */ public function previous(): ?string { if (! get_previous_comments_link()) { return null; } return get_previous_comments_link( __('&larr; Older comments', 'sage') ); } /** * The next comments link. */ public function next(): ?string { if (! get_next_comments_link()) { return null; } return get_next_comments_link( __('Newer comments &rarr;', 'sage') ); } /** * Determine if the comments are paginated. */ public function paginated(): bool { return get_comment_pages_count() > 1 && get_option('page_comments'); } /** * Determine if the comments are closed. */ public function closed(): bool { return ! comments_open() && get_comments_number() != '0' && post_type_supports(get_post_type(), 'comments'); } }
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/app/View/Composers/Post.php
app/View/Composers/Post.php
<?php namespace App\View\Composers; use Roots\Acorn\View\Composer; class Post extends Composer { /** * List of views served by this composer. * * @var array */ protected static $views = [ 'partials.page-header', 'partials.content', 'partials.content-*', ]; /** * Retrieve the post title. */ public function title(): string { if ($this->view->name() !== 'partials.page-header') { return get_the_title(); } if (is_home()) { if ($home = get_option('page_for_posts', true)) { return get_the_title($home); } return __('Latest Posts', 'sage'); } if (is_archive()) { return get_the_archive_title(); } if (is_search()) { return sprintf( /* translators: %s is replaced with the search query */ __('Search Results for %s', 'sage'), get_search_query() ); } if (is_404()) { return __('Not Found', 'sage'); } return get_the_title(); } /** * Retrieve the pagination links. */ public function pagination(): string { return wp_link_pages([ 'echo' => 0, 'before' => '<p>'.__('Pages:', 'sage'), 'after' => '</p>', ]); } }
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/single.blade.php
resources/views/single.blade.php
@extends('layouts.app') @section('content') @while(have_posts()) @php(the_post()) @includeFirst(['partials.content-single-' . get_post_type(), 'partials.content-single']) @endwhile @endsection
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/index.blade.php
resources/views/index.blade.php
@extends('layouts.app') @section('content') @include('partials.page-header') @if (! have_posts()) <x-alert type="warning"> {!! __('Sorry, no results were found.', 'sage') !!} </x-alert> {!! get_search_form(false) !!} @endif @while(have_posts()) @php(the_post()) @includeFirst(['partials.content-' . get_post_type(), 'partials.content']) @endwhile {!! get_the_posts_navigation() !!} @endsection @section('sidebar') @include('sections.sidebar') @endsection
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/search.blade.php
resources/views/search.blade.php
@extends('layouts.app') @section('content') @include('partials.page-header') @if (! have_posts()) <x-alert type="warning"> {!! __('Sorry, no results were found.', 'sage') !!} </x-alert> {!! get_search_form(false) !!} @endif @while(have_posts()) @php(the_post()) @include('partials.content-search') @endwhile {!! get_the_posts_navigation() !!} @endsection
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/page.blade.php
resources/views/page.blade.php
@extends('layouts.app') @section('content') @while(have_posts()) @php(the_post()) @include('partials.page-header') @includeFirst(['partials.content-page', 'partials.content']) @endwhile @endsection
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/404.blade.php
resources/views/404.blade.php
@extends('layouts.app') @section('content') @include('partials.page-header') @if (! have_posts()) <x-alert type="warning"> {!! __('Sorry, but the page you are trying to view does not exist.', 'sage') !!} </x-alert> {!! get_search_form(false) !!} @endif @endsection
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/template-custom.blade.php
resources/views/template-custom.blade.php
{{-- Template Name: Custom Template --}} @extends('layouts.app') @section('content') @while(have_posts()) @php(the_post()) @include('partials.page-header') @include('partials.content-page') @endwhile @endsection
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/sections/header.blade.php
resources/views/sections/header.blade.php
<header class="banner"> <a class="brand" href="{{ home_url('/') }}"> {!! $siteName !!} </a> @if (has_nav_menu('primary_navigation')) <nav class="nav-primary" aria-label="{{ wp_get_nav_menu_name('primary_navigation') }}"> {!! wp_nav_menu(['theme_location' => 'primary_navigation', 'menu_class' => 'nav', 'echo' => false]) !!} </nav> @endif </header>
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/sections/sidebar.blade.php
resources/views/sections/sidebar.blade.php
@php(dynamic_sidebar('sidebar-primary'))
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/sections/footer.blade.php
resources/views/sections/footer.blade.php
<footer class="content-info"> @php(dynamic_sidebar('sidebar-footer')) </footer>
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/components/alert.blade.php
resources/views/components/alert.blade.php
@props([ 'type' => null, 'message' => null, ]) @php($class = match ($type) { 'success' => 'text-green-50 bg-green-400', 'caution' => 'text-yellow-50 bg-yellow-400', 'warning' => 'text-red-50 bg-red-400', default => 'text-indigo-50 bg-indigo-400', }) <div {{ $attributes->merge(['class' => "px-2 py-1 {$class}"]) }}> {!! $message ?? $slot !!} </div>
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/forms/search.blade.php
resources/views/forms/search.blade.php
<form role="search" method="get" class="search-form" action="{{ home_url('/') }}"> <label> <span class="sr-only"> {{ _x('Search for:', 'label', 'sage') }} </span> <input type="search" placeholder="{!! esc_attr_x('Search &hellip;', 'placeholder', 'sage') !!}" value="{{ get_search_query() }}" name="s" > </label> <button>{{ _x('Search', 'submit button', 'sage') }}</button> </form>
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/partials/page-header.blade.php
resources/views/partials/page-header.blade.php
<div class="page-header"> <h1>{!! $title !!}</h1> </div>
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/partials/content.blade.php
resources/views/partials/content.blade.php
<article @php(post_class())> <header> <h2 class="entry-title"> <a href="{{ get_permalink() }}"> {!! $title !!} </a> </h2> @include('partials.entry-meta') </header> <div class="entry-summary"> @php(the_excerpt()) </div> </article>
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false
roots/sage
https://github.com/roots/sage/blob/7920ac9eae20e7f12e62f496a41561c5c48eca1b/resources/views/partials/content-search.blade.php
resources/views/partials/content-search.blade.php
<article @php(post_class())> <header> <h2 class="entry-title"> <a href="{{ get_permalink() }}"> {!! $title !!} </a> </h2> @includeWhen(get_post_type() === 'post', 'partials.entry-meta') </header> <div class="entry-summary"> @php(the_excerpt()) </div> </article>
php
MIT
7920ac9eae20e7f12e62f496a41561c5c48eca1b
2026-01-04T15:02:59.095642Z
false