. */ namespace App\Tests\Services\LabelSystem; use App\Entity\Base\AbstractDBElement; use App\Entity\LabelSystem\LabelOptions; use App\Entity\Parts\Part; use App\Entity\Parts\PartLot; use App\Entity\Parts\Storelocation; use App\Services\LabelSystem\LabelGenerator; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class LabelGeneratorTest extends WebTestCase { /** * @var LabelGenerator */ protected $service; protected function setUp(): void { self::bootKernel(); $this->service = self::$container->get(LabelGenerator::class); } public function supportsDataProvider(): array { return [ ['part', Part::class], ['part_lot', PartLot::class], ['storelocation', Storelocation::class], ]; } /** * @dataProvider supportsDataProvider */ public function testSupports(string $type, string $class): void { $options = new LabelOptions(); $options->setSupportedElement($type); //Ensure that the given class is supported $this->assertTrue($this->service->supports($options, new $class())); //Ensure that another class is not supported $not_supported = new class() extends AbstractDBElement {}; $this->assertFalse($this->service->supports($options, $not_supported)); } public function testMmToPointsArray(): void { $this->assertSame( [0.0, 0.0, 141.7325, 85.0395], $this->service->mmToPointsArray(50.0, 30.0) ); } public function testGenerateLabel(): void { $part = new Part(); $options = new LabelOptions(); $options->setLines('Test'); $options->setSupportedElement('part'); //Test for a single passed element: $pdf = $this->service->generateLabel($options, $part); //Just a simple check if a PDF is returned $this->assertStringStartsWith('%PDF-', $pdf); //Test for an array of elements $pdf = $this->service->generateLabel($options, [$part, $part]); //Just a simple check if a PDF is returned $this->assertStringStartsWith('%PDF-', $pdf); } }