tetssssss
This commit is contained in:
parent
6f07d70436
commit
8063e7bec9
28 changed files with 771 additions and 273 deletions
|
@ -1,18 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Enum\SystemSettingKey;
|
||||
use App\Service\Config\AppName;
|
||||
use App\Service\ConfigurationService;
|
||||
|
||||
test('it returns the system name from configuration service', function () {
|
||||
test('it returns the system name from configuration service', function (): void {
|
||||
|
||||
/** @var ConfigurationService $configService */
|
||||
$configService = $this->getContainer()->get(ConfigurationService::class);
|
||||
$appName = new AppName($configService);
|
||||
expect((string)$appName)->toBe(SystemSettingKey::SYSTEM_NAME->defaultValue());
|
||||
expect((string) $appName)->toBe(SystemSettingKey::SYSTEM_NAME->defaultValue());
|
||||
|
||||
$expected = 'Test System Name';
|
||||
$configService->set(SystemSettingKey::SYSTEM_NAME, $expected);
|
||||
expect((string)$appName)->toBe($expected);
|
||||
expect((string) $appName)->toBe($expected);
|
||||
|
||||
});
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Entity\SystemConfig;
|
||||
use App\Enum\SystemSettingKey;
|
||||
use App\Service\ConfigurationService;
|
||||
|
||||
|
||||
test('get returns correct value', function (): void {
|
||||
// Arrange
|
||||
/** @var ConfigurationService $configService */
|
||||
|
|
87
tests/Feature/Service/DrinkType/GetStockHistoryTest.php
Normal file
87
tests/Feature/Service/DrinkType/GetStockHistoryTest.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Entity\DrinkType;
|
||||
use App\Entity\PropertyChangeLog;
|
||||
use App\Service\DrinkType\GetStockHistory;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
test('it returns empty array for unsaved drink type', function (): void {
|
||||
$drinkType = new DrinkType();
|
||||
$drinkType->setName('Test Drink');
|
||||
|
||||
$getStockHistory = $this->getContainer()->get(GetStockHistory::class);
|
||||
$result = $getStockHistory($drinkType);
|
||||
|
||||
expect($result)->toBeArray();
|
||||
expect($result)->toBeEmpty();
|
||||
});
|
||||
|
||||
test('it returns stock history for a drink type', function (): void {
|
||||
// Create a drink type
|
||||
$drinkType = new DrinkType();
|
||||
$drinkType->setName('Test Drink');
|
||||
$drinkType->setCurrentStock(10);
|
||||
|
||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
||||
$em->persist($drinkType);
|
||||
$em->flush();
|
||||
|
||||
// Change the current stock to create logs
|
||||
$drinkType->setCurrentStock(15);
|
||||
$em->persist($drinkType);
|
||||
$em->flush();
|
||||
|
||||
$drinkType->setCurrentStock(5);
|
||||
$em->persist($drinkType);
|
||||
$em->flush();
|
||||
|
||||
// Get the stock history
|
||||
$getStockHistory = $this->getContainer()->get(GetStockHistory::class);
|
||||
$result = $getStockHistory($drinkType);
|
||||
|
||||
// Verify the result
|
||||
expect($result)->toBeArray();
|
||||
expect($result)->toHaveCount(3);
|
||||
|
||||
// Verify that all logs are for currentStock
|
||||
foreach ($result as $log) {
|
||||
expect($log)->toBeInstanceOf(PropertyChangeLog::class);
|
||||
expect($log->getPropertyName())->toBe('currentStock');
|
||||
expect($log->getEntityClass())->toBe(DrinkType::class);
|
||||
expect($log->getEntityId())->toBe($drinkType->getId());
|
||||
}
|
||||
|
||||
// Verify the values in order (oldest first)
|
||||
expect($result[0]->getNewValue())->toBe('10');
|
||||
expect($result[1]->getNewValue())->toBe('15');
|
||||
expect($result[2]->getNewValue())->toBe('5');
|
||||
});
|
||||
|
||||
test('it only returns logs for the specified drink type', function (): void {
|
||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
// Create first drink type
|
||||
$drinkType1 = new DrinkType();
|
||||
$drinkType1->setName('Drink 1');
|
||||
$drinkType1->setCurrentStock(10);
|
||||
$em->persist($drinkType1);
|
||||
$em->flush();
|
||||
|
||||
// Create second drink type
|
||||
$drinkType2 = new DrinkType();
|
||||
$drinkType2->setName('Drink 2');
|
||||
$drinkType2->setCurrentStock(20);
|
||||
$em->persist($drinkType2);
|
||||
$em->flush();
|
||||
|
||||
// Get history for first drink type
|
||||
$getStockHistory = $this->getContainer()->get(GetStockHistory::class);
|
||||
$result = $getStockHistory($drinkType1);
|
||||
|
||||
// Verify we only get logs for the first drink type
|
||||
expect($result)->toHaveCount(1);
|
||||
expect($result[0]->getEntityId())->toBe($drinkType1->getId());
|
||||
expect($result[0]->getNewValue())->toBe('10');
|
||||
});
|
87
tests/Feature/Service/DrinkType/GetWantedHistoryTest.php
Normal file
87
tests/Feature/Service/DrinkType/GetWantedHistoryTest.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Entity\DrinkType;
|
||||
use App\Entity\PropertyChangeLog;
|
||||
use App\Service\DrinkType\GetWantedHistory;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
test('it returns empty array for unsaved drink type', function (): void {
|
||||
$drinkType = new DrinkType();
|
||||
$drinkType->setName('Test Drink');
|
||||
|
||||
$getWantedHistory = $this->getContainer()->get(GetWantedHistory::class);
|
||||
$result = $getWantedHistory($drinkType);
|
||||
|
||||
expect($result)->toBeArray();
|
||||
expect($result)->toBeEmpty();
|
||||
});
|
||||
|
||||
test('it returns wanted stock history for a drink type', function (): void {
|
||||
// Create a drink type
|
||||
$drinkType = new DrinkType();
|
||||
$drinkType->setName('Test Drink');
|
||||
$drinkType->setWantedStock(10);
|
||||
|
||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
||||
$em->persist($drinkType);
|
||||
$em->flush();
|
||||
|
||||
// Change the wanted stock to create logs
|
||||
$drinkType->setWantedStock(15);
|
||||
$em->persist($drinkType);
|
||||
$em->flush();
|
||||
|
||||
$drinkType->setWantedStock(5);
|
||||
$em->persist($drinkType);
|
||||
$em->flush();
|
||||
|
||||
// Get the wanted stock history
|
||||
$getWantedHistory = $this->getContainer()->get(GetWantedHistory::class);
|
||||
$result = $getWantedHistory($drinkType);
|
||||
|
||||
// Verify the result
|
||||
expect($result)->toBeArray();
|
||||
expect($result)->toHaveCount(3);
|
||||
|
||||
// Verify that all logs are for wantedStock
|
||||
foreach ($result as $log) {
|
||||
expect($log)->toBeInstanceOf(PropertyChangeLog::class);
|
||||
expect($log->getPropertyName())->toBe('wantedStock');
|
||||
expect($log->getEntityClass())->toBe(DrinkType::class);
|
||||
expect($log->getEntityId())->toBe($drinkType->getId());
|
||||
}
|
||||
|
||||
// Verify the values in order (oldest first)
|
||||
expect($result[0]->getNewValue())->toBe('10');
|
||||
expect($result[1]->getNewValue())->toBe('15');
|
||||
expect($result[2]->getNewValue())->toBe('5');
|
||||
});
|
||||
|
||||
test('it only returns logs for the specified drink type', function (): void {
|
||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
// Create first drink type
|
||||
$drinkType1 = new DrinkType();
|
||||
$drinkType1->setName('Drink 1');
|
||||
$drinkType1->setWantedStock(10);
|
||||
$em->persist($drinkType1);
|
||||
$em->flush();
|
||||
|
||||
// Create second drink type
|
||||
$drinkType2 = new DrinkType();
|
||||
$drinkType2->setName('Drink 2');
|
||||
$drinkType2->setWantedStock(20);
|
||||
$em->persist($drinkType2);
|
||||
$em->flush();
|
||||
|
||||
// Get history for first drink type
|
||||
$getWantedHistory = $this->getContainer()->get(GetWantedHistory::class);
|
||||
$result = $getWantedHistory($drinkType1);
|
||||
|
||||
// Verify we only get logs for the first drink type
|
||||
expect($result)->toHaveCount(1);
|
||||
expect($result[0]->getEntityId())->toBe($drinkType1->getId());
|
||||
expect($result[0]->getNewValue())->toBe('10');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue