. */ namespace App\Tests\Services\LabelSystem\Barcodes; use App\Entity\LabelSystem\BarcodeType; use App\Services\LabelSystem\Barcodes\BarcodeHelper; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class BarcodeHelperTest extends WebTestCase { protected ?BarcodeHelper $service = null; protected function setUp(): void { self::bootKernel(); $this->service = self::getContainer()->get(BarcodeHelper::class); } public function testBarcodeAsHTML(): void { $html = $this->service->barcodeAsHTML('Test', BarcodeType::QR); $this->assertStringStartsWith('assertStringContainsString('alt="Test"', $html); } public function testBarcodeAsSVG(): void { //Test that all barcodes types are supported foreach (BarcodeType::cases() as $type) { //Skip NONE type if (BarcodeType::NONE === $type) { continue; } $svg = $this->service->barcodeAsSVG('1234', $type); $this->assertStringContainsStringIgnoringCase('SVG', $svg); } } public function testBarcodeAsSVGNoneType(): void { //On NONE type, service must throw an exception. $this->expectException(\InvalidArgumentException::class); $this->service->barcodeAsSVG('test', BarcodeType::NONE); } }