Compare commits
No commits in common. "25b73e7da5b507837137408bf6ac00e99066c59b" and "add36313762544efcf2a29e8695c0d261e341ddb" have entirely different histories.
25b73e7da5
...
add3631376
3 changed files with 1 additions and 84 deletions
|
@ -11,8 +11,6 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Bridge\Doctrine\Types\UlidType;
|
use Symfony\Bridge\Doctrine\Types\UlidType;
|
||||||
use Symfony\Component\Uid\Ulid;
|
use Symfony\Component\Uid\Ulid;
|
||||||
|
|
||||||
use function iterator_to_array;
|
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
|
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
|
||||||
class FoodOrder
|
class FoodOrder
|
||||||
{
|
{
|
||||||
|
@ -101,23 +99,6 @@ class FoodOrder
|
||||||
return $this->orderItems;
|
return $this->orderItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection<int, OrderItem>
|
|
||||||
*/
|
|
||||||
public function getOrderItemsSortedByName(): Collection
|
|
||||||
{
|
|
||||||
$iterator = $this->getOrderItems()
|
|
||||||
->getIterator();
|
|
||||||
$iterator->uasort(
|
|
||||||
static fn(OrderItem $a, OrderItem $b): int => $a->getName() <=> $b->getName()
|
|
||||||
);
|
|
||||||
return new ArrayCollection(
|
|
||||||
iterator_to_array(
|
|
||||||
$iterator
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addOrderItem(OrderItem $orderItem): static
|
public function addOrderItem(OrderItem $orderItem): static
|
||||||
{
|
{
|
||||||
if (! $this->orderItems->contains($orderItem)) {
|
if (! $this->orderItems->contains($orderItem)) {
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for item in food_order.orderItemsSortedByName %}
|
{% for item in food_order.orderItems %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ item.createdBy }}</td>
|
<td>{{ item.createdBy }}</td>
|
||||||
<td>{{ item.name }}</td>
|
<td>{{ item.name }}</td>
|
||||||
|
|
|
@ -4,8 +4,6 @@ namespace App\Tests\Controller;
|
||||||
|
|
||||||
use App\Entity\FoodOrder;
|
use App\Entity\FoodOrder;
|
||||||
use App\Entity\FoodVendor;
|
use App\Entity\FoodVendor;
|
||||||
use App\Entity\MenuItem;
|
|
||||||
use App\Entity\OrderItem;
|
|
||||||
use App\Tests\DbWebTest;
|
use App\Tests\DbWebTest;
|
||||||
use Override;
|
use Override;
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
@ -54,68 +52,6 @@ final class FoodOrderControllerTest extends DbWebTest
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOrderedItems(): void
|
|
||||||
{
|
|
||||||
$order = new FoodOrder;
|
|
||||||
$order->setFoodVendor($this->vendor);
|
|
||||||
|
|
||||||
$this->manager->persist($order);
|
|
||||||
$this->manager->persist($this->vendor);
|
|
||||||
|
|
||||||
$menuItemA = new MenuItem;
|
|
||||||
$menuItemA->setName('A');
|
|
||||||
$menuItemA->setFoodVendor($this->vendor);
|
|
||||||
|
|
||||||
$this->manager->persist($menuItemA);
|
|
||||||
$itemA = new OrderItem;
|
|
||||||
$itemA->setMenuItem($menuItemA);
|
|
||||||
$itemA->setName($menuItemA->getName());
|
|
||||||
|
|
||||||
$order->addOrderItem($itemA);
|
|
||||||
$this->manager->persist($itemA);
|
|
||||||
|
|
||||||
$menuItemC = new MenuItem;
|
|
||||||
$menuItemC->setName('C');
|
|
||||||
$menuItemC->setFoodVendor($this->vendor);
|
|
||||||
|
|
||||||
$this->manager->persist($menuItemC);
|
|
||||||
$itemC = new OrderItem;
|
|
||||||
$itemC->setMenuItem($menuItemC);
|
|
||||||
$itemC->setName($menuItemC->getName());
|
|
||||||
|
|
||||||
$order->addOrderItem($itemC);
|
|
||||||
$this->manager->persist($itemC);
|
|
||||||
|
|
||||||
$menuItemB = new MenuItem;
|
|
||||||
$menuItemB->setName('B');
|
|
||||||
$menuItemB->setFoodVendor($this->vendor);
|
|
||||||
|
|
||||||
$this->manager->persist($menuItemB);
|
|
||||||
$itemB = new OrderItem;
|
|
||||||
$itemB->setMenuItem($menuItemB);
|
|
||||||
$itemB->setName($menuItemB->getName());
|
|
||||||
|
|
||||||
$order->addOrderItem($itemB);
|
|
||||||
$this->manager->persist($itemB);
|
|
||||||
|
|
||||||
$this->manager->flush();
|
|
||||||
|
|
||||||
$crawler = $this->client->request('GET', "{$this->path}{$order->getId()}");
|
|
||||||
self::assertResponseIsSuccessful();
|
|
||||||
$tdContent = $crawler->filter(
|
|
||||||
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)'
|
|
||||||
)->text();
|
|
||||||
$this->assertEquals('A', $tdContent);
|
|
||||||
$tdContent = $crawler->filter(
|
|
||||||
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(2) > td:nth-child(2)'
|
|
||||||
)->text();
|
|
||||||
$this->assertEquals('B', $tdContent);
|
|
||||||
$tdContent = $crawler->filter(
|
|
||||||
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(3) > td:nth-child(2)'
|
|
||||||
)->text();
|
|
||||||
$this->assertEquals('C', $tdContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPaginatedIndex(): void
|
public function testPaginatedIndex(): void
|
||||||
{
|
{
|
||||||
$this->generatePaginatedOrders();
|
$this->generatePaginatedOrders();
|
||||||
|
|
Loading…
Reference in a new issue