. */ namespace App\Tests\Services\LabelSystem\Barcodes; use App\Services\LabelSystem\Barcodes\BarcodeNormalizer; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class BarcodeNormalizerTest extends WebTestCase { /** @var BarcodeNormalizer */ protected $service; public function setUp(): void { self::bootKernel(); $this->service = self::$container->get(BarcodeNormalizer::class); } public function dataProvider(): array { return [ //QR URL content: [['lot', 1], 'https://localhost:8000/scan/lot/1'], [['part', 123], 'https://localhost:8000/scan/part/123'], [['location', 4], 'http://foo.bar/part-db/scan/location/4'], [['under_score', 10], 'http://test/part-db/sub/scan/under_score/10/'], //New Code39 barcodes: [['lot', 10], 'L-000010'], [['lot', 10], 'Lß000010'], [['part', 123], 'P-000123'], [['location', 123], 'S-000123'], [['lot', 12345678], 'L-12345678'], //Legacy storelocation format [['location', 336], '$L00336'], [['location', 12345678], '$L12345678'], //Legacy Part format [['part', 123], '0000123'], [['part', 123], '00001236'], [['part', 1234567], '12345678'], ]; } public function invalidDataProvider(): array { return [ ['https://localhost/part/1'], //Without scan ['L-'], //Without number ['L-123'], //Too short ['X-123456'], //Unknown prefix ['XXXWADSDF sdf'], //Garbage [''], //Empty ]; } /** * @dataProvider dataProvider */ public function testNormalizeBarcodeContent(array $expected, string $input) { $this->assertSame($expected, $this->service->normalizeBarcodeContent($input)); } /** * @dataProvider invalidDataProvider */ public function testInvalidFormats(string $input) { $this->expectException(\InvalidArgumentException::class); $this->service->normalizeBarcodeContent($input); } }