You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optionally, you can install [JSON Schema for PHP](https://github.com/justinrainbow/json-schema) if you want to use the [JSON Schema](https://json-schema.org) test assertions provided by API Platform:
160
182
161
183
```console
@@ -175,15 +197,20 @@ namespace App\Tests;
175
197
176
198
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
177
199
use App\Entity\Book;
178
-
use Hautelook\AliceBundle\PhpUnit\RefreshDatabaseTrait;
200
+
use App\Factory\BookFactory;
201
+
use Zenstruck\Foundry\Test\Factories;
202
+
use Zenstruck\Foundry\Test\ResetDatabase;
179
203
180
204
class BooksTest extends ApiTestCase
181
205
{
182
-
// This trait provided by AliceBundle will take care of refreshing the database content to a known state before each test
183
-
use RefreshDatabaseTrait;
206
+
// This trait provided by Foundry will take care of refreshing the database content to a known state before each test
207
+
use ResetDatabase, Factories;
184
208
185
209
public function testGetCollection(): void
186
210
{
211
+
// Create 100 books using our factory
212
+
BookFactory::createMany(100);
213
+
187
214
// The client implements Symfony HttpClient's `HttpClientInterface`, and the response `ResponseInterface`
As you can see, the example uses the [trait `RefreshDatabaseTrait`](https://github.com/theofidry/AliceBundle#database-testing)
311
-
from [AliceBundle](https://github.com/theofidry/AliceBundle) which will, at the beginning of each
312
-
test, purge the database, load fixtures, begin a transaction, and, at the end of each test, roll back the
337
+
As you can see, the example uses the [trait `ResetDatabase`](https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#database-reset)
338
+
from [Foundry](https://github.com/zenstruck/foundry) which will, at the beginning of each
339
+
test, purge the database, begin a transaction, and, at the end of each test, roll back the
313
340
transaction previously begun. Because of this, you can run your tests without worrying about fixtures.
314
341
315
342
There is one caveat though: in some tests, it is necessary to perform multiple requests in one test, for example when creating a user via the API and checking that a subsequent login using the same password works. However, the client will by default reboot the kernel, which will reset the database. You can prevent this by adding `$client->disableReboot();` to such tests.
0 commit comments