improve test coverage
All checks were successful
/ ls (pull_request) Successful in 39s

This commit is contained in:
Jonas 2024-08-16 11:14:41 +02:00
parent a4f62868fd
commit 6f23c3c1b7
Signed by: lubiana
SSH key fingerprint: SHA256:gkqM8DUX4Blf6P52fycW8ISTd+4eAHH+Uzu9iyc8hAM
3 changed files with 132 additions and 2 deletions

View file

@ -58,7 +58,7 @@ class FoodOrder
return $this->closedAt;
}
public function setClosedAt(DateTimeImmutable|null $closedAt): static
public function setClosedAt(DateTimeImmutable|null $closedAt = null): static
{
$this->closedAt = $closedAt;
@ -67,7 +67,15 @@ class FoodOrder
public function isClosed(): bool
{
return $this->closedAt instanceof DateTimeImmutable && $this->closedAt->getTimestamp() <= (new DateTimeImmutable)->getTimestamp();
if ($this->closedAt === null) {
return false;
}
if ($this->closedAt < new DateTimeImmutable) {
return true;
}
return false;
}
public function close(): static

View file

@ -182,6 +182,40 @@ final class FoodOrderControllerTest extends DbWebTest
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
{
foreach (range(1, 35) as $i) {

View file

@ -63,6 +63,23 @@ final class OrderItemControllerTest extends DbWebTest
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
{
$this->client->request(
@ -101,6 +118,26 @@ final class OrderItemControllerTest extends DbWebTest
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
{
$orderItem = new OrderItem;
@ -124,6 +161,35 @@ final class OrderItemControllerTest extends DbWebTest
'My Extra',
$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();
$crawler = $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
@ -150,6 +216,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]
public function getEntityClass(): string
{