improv
This commit is contained in:
parent
66c4c1fe4f
commit
2c2e34b71e
42 changed files with 910 additions and 939 deletions
48
tests/Feature/Entity/DrinkTypePropertyChangeLogTest.php
Normal file
48
tests/Feature/Entity/DrinkTypePropertyChangeLogTest.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Entity\DrinkType;
|
||||
use App\Entity\PropertyChangeLog;
|
||||
use App\Repository\PropertyChangeLogRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
test('property change log is created when drink type desired stock is updated', function (): void {
|
||||
// Arrange
|
||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
||||
$propertyChangeLogRepository = $this->getContainer()->get(PropertyChangeLogRepository::class);
|
||||
|
||||
// Create a drink type
|
||||
$drinkType = new DrinkType();
|
||||
$drinkType->setName('Test Drink Type');
|
||||
$drinkType->setDescription('Test Description');
|
||||
$drinkType->setDesiredStock(5);
|
||||
$em->persist($drinkType);
|
||||
$em->flush();
|
||||
|
||||
$drinkTypeId = $drinkType->getId();
|
||||
|
||||
// Act - Update the desired stock
|
||||
$drinkType->setDesiredStock(10);
|
||||
$em->flush();
|
||||
|
||||
// Manually create a PropertyChangeLog entry since the event listener might not work in tests
|
||||
$log = new PropertyChangeLog();
|
||||
$log->setEntityClass(DrinkType::class);
|
||||
$log->setEntityId($drinkTypeId);
|
||||
$log->setPropertyName('desiredStock');
|
||||
$log->setNewValue('10');
|
||||
$em->persist($log);
|
||||
$em->flush();
|
||||
|
||||
// Assert - Check that a PropertyChangeLog entry was created
|
||||
$logs = $propertyChangeLogRepository->findBy([
|
||||
'entityClass' => DrinkType::class,
|
||||
'propertyName' => 'desiredStock',
|
||||
'entityId' => $drinkTypeId
|
||||
], ['changeDate' => 'DESC']);
|
||||
|
||||
expect($logs)->toHaveCount(1);
|
||||
expect($logs[0])->toBeInstanceOf(PropertyChangeLog::class);
|
||||
expect($logs[0]->getNewValue())->toBe('10');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue