123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?php
- declare(strict_types=1);
- namespace PhpCsFixer\Tests\FixerConfiguration;
- use PhpCsFixer\FixerConfiguration\AliasedFixerOption;
- use PhpCsFixer\FixerConfiguration\FixerOption;
- use PhpCsFixer\Tests\TestCase;
- final class AliasedFixerOptionTest extends TestCase
- {
-
- public function testGetName(string $name): void
- {
- $option = new AliasedFixerOption(new FixerOption($name, 'Bar.'), 'baz');
- self::assertSame($name, $option->getName());
- }
-
- public static function provideGetNameCases(): iterable
- {
- yield ['foo'];
- yield ['bar'];
- }
-
- public function testGetDescription(string $description): void
- {
- $option = new AliasedFixerOption(new FixerOption('foo', $description), 'baz');
- self::assertSame($description, $option->getDescription());
- }
-
- public static function provideGetDescriptionCases(): iterable
- {
- yield ['Foo.'];
- yield ['Bar.'];
- }
-
- public function testHasDefault(bool $hasDefault, AliasedFixerOption $input): void
- {
- self::assertSame($hasDefault, $input->hasDefault());
- }
-
- 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'),
- ];
- }
-
- public function testGetDefault(string $default): void
- {
- $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.', false, $default), 'baz');
- self::assertSame($default, $option->getDefault());
- }
-
- 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();
- }
-
- public function testGetAllowedTypes(?array $allowedTypes): void
- {
- $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.', true, null, $allowedTypes), 'baz');
- self::assertSame($allowedTypes, $option->getAllowedTypes());
- }
- public static function provideGetAllowedTypesCases(): iterable
- {
- yield [null];
- yield [['bool']];
- yield [['bool', 'string']];
- }
-
- public function testGetAllowedValues(?array $allowedValues): void
- {
- $option = new AliasedFixerOption(new FixerOption('foo', 'Bar.', true, null, null, $allowedValues), 'baz');
- self::assertSame($allowedValues, $option->getAllowedValues());
- }
- 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());
- }
-
- public function testGetAlias(string $alias): void
- {
- $options = new AliasedFixerOption(new FixerOption('foo', 'Bar', true, null, null, null, null), $alias);
- self::assertSame($alias, $options->getAlias());
- }
-
- public static function provideGetAliasCases(): iterable
- {
- yield ['bar'];
- yield ['baz'];
- }
- public function testRequiredWithDefaultValue(): void
- {
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('Required options cannot have a default value.');
- new AliasedFixerOption(new FixerOption('foo', 'Bar.', true, false), 'baz');
- }
- }
|