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
Copy file name to clipboardExpand all lines: distribution/testing.md
+26-21Lines changed: 26 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,13 +11,11 @@ Let's learn how to use them!
11
11
12
12
In this article you'll learn how to use:
13
13
14
-
*[PHPUnit](https://phpunit.de/index.html), a testing framework to cover your classes with unit tests and to write
14
+
*[PHPUnit](https://phpunit.de), a testing framework to cover your classes with unit tests and to write
15
15
API-oriented functional tests thanks to its API Platform and [Symfony](https://symfony.com/doc/current/testing.html) integrations.
16
16
*[Alice](https://github.com/nelmio/alice) and [its Symfony
17
17
integration](https://github.com/theofidry/AliceBundle#database-testing), an expressive fixtures generator to write data fixtures.
18
18
19
-
Official [Symfony recipes](https://flex.symfony.com/) are provided for both tools.
20
-
21
19
## Creating Data Fixtures
22
20
23
21
Before creating your functional tests, you will need a dataset to pre-populate your API and be able to test it.
@@ -69,17 +67,20 @@ The list of available generators as well as a cookbook explaining how to create
69
67
70
68
## Writing Functional Tests
71
69
72
-
Now that you have some data fixtures for your API, you are ready to write functional tests with [PHPUnit](https://phpunit.de/index.html).
70
+
Now that you have some data fixtures for your API, you are ready to write functional tests with [PHPUnit](https://phpunit.de).
71
+
72
+
The API Platform test client implements the interfaces of the [Symfony HttpClient](https://symfony.com/doc/current/components/http_client.html). HttpClient is shipped with the API Platform distribution. The [Symfony test pack](https://github.com/symfony/test-pack/blob/main/composer.json), which includes PHPUnit as well as Symfony components useful for testing, is also included.
73
73
74
-
Install the Symfony test pack (which includes PHPUnit and [PHPUnit Bridge](https://symfony.com/doc/current/components/phpunit_bridge.html)), [Symfony HttpClient](https://symfony.com/doc/current/components/http_client.html)
75
-
(the API Platform test client is built on top of Symfony HttpClient, and allows to leverage all its features) and [JSON Schema for PHP](https://github.com/justinrainbow/json-schema) (used by API Platform to provide [JSON Schema](https://json-schema.org/) test assertions):
74
+
If you don't use the distribution, run `composer require --dev symfony/test-pack symfony/http-client` to install them.
75
+
76
+
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:
Your API is ready to be functionally tested. Create your test classes under the `tests/` directory.
83
+
Your API is now ready to be functionally tested. Create your test classes under the `tests/` directory.
83
84
84
85
Here is an example of functional tests specifying the behavior of [the bookstore API you created in the tutorial](index.md):
85
86
@@ -245,31 +246,35 @@ Check out the [testing documentation](../core/testing.md) to discover the full r
245
246
## Writing Unit Tests
246
247
247
248
In addition to integration tests written using the helpers provided by `ApiTestCase`, all the classes of your project should be covered by [unit tests](https://en.wikipedia.org/wiki/Unit_testing).
248
-
To do so, learn how to write unit tests with [PHPUnit](https://phpunit.de/index.html) and [its Symfony/API Platform integration](https://symfony.com/doc/current/testing.html).
249
+
To do so, learn how to write unit tests with [PHPUnit](https://phpunit.de/) and [its Symfony/API Platform integration](https://symfony.com/doc/current/testing.html).
250
+
251
+
## Continuous Integration, Continuous Delivery and Continuous Deployment
252
+
253
+
Running your test suite in your [CI/CD pipeline](https://en.wikipedia.org/wiki/Continuous_integration) is important to ensure good quality and delivery time.
254
+
255
+
The API Platform distribution is [shipped with a GitHub Actions workflow](https://github.com/api-platform/api-platform/blob/main/.github/workflows/ci.yml) that builds the Docker images, does a [smoke test](https://en.wikipedia.org/wiki/Smoke_testing_(software)) to check that the application's entrypoint is accessible, and runs PHPUnit.
256
+
257
+
The API Platform Demo [contains a CD worklow](https://github.com/api-platform/demo/tree/main/.github/workflows) that uses [the Helm chart provided with the distribution](../deployment/kubernetes.md) to deploy the app on a Kubernetes cluster.
249
258
250
259
## Additional and Alternative Testing Tools
251
260
252
261
You may also be interested in these alternative testing tools (not included in the API Platform distribution):
253
262
254
-
*[Behat](http://behat.org/en/latest/) and its [Behatch extension](https://github.com/Behatch/contexts), a
263
+
*[Foundry](https://github.com/zenstruck/foundry), a modern fixtures library that will replace Alice as the recommended fixtures library soon;
264
+
*[Hoppscotch](https://docs.hoppscotch.io/features/tests), create functional test for your API
265
+
Platform project using a nice UI, benefit from its Swagger integration and run tests in the CI using [the CLI tool](https://docs.hoppscotch.io/cli);
266
+
*[Behat](http://behat.org), a
255
267
[behavior-driven development (BDD)](https://en.wikipedia.org/wiki/Behavior-driven_development) framework to write the API
256
268
specification as user stories and in natural language then execute these scenarios against the application to validate
257
269
its behavior;
258
270
*[Blackfire Player](https://blackfire.io/player), a nice DSL to crawl HTTP services, assert responses, and extract data
259
-
from HTML/XML/JSON responses ([see example in API Platform Demo](https://github.com/api-platform/demo/blob/master/test-api.bkf));
260
-
*[Postman tests](https://www.getpostman.com/docs/writing_tests) (proprietary), create functional test for your API
261
-
Platform project using a nice UI, benefit from [the Swagger integration](https://www.getpostman.com/docs/importing_swagger)
262
-
and run tests in the CI using [newman](https://github.com/postmanlabs/newman);
271
+
from HTML/XML/JSON responses;
263
272
*[PHP Matcher](https://github.com/coduo/php-matcher), the Swiss Army knife of JSON document testing.
264
273
265
-
## Using the API Platform Distribution for End-to-end Testing
274
+
## Using the API Platform Distribution for End-to-End Testing
266
275
267
276
If you would like to verify that your stack (including services such as the DBMS, web server, [Varnish](https://varnish-cache.org/))
268
-
works, you need [end-to-end (E2E) testing](https://wiki.c2.com/?EndToEndPrinciple).
269
-
270
-
It is also useful to do a [smoke test](https://en.wikipedia.org/wiki/Smoke_testing_(software)) to check that your application
271
-
is working; for example, that the application's entrypoint is accessible. This could be used as a quick test after each
272
-
Docker build to ensure that the Docker images are not broken.
277
+
works, you need [end-to-end (E2E) testing](https://wiki.c2.com/?EndToEndPrinciple). To do so, we recommend using [Playwright](https://playwright.dev) if you use have PWA/JavaScript-heavy app, or [Symfony Panther](https://github.com/symfony/panther) if you mostly use Twig.
273
278
274
-
Usually, this should be done with a production-like setup. For your convenience, you may [run our Docker Compose setup
279
+
Usually, E2E testing should be done with a production-like setup. For your convenience, you may [run our Docker Compose setup
275
280
for production locally](../deployment/docker-compose.md#running-the-docker-compose-setup-for-production-locally).
0 commit comments