forked from lubiana/futtern
upidati
This commit is contained in:
parent
314063f15c
commit
937973e8e9
20 changed files with 725 additions and 2221 deletions
|
@ -1,26 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
||||
use ApiPlatform\Symfony\Bundle\Test\Client;
|
||||
use App\DataFixtures\AppFixtures;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
|
||||
use Override;
|
||||
|
||||
abstract class DbApiTestCase extends ApiTestCase
|
||||
{
|
||||
protected EntityManagerInterface $manager;
|
||||
protected Client $client;
|
||||
|
||||
#[Override]
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->client = static::createClient();
|
||||
$this->manager = static::getContainer()->get('doctrine')->getManager();
|
||||
$toolKit = self::getContainer()->get(DatabaseToolCollection::class)->get();
|
||||
$toolKit->loadFixtures([AppFixtures::class]);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
test('orders', function (): void {
|
||||
$response = $this->client->request('GET', '/api/food_orders');
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
||||
$this->assertJsonContains([
|
||||
'@context' => '/api/contexts/FoodOrder',
|
||||
'@id' => '/api/food_orders',
|
||||
'@type' => 'Collection',
|
||||
'totalItems' => 1,
|
||||
]);
|
||||
$array = $response->toArray();
|
||||
expect($array['member'][0]['orderItems'])->toHaveCount(10);
|
||||
});
|
||||
|
||||
test('open orders', function (): void {
|
||||
$response = $this->client->request('GET', '/api/food_orders/open');
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
|
||||
$this->assertJsonContains([
|
||||
'@context' => '/api/contexts/FoodOrder',
|
||||
'@id' => '/api/food_orders/open',
|
||||
'@type' => 'Collection',
|
||||
]);
|
||||
|
||||
// Get the response content and verify that all returned orders are open
|
||||
$array = $response->toArray();
|
||||
|
||||
// If we have no items, we should still have a successful response
|
||||
if ($array['totalItems'] === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// For each order in the response, check that it is not closed
|
||||
foreach ($array['member'] as $order) {
|
||||
// An order is considered open if either:
|
||||
// 1. closedAt is null or
|
||||
// 2. closedAt is in the future
|
||||
$closedAt = isset($order['closedAt']) ? new DateTimeImmutable($order['closedAt']) : null;
|
||||
$now = new DateTimeImmutable;
|
||||
|
||||
// Assert that the order is open (not closed)
|
||||
$isOpen = (! $closedAt instanceof DateTimeImmutable || $closedAt > $now);
|
||||
expect($isOpen)
|
||||
->toBeTrue('Order should be open but is closed');
|
||||
}
|
||||
});
|
|
@ -16,8 +16,6 @@ use App\Tests\DbWebTest;
|
|||
|
||||
pest()
|
||||
->extends(DbWebTest::class)->in('Feature/Controller/*.php');
|
||||
pest()
|
||||
->extends(DbApiTestCase::class)->in('Feature/Api/*.php');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue