Compare commits
2 commits
a4f62868fd
...
2a28465626
Author | SHA1 | Date | |
---|---|---|---|
2a28465626 | |||
6f23c3c1b7 |
3 changed files with 126 additions and 2 deletions
|
@ -58,7 +58,7 @@ class FoodOrder
|
||||||
return $this->closedAt;
|
return $this->closedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setClosedAt(DateTimeImmutable|null $closedAt): static
|
public function setClosedAt(DateTimeImmutable|null $closedAt = null): static
|
||||||
{
|
{
|
||||||
$this->closedAt = $closedAt;
|
$this->closedAt = $closedAt;
|
||||||
|
|
||||||
|
@ -67,7 +67,10 @@ class FoodOrder
|
||||||
|
|
||||||
public function isClosed(): bool
|
public function isClosed(): bool
|
||||||
{
|
{
|
||||||
return $this->closedAt instanceof DateTimeImmutable && $this->closedAt->getTimestamp() <= (new DateTimeImmutable)->getTimestamp();
|
if (! $this->closedAt instanceof DateTimeImmutable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $this->closedAt < new DateTimeImmutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(): static
|
public function close(): static
|
||||||
|
|
|
@ -182,6 +182,38 @@ final class FoodOrderControllerTest extends DbWebTest
|
||||||
self::assertSame(1, $this->repository->count([]));
|
self::assertSame(1, $this->repository->count([]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testOpen(): void
|
||||||
|
{
|
||||||
|
$order = new FoodOrder;
|
||||||
|
$order->setFoodVendor($this->vendor);
|
||||||
|
$order->close();
|
||||||
|
|
||||||
|
$this->assertTrue($order->isClosed());
|
||||||
|
$this->manager->persist($order);
|
||||||
|
$this->manager->flush();
|
||||||
|
|
||||||
|
$this->client->request('GET', sprintf('%s%s/open', $this->path, $order->getId()));
|
||||||
|
self::assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||||
|
$openOrder = $this->repository->find($order->getId());
|
||||||
|
$this->assertFalse($openOrder->isClosed());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClose(): void
|
||||||
|
{
|
||||||
|
$order = new FoodOrder;
|
||||||
|
$order->setClosedAt();
|
||||||
|
$order->setFoodVendor($this->vendor);
|
||||||
|
|
||||||
|
$this->assertFalse($order->isClosed());
|
||||||
|
$this->manager->persist($order);
|
||||||
|
$this->manager->flush();
|
||||||
|
|
||||||
|
$this->client->request('GET', sprintf('%s%s/close', $this->path, $order->getId()));
|
||||||
|
self::assertResponseRedirects("{$this->path}{$order->getId()}");
|
||||||
|
$openOrder = $this->repository->find($order->getId());
|
||||||
|
$this->assertTrue($openOrder->isClosed());
|
||||||
|
}
|
||||||
|
|
||||||
private function generatePaginatedOrders(): void
|
private function generatePaginatedOrders(): void
|
||||||
{
|
{
|
||||||
foreach (range(1, 35) as $i) {
|
foreach (range(1, 35) as $i) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ use App\Entity\MenuItem;
|
||||||
use App\Entity\OrderItem;
|
use App\Entity\OrderItem;
|
||||||
use App\Repository\MenuItemRepository;
|
use App\Repository\MenuItemRepository;
|
||||||
use App\Tests\DbWebTest;
|
use App\Tests\DbWebTest;
|
||||||
|
use DateTimeImmutable;
|
||||||
use Override;
|
use Override;
|
||||||
|
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
@ -63,6 +64,23 @@ final class OrderItemControllerTest extends DbWebTest
|
||||||
self::assertSame(1, $this->menuItemRepository->count([]));
|
self::assertSame(1, $this->menuItemRepository->count([]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNewOrderClosed(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->order->setClosedAt(new DateTimeImmutable('-1 Hour'));
|
||||||
|
$this->manager->persist($this->order);
|
||||||
|
$this->manager->flush();
|
||||||
|
|
||||||
|
$this->client->request(
|
||||||
|
'GET',
|
||||||
|
sprintf('%snew/%s', $this->path, $this->order->getId())
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||||
|
|
||||||
|
self::assertSame(0, $this->repository->count([]));
|
||||||
|
}
|
||||||
|
|
||||||
public function testNewCreateMenuItem(): void
|
public function testNewCreateMenuItem(): void
|
||||||
{
|
{
|
||||||
$this->client->request(
|
$this->client->request(
|
||||||
|
@ -101,6 +119,26 @@ final class OrderItemControllerTest extends DbWebTest
|
||||||
self::assertSame(0, $this->repository->count([]));
|
self::assertSame(0, $this->repository->count([]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testOrderClosed(): void
|
||||||
|
{
|
||||||
|
$fixture = new OrderItem;
|
||||||
|
$fixture->setName('Testing');
|
||||||
|
$fixture->setExtras('Value');
|
||||||
|
$fixture->setMenuItem($this->menuItem);
|
||||||
|
$fixture->setFoodOrder($this->order);
|
||||||
|
|
||||||
|
$this->order->close();
|
||||||
|
|
||||||
|
$this->manager->persist($this->order);
|
||||||
|
$this->manager->persist($fixture);
|
||||||
|
$this->manager->flush();
|
||||||
|
|
||||||
|
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
|
||||||
|
|
||||||
|
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||||
|
self::assertSame(1, $this->repository->count([]));
|
||||||
|
}
|
||||||
|
|
||||||
public function testEdit(): void
|
public function testEdit(): void
|
||||||
{
|
{
|
||||||
$orderItem = new OrderItem;
|
$orderItem = new OrderItem;
|
||||||
|
@ -124,6 +162,35 @@ final class OrderItemControllerTest extends DbWebTest
|
||||||
'My Extra',
|
'My Extra',
|
||||||
$extrasElem->attr('value')
|
$extrasElem->attr('value')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->client->submitForm('Update', [
|
||||||
|
'order_item[name]' => 'Testing-1',
|
||||||
|
'order_item[extras]' => 'Testing-1',
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||||
|
|
||||||
|
self::assertSame(1, $this->repository->count([]));
|
||||||
|
self::assertSame(2, $this->menuItemRepository->count([]));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEditOrderClosed(): void
|
||||||
|
{
|
||||||
|
$orderItem = new OrderItem;
|
||||||
|
$orderItem->setName('Testing');
|
||||||
|
$orderItem->setExtras('My Extra');
|
||||||
|
$orderItem->setFoodOrder($this->order);
|
||||||
|
$orderItem->setMenuItem($this->menuItem);
|
||||||
|
|
||||||
|
$this->order->close();
|
||||||
|
|
||||||
|
$this->manager->persist($orderItem);
|
||||||
|
$this->manager->persist($this->order);
|
||||||
|
$this->manager->flush();
|
||||||
|
|
||||||
|
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $orderItem->getId()));
|
||||||
|
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCopy(): void
|
public function testCopy(): void
|
||||||
|
@ -150,6 +217,28 @@ final class OrderItemControllerTest extends DbWebTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCopyOrderClosed(): void
|
||||||
|
{
|
||||||
|
$orderItem = new OrderItem;
|
||||||
|
$orderItem->setName('My Title');
|
||||||
|
$orderItem->setExtras('My Title');
|
||||||
|
$orderItem->setFoodOrder($this->order);
|
||||||
|
$orderItem->setMenuItem($this->menuItem);
|
||||||
|
|
||||||
|
$this->order->close();
|
||||||
|
$this->manager->persist($this->order);
|
||||||
|
$this->manager->persist($orderItem);
|
||||||
|
$this->manager->flush();
|
||||||
|
|
||||||
|
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
|
||||||
|
self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
|
||||||
|
|
||||||
|
$result = $this->repository->findBy([
|
||||||
|
'foodOrder' => $this->order->getId(),
|
||||||
|
]);
|
||||||
|
$this->assertCount(1, $result);
|
||||||
|
}
|
||||||
|
|
||||||
#[Override]
|
#[Override]
|
||||||
public function getEntityClass(): string
|
public function getEntityClass(): string
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue