Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit ae27a90

Browse files
authored
Merge pull request #17 from eerison/RefreshDatabase
Refresh Database
2 parents a2a2a63 + f83034b commit ae27a90

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ You can install the package via composer:
1111
composer require eerison/pest-plugin-api-platform --dev
1212
```
1313

14+
Add `uses(ApiTestCase::class)` in your `tests/Pest.php`
15+
16+
```php
17+
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
18+
19+
uses(ApiTestCase::class)->beforeEach(fn() => static::bootKernel())->in('Feature');
20+
```
21+
1422
## Usage
1523

1624
```php
@@ -80,6 +88,9 @@ use App\Entity\Book;
8088

8189
class BooksTest extends ApiTestCase
8290
{
91+
// This trait provided by AliceBundle will take care of refreshing the database content to a known state before each test
92+
use RefreshDatabaseTrait;
93+
8394
public function testGetCollection(): void
8495
{
8596
// The client implements Symfony HttpClient's `HttpClientInterface`, and the response `ResponseInterface`
@@ -112,6 +123,9 @@ After
112123

113124
```php
114125
use App\Entity\Book;
126+
use Hautelook\AliceBundle\PhpUnit\RefreshDatabaseTrait;
127+
128+
uses(RefreshDatabaseTrait::class);
115129

116130
it('can get a collection')
117131
->get('/books')

src/Resource.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ public function delete(string $url, array $options = []): TestCase
5555
return $this;
5656
}
5757

58-
public function assertResponseStatusCodeSame(int $statusCode): TestCase
59-
{
60-
ApiPlatform::assertResponseStatusCodeSame($statusCode);
61-
62-
return $this;
63-
}
64-
6558
public function response(): ResponseInterface
6659
{
6760
return $this->response;

src/ResourceShortcuts.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
*/
1515
trait ResourceShortcuts
1616
{
17-
/**
18-
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
19-
*/
20-
public function assertResponseIsSuccessful(): TestCase
21-
{
22-
ApiPlatform::assertResponseIsSuccessful();
23-
24-
return $this;
25-
}
26-
2717
public function assertResourceIsBadRequest(): TestCase
2818
{
2919
test()->assertResponseStatusCodeSame(400);
File renamed without changes.
File renamed without changes.

tests/Pest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
6+
7+
uses(ApiTestCase::class)->beforeEach(fn () => static::bootKernel())->in('Feature');

0 commit comments

Comments
 (0)