Fixed phpunit tests

This commit is contained in:
Jan Böhmer 2023-07-17 00:34:00 +02:00
parent d10d29e590
commit afcbbe0f43
5 changed files with 11 additions and 8 deletions

View file

@ -46,6 +46,7 @@ use App\Entity\Attachments\PartAttachment;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer; use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\ManufacturingStatus;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
@ -83,7 +84,7 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
$part->setTags('test, Test, Part2'); $part->setTags('test, Test, Part2');
$part->setMass(100.2); $part->setMass(100.2);
$part->setNeedsReview(true); $part->setNeedsReview(true);
$part->setManufacturingStatus('active'); $part->setManufacturingStatus(ManufacturingStatus::ACTIVE);
$manager->persist($part); $manager->persist($part);
/** Part with orderdetails, storelocations and Attachments */ /** Part with orderdetails, storelocations and Attachments */

View file

@ -46,6 +46,7 @@ use App\Entity\LabelSystem\LabelSupportedElement;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer; use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\ManufacturingStatus;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
@ -79,7 +80,7 @@ final class LabelExampleElementsGenerator
$part->setMass(123.4); $part->setMass(123.4);
$part->setManufacturerProductNumber('CUSTOM MPN'); $part->setManufacturerProductNumber('CUSTOM MPN');
$part->setTags('Tag1, Tag2, Tag3'); $part->setTags('Tag1, Tag2, Tag3');
$part->setManufacturingStatus('active'); $part->setManufacturingStatus(ManufacturingStatus::ACTIVE);
$part->updateTimestamps(); $part->updateTimestamps();
$part->setFavorite(true); $part->setFavorite(true);

View file

@ -105,11 +105,11 @@ final class PartProvider implements PlaceholderProviderInterface
} }
if ('[[M_STATUS]]' === $placeholder) { if ('[[M_STATUS]]' === $placeholder) {
if ('' === $part->getManufacturingStatus()) { if (null === $part->getManufacturingStatus()) {
return ''; return '';
} }
return $this->translator->trans('m_status.'.$part->getManufacturingStatus()); return $this->translator->trans($part->getManufacturingStatus()->toTranslationKey());
} }
$parsedown = new Parsedown(); $parsedown = new Parsedown();

View file

@ -215,7 +215,7 @@ EOT;
$this->assertSame($category, $results[1]->getCategory()); $this->assertSame($category, $results[1]->getCategory());
$input = <<<EOT $input = <<<EOT
[{"name":"Test 1","description":"Test 1 description","notes":"Test 1 notes","manufacturer":"Test 1 manufacturer", "tags": "test,test2"},{"name":"Test 2","description":"Test 2 description","notes":"Test 2 notes","manufacturer":"Test 2 manufacturer", "manufacturing_status": "invalid"}] [{"name":"Test 1","description":"Test 1 description","notes":"Test 1 notes","manufacturer":"Test 1 manufacturer", "tags": "test,test2"},{"name":"","description":"Test 2 description","notes":"Test 2 notes","manufacturer":"Test 2 manufacturer", "manufacturing_status": "active"}]
EOT; EOT;
$errors = []; $errors = [];
@ -234,10 +234,10 @@ EOT;
//Check the format of the error //Check the format of the error
$error = reset($errors); $error = reset($errors);
$this->assertInstanceOf(Part::class, $error['entity']); $this->assertInstanceOf(Part::class, $error['entity']);
$this->assertSame('Test 2', $error['entity']->getName()); $this->assertSame('', $error['entity']->getName());
$this->assertContainsOnlyInstancesOf(ConstraintViolation::class, $error['violations']); $this->assertContainsOnlyInstancesOf(ConstraintViolation::class, $error['violations']);
//Element name must be element name //Element name must be element name
$this->assertArrayHasKey('Test 2', $errors); $this->assertArrayHasKey('', $errors);
//Check the valid element //Check the valid element
$this->assertSame('Test 1', $results[0]->getName()); $this->assertSame('Test 1', $results[0]->getName());

View file

@ -41,6 +41,7 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\PlaceholderProviders; namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Parts\ManufacturingStatus;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
@ -80,7 +81,7 @@ class PartProviderTest extends WebTestCase
$this->target->setMass(1234.2); $this->target->setMass(1234.2);
$this->target->setTags('SMD, Tag1, Tag2'); $this->target->setTags('SMD, Tag1, Tag2');
$this->target->setManufacturerProductNumber('MPN123'); $this->target->setManufacturerProductNumber('MPN123');
$this->target->setManufacturingStatus('active'); $this->target->setManufacturingStatus(ManufacturingStatus::ACTIVE);
$this->target->setDescription('<b>Bold</b> *Italic*'); $this->target->setDescription('<b>Bold</b> *Italic*');
$this->target->setComment('<b>Bold</b> *Italic*'); $this->target->setComment('<b>Bold</b> *Italic*');