futtern/tests/Unit/Entity/FoodVendorTest.php

65 lines
2.3 KiB
PHP
Raw Normal View History

2024-08-16 13:44:16 +02:00
<?php declare(strict_types=1);
namespace App\Tests\Unit\Entity;
2024-08-16 13:44:16 +02:00
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use Symfony\Component\Uid\Ulid;
use function describe;
use function test;
describe(FoodVendor::class, function (): void {
test('FoodVendor entity', function (): void {
2024-08-16 13:44:16 +02:00
$vendor = new FoodVendor;
$vendor->setName('Test');
$this->assertEquals('Test', $vendor->getName());
$this->assertInstanceOf(Ulid::class, $vendor->getId());
$this->assertEmpty($vendor->getPhone());
$vendor->setPhone('1234567890');
$this->assertEquals('1234567890', $vendor->getPhone());
2024-08-16 13:44:16 +02:00
$this->assertCount(0, $vendor->getFoodOrders());
$order1 = new FoodOrder;
$vendor->addFoodOrder($order1);
$vendor->addFoodOrder($order1);
$this->assertCount(1, $vendor->getFoodOrders());
2024-09-15 22:11:42 +02:00
$this->assertSame($vendor, $order1->getFoodVendor());
2024-08-16 13:44:16 +02:00
$vendor->removeFoodOrder($order1);
$this->assertCount(0, $vendor->getFoodOrders());
2024-09-15 22:11:42 +02:00
$this->assertNull($order1->getFoodVendor());
});
2024-08-16 13:44:16 +02:00
test('MenutItem entity', function (): void {
2024-09-15 22:11:42 +02:00
$vendor = new FoodVendor;
2024-08-16 13:44:16 +02:00
$menuItem1 = new MenuItem;
$menuItem2 = new MenuItem;
$this->assertCount(0, $vendor->getMenuItems());
$vendor->addMenuItem($menuItem1);
$vendor->addMenuItem($menuItem1);
$this->assertCount(1, $vendor->getMenuItems());
$vendor->removeMenuItem($menuItem1);
$this->assertCount(0, $vendor->getMenuItems());
2024-09-15 22:11:42 +02:00
$this->assertNull($menuItem1->getFoodVendor());
2024-08-16 13:44:16 +02:00
$vendor->addMenuItem($menuItem1);
$menuItem2->delete();
$vendor->addMenuItem($menuItem2);
$this->assertCount(1, $vendor->getMenuItems());
$this->assertCount(2, $vendor->getMenuItems(true));
});
2024-09-15 22:11:42 +02:00
test('remove foreign menu item', function (): void {
2024-09-15 22:11:42 +02:00
$vendor1 = new FoodVendor;
$vendor2 = new FoodVendor;
$item1 = new MenuItem;
2024-08-16 13:44:16 +02:00
2024-09-15 22:11:42 +02:00
$vendor1->addMenuItem($item1);
$this->assertCount(1, $vendor1->getMenuItems());
$vendor2->removeMenuItem($item1);
$this->assertCount(1, $vendor1->getMenuItems());
$this->assertSame($vendor1, $item1->getFoodVendor());
});
})->covers(FoodVendor::class, FoodOrder::class, MenuItem::class);