123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?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
- */
- final class AllowedValueSubsetTest extends TestCase
- {
- public static function provideGetAllowedValuesAreSortedCases(): iterable
- {
- yield [
- ['bar', 'foo'],
- ['foo', 'bar'],
- ];
- yield [
- ['bar', 'Foo'],
- ['Foo', 'bar'],
- ];
- }
- /**
- * @param list<string> $expected
- * @param list<string> $input
- *
- * @dataProvider provideGetAllowedValuesAreSortedCases
- */
- public function testGetAllowedValuesAreSorted(array $expected, array $input): void
- {
- $subset = new AllowedValueSubset($input);
- self::assertSame($expected, $subset->getAllowedValues());
- }
- /**
- * @param mixed $inputValue
- *
- * @dataProvider provideInvokeCases
- */
- public function testInvoke($inputValue, bool $expectedResult): void
- {
- $subset = new AllowedValueSubset(['foo', 'bar']);
- self::assertSame($expectedResult, $subset($inputValue));
- }
- 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());
- }
- }
|