This commit is contained in:
parent
83989916a3
commit
25b73e7da5
2 changed files with 15 additions and 5 deletions
|
@ -11,6 +11,8 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -104,9 +106,10 @@ class FoodOrder
|
||||||
*/
|
*/
|
||||||
public function getOrderItemsSortedByName(): Collection
|
public function getOrderItemsSortedByName(): Collection
|
||||||
{
|
{
|
||||||
$iterator = $this->getOrderItems()->getIterator();
|
$iterator = $this->getOrderItems()
|
||||||
|
->getIterator();
|
||||||
$iterator->uasort(
|
$iterator->uasort(
|
||||||
fn (OrderItem $a, OrderItem $b): int => $a->getName() <=> $b->getName()
|
static fn(OrderItem $a, OrderItem $b): int => $a->getName() <=> $b->getName()
|
||||||
);
|
);
|
||||||
return new ArrayCollection(
|
return new ArrayCollection(
|
||||||
iterator_to_array(
|
iterator_to_array(
|
||||||
|
|
|
@ -58,36 +58,43 @@ final class FoodOrderControllerTest extends DbWebTest
|
||||||
{
|
{
|
||||||
$order = new FoodOrder;
|
$order = new FoodOrder;
|
||||||
$order->setFoodVendor($this->vendor);
|
$order->setFoodVendor($this->vendor);
|
||||||
|
|
||||||
$this->manager->persist($order);
|
$this->manager->persist($order);
|
||||||
$this->manager->persist($this->vendor);
|
$this->manager->persist($this->vendor);
|
||||||
|
|
||||||
$menuItemA = new MenuItem();
|
$menuItemA = new MenuItem;
|
||||||
$menuItemA->setName('A');
|
$menuItemA->setName('A');
|
||||||
$menuItemA->setFoodVendor($this->vendor);
|
$menuItemA->setFoodVendor($this->vendor);
|
||||||
|
|
||||||
$this->manager->persist($menuItemA);
|
$this->manager->persist($menuItemA);
|
||||||
$itemA = new OrderItem;
|
$itemA = new OrderItem;
|
||||||
$itemA->setMenuItem($menuItemA);
|
$itemA->setMenuItem($menuItemA);
|
||||||
$itemA->setName($menuItemA->getName());
|
$itemA->setName($menuItemA->getName());
|
||||||
|
|
||||||
$order->addOrderItem($itemA);
|
$order->addOrderItem($itemA);
|
||||||
$this->manager->persist($itemA);
|
$this->manager->persist($itemA);
|
||||||
|
|
||||||
$menuItemC = new MenuItem();
|
$menuItemC = new MenuItem;
|
||||||
$menuItemC->setName('C');
|
$menuItemC->setName('C');
|
||||||
$menuItemC->setFoodVendor($this->vendor);
|
$menuItemC->setFoodVendor($this->vendor);
|
||||||
|
|
||||||
$this->manager->persist($menuItemC);
|
$this->manager->persist($menuItemC);
|
||||||
$itemC = new OrderItem;
|
$itemC = new OrderItem;
|
||||||
$itemC->setMenuItem($menuItemC);
|
$itemC->setMenuItem($menuItemC);
|
||||||
$itemC->setName($menuItemC->getName());
|
$itemC->setName($menuItemC->getName());
|
||||||
|
|
||||||
$order->addOrderItem($itemC);
|
$order->addOrderItem($itemC);
|
||||||
$this->manager->persist($itemC);
|
$this->manager->persist($itemC);
|
||||||
|
|
||||||
$menuItemB = new MenuItem();
|
$menuItemB = new MenuItem;
|
||||||
$menuItemB->setName('B');
|
$menuItemB->setName('B');
|
||||||
$menuItemB->setFoodVendor($this->vendor);
|
$menuItemB->setFoodVendor($this->vendor);
|
||||||
|
|
||||||
$this->manager->persist($menuItemB);
|
$this->manager->persist($menuItemB);
|
||||||
$itemB = new OrderItem;
|
$itemB = new OrderItem;
|
||||||
$itemB->setMenuItem($menuItemB);
|
$itemB->setMenuItem($menuItemB);
|
||||||
$itemB->setName($menuItemB->getName());
|
$itemB->setName($menuItemB->getName());
|
||||||
|
|
||||||
$order->addOrderItem($itemB);
|
$order->addOrderItem($itemB);
|
||||||
$this->manager->persist($itemB);
|
$this->manager->persist($itemB);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue