This commit is contained in:
lubiana 2025-06-09 19:56:08 +02:00
parent 66c4c1fe4f
commit 2c2e34b71e
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
42 changed files with 910 additions and 939 deletions

View file

@ -1,17 +1,17 @@
<?php
declare(strict_types=1);
use App\Entity\DrinkType;
use App\Entity\Order;
use App\Entity\OrderItem;
use App\Enum\OrderStatus;
use App\Repository\DrinkTypeRepository;
use App\Repository\OrderItemRepository;
use App\Repository\OrderRepository;
use App\Service\InventoryService;
use App\Service\OrderService;
use Doctrine\ORM\EntityManagerInterface;
test('getAllOrders returns all orders', function () {
test('getAllOrders returns all orders', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
@ -22,7 +22,7 @@ test('getAllOrders returns all orders', function () {
expect($orders)->toBeArray();
});
test('getOrderById returns correct order', function () {
test('getOrderById returns correct order', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -43,7 +43,7 @@ test('getOrderById returns correct order', function () {
expect($retrievedOrder->getId())->toBe($id);
});
test('getOrderById returns null for non-existent id', function () {
test('getOrderById returns null for non-existent id', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$nonExistentId = 9999;
@ -55,7 +55,7 @@ test('getOrderById returns null for non-existent id', function () {
expect($order)->toBeNull();
});
test('getOrdersByStatus returns orders with specific status', function () {
test('getOrdersByStatus returns orders with specific status', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -95,7 +95,7 @@ test('getOrdersByStatus returns orders with specific status', function () {
}
});
test('getActiveOrders returns orders with active statuses', function () {
test('getActiveOrders returns orders with active statuses', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -130,7 +130,7 @@ test('getActiveOrders returns orders with active statuses', function () {
}
});
test('getMostRecentActiveOrder returns most recent active order', function () {
test('getMostRecentActiveOrder returns most recent active order', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -158,7 +158,7 @@ test('getMostRecentActiveOrder returns most recent active order', function () {
expect($recentOrder->getId())->toBe($order2->getId());
});
test('hasActiveOrders returns true when active orders exist', function () {
test('hasActiveOrders returns true when active orders exist', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -176,7 +176,7 @@ test('hasActiveOrders returns true when active orders exist', function () {
expect($hasActiveOrders)->toBeTrue();
});
test('getOrdersByDateRange returns orders within date range', function () {
test('getOrdersByDateRange returns orders within date range', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -204,7 +204,7 @@ test('getOrdersByDateRange returns orders within date range', function () {
}
});
test('createOrder creates new order with items', function () {
test('createOrder creates new order with items', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -222,8 +222,14 @@ test('createOrder creates new order with items', function () {
$em->flush();
$items = [
['drinkTypeId' => $drinkType1->getId(), 'quantity' => 3],
['drinkTypeId' => $drinkType2->getId(), 'quantity' => 2],
[
'drinkTypeId' => $drinkType1->getId(),
'quantity' => 3,
],
[
'drinkTypeId' => $drinkType2->getId(),
'quantity' => 2,
],
];
// Act
@ -241,7 +247,7 @@ test('createOrder creates new order with items', function () {
expect($orderItems[1]->getQuantity())->toBe(2);
});
test('createOrderFromStockLevels creates order based on stock levels', function () {
test('createOrderFromStockLevels creates order based on stock levels', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$inventoryService = $this->getContainer()->get(InventoryService::class);
@ -295,7 +301,7 @@ test('createOrderFromStockLevels creates order based on stock levels', function
}
});
test('updateOrderStatus updates order status', function () {
test('updateOrderStatus updates order status', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -316,7 +322,7 @@ test('updateOrderStatus updates order status', function () {
// Verify the status was updated in the database
});
test('addOrderItem adds item to order', function () {
test('addOrderItem adds item to order', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -348,7 +354,7 @@ test('addOrderItem adds item to order', function () {
expect($order->getOrderItems()->contains($orderItem))->toBeTrue();
});
test('addOrderItem updates quantity if item already exists', function () {
test('addOrderItem updates quantity if item already exists', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -380,12 +386,12 @@ test('addOrderItem updates quantity if item already exists', function () {
// Verify the order still has only one item for this drink type
$matchingItems = $order->getOrderItems()->filter(
fn($item) => $item->getDrinkType()->getId() === $drinkType->getId()
fn($item): bool => $item->getDrinkType()->getId() === $drinkType->getId()
);
expect($matchingItems->count())->toBe(1);
});
test('removeOrderItem removes item from order', function () {
test('removeOrderItem removes item from order', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);
@ -414,12 +420,12 @@ test('removeOrderItem removes item from order', function () {
// Verify the item was removed from the database
$em->refresh($order);
$matchingItems = $order->getOrderItems()->filter(
fn($item) => $item->getDrinkType()->getId() === $drinkType->getId()
fn($item): bool => $item->getDrinkType()->getId() === $drinkType->getId()
);
expect($matchingItems->count())->toBe(0);
});
test('deleteOrder removes order and its items', function () {
test('deleteOrder removes order and its items', function (): void {
// Arrange
$orderService = $this->getContainer()->get(OrderService::class);
$em = $this->getContainer()->get(EntityManagerInterface::class);