add simple apitest
This commit is contained in:
parent
d92a63fd7d
commit
b00b923d43
13 changed files with 349 additions and 8 deletions
26
tests/DbApiTestCase.php
Normal file
26
tests/DbApiTestCase.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?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]);
|
||||
}
|
||||
}
|
15
tests/Feature/Api/ApiSmokeTest.php
Normal file
15
tests/Feature/Api/ApiSmokeTest.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?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);
|
||||
});
|
|
@ -1,5 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use App\Tests\DbApiTestCase;
|
||||
use App\Tests\DbWebTest;
|
||||
|
||||
/*
|
||||
|
@ -15,6 +16,8 @@ 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