improve unit tests
All checks were successful
/ ls (pull_request) Successful in 2m32s

This commit is contained in:
Jonas 2024-12-19 00:35:23 +01:00
parent a974688872
commit cb1ab0ed18
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk

View file

@ -137,10 +137,10 @@ final class FoodOrderControllerTest extends DbWebTest
} }
/** /**
* @testWith [1, 0, 1] * @testWith [1, 0, 2]
* [2, 1, 1] * [2, 1, 3]
* [3, 1, 1] * [3, 2, 4]
* [4, 1, 0, 5] * [4, 3, 0, 5]
*/ */
public function testPaginatedFirstPage(int $page, int $prevPage, int $nextPage, int $items = 10): void public function testPaginatedFirstPage(int $page, int $prevPage, int $nextPage, int $items = 10): void
{ {
@ -154,22 +154,27 @@ final class FoodOrderControllerTest extends DbWebTest
$items, $items,
'nobody' 'nobody'
); );
$this->assertElementContainsCount( if ($prevPage > 0) {
$crawler, if ($prevPage === 1) {
'a', $prevPage = '';
$nextPage, } else {
'next page' $prevPage = "/{$prevPage}";
); }
$this->assertElementContainsCount(
$crawler, $node = $crawler->filter('a')->reduce(fn(Crawler $node, $i): bool => $node->text() === 'previous page')->first();
'a', $target = $node->attr('href');
$prevPage, $this->assertTrue(str_ends_with($target, $prevPage));
'previous page' }
); if ($prevPage > 3) {
$node = $crawler->filter('a')->reduce(fn(Crawler $node, $i): bool => $node->text() === 'next page')->first();
$target = $node->attr('href');
$this->assertTrue(str_ends_with($target, "/{$nextPage}"));
}
} }
public function testNew(): void public function testNew(): void
{ {
$this->client->getCookieJar()->set(new \Symfony\Component\BrowserKit\Cookie('username', 'Testing-1'));
$this->client->request('GET', sprintf('%snew', $this->path)); $this->client->request('GET', sprintf('%snew', $this->path));
self::assertResponseStatusCodeSame(200); self::assertResponseStatusCodeSame(200);
@ -180,6 +185,8 @@ final class FoodOrderControllerTest extends DbWebTest
self::assertResponseRedirects("{$this->path}list"); self::assertResponseRedirects("{$this->path}list");
self::assertSame(1, $this->repository->count([])); self::assertSame(1, $this->repository->count([]));
$order = $this->repository->findOneBy(['createdBy' => 'Testing-1']);
assert($order instanceof FoodOrder);
} }
public function testOpen(): void public function testOpen(): void