futtern/tests/Entity/FoodVendorTest.php

64 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2024-08-16 11:44:16 +00:00
<?php declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Uid\Ulid;
final class FoodVendorTest extends TestCase
{
public function testFoodVendor(): void
{
$vendor = new FoodVendor;
$vendor->setName('Test');
$this->assertEquals('Test', $vendor->getName());
$this->assertInstanceOf(Ulid::class, $vendor->getId());
$this->assertCount(0, $vendor->getFoodOrders());
$order1 = new FoodOrder;
$vendor->addFoodOrder($order1);
$vendor->addFoodOrder($order1);
$this->assertCount(1, $vendor->getFoodOrders());
2024-09-15 20:11:42 +00:00
$this->assertSame($vendor, $order1->getFoodVendor());
2024-08-16 11:44:16 +00:00
$vendor->removeFoodOrder($order1);
$this->assertCount(0, $vendor->getFoodOrders());
2024-09-15 20:11:42 +00:00
$this->assertNull($order1->getFoodVendor());
2024-08-16 11:44:16 +00:00
2024-09-15 20:11:42 +00:00
}
public function testMenuItem(): void
{
$vendor = new FoodVendor;
2024-08-16 11:44:16 +00: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 20:11:42 +00:00
$this->assertNull($menuItem1->getFoodVendor());
2024-08-16 11:44:16 +00:00
$vendor->addMenuItem($menuItem1);
$menuItem2->delete();
$vendor->addMenuItem($menuItem2);
$this->assertCount(1, $vendor->getMenuItems());
$this->assertCount(2, $vendor->getMenuItems(true));
2024-09-15 20:11:42 +00:00
}
public function testRemoveForeignMenuItem(): void
{
$vendor1 = new FoodVendor;
$vendor2 = new FoodVendor;
$item1 = new MenuItem;
2024-08-16 11:44:16 +00:00
2024-09-15 20:11:42 +00:00
$vendor1->addMenuItem($item1);
$this->assertCount(1, $vendor1->getMenuItems());
$vendor2->removeMenuItem($item1);
$this->assertCount(1, $vendor1->getMenuItems());
$this->assertSame($vendor1, $item1->getFoodVendor());
2024-08-16 11:44:16 +00:00
}
}