. */ namespace App\Tests\Services\Misc; use App\Services\Misc\RangeParser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class RangeParserTest extends WebTestCase { /** * @var RangeParser */ protected $service; public function setUp(): void { self::bootKernel(); $this->service = self::$container->get(RangeParser::class); } public function dataProvider(): array { return [ [[], ''], [[], ' '], [[], "\t"], [[1], "1"], [[1, 2, 3], "1,2, 3"], [[1, 2, 3], "1-3"], [[1, 2, 3, 4], "1- 3, 4"], [[1, 2, 3, 4], "1, 2,3 - 4"], [[1, 2, 3], " 1; 2, 3"], [[-1, 0, 1, 2], "-1; 0; 1, 2"], [[4,3, 1, 2], "4,3, 1;2"], [[1, 2, 3, 4], "2-1, 3-4"], [[1], "1-1"], [[-3, -2, -1], "-3--1"], [[1, 2, 3], "1,,2;;,,3"], [[100, 1000, 1], "100, 1000, 1"], [[], 'test', true], [[], '1-2-3-4,5', true], [[], '1 2 3, 455, 23', true], [[], '1, 2, test', true], ]; } public function validDataProvider(): array { return [ [true, ''], [true, ' '], [true, '1, 2, 3'], [true, '1-2,3, 4- 5'], [true, '1 -2, 3- 4, 6'], [true, '1--2'], [true, '1- -2'], [true, ',,12,33'], [false, 'test'], [false, '1-2-3'], [false, '1, 2 test'], ]; } /** * @dataProvider dataProvider */ public function testParse(array $expected, string $input, bool $must_throw = false): void { if ($must_throw) { $this->expectException(\InvalidArgumentException::class); $this->service->parse($input); } else { $this->assertSame($expected, $this->service->parse($input)); } } /** * @dataProvider validDataProvider */ public function testIsValidRange(bool $expected, string $input): void { $this->assertSame($expected, $this->service->isValidRange($input)); } }