Testing

← Testing

Ashterix

docs: rewrite JsonRpcBundle docs, add SDK docs, move them under docs/api

en/docs/api/rest-bundle/developers/testing.md new file +35 −0

1 + # Testing
2 +
3 + How to run the bundle's own tests and how they are organised. Useful if you make changes to REST Bundle.
4 +
5 + ## Running
6 +
7 + ```bash
8 + composer install
9 + vendor/bin/phpunit -c phpunit.xml.dist
10 + vendor/bin/phpunit -c phpunit.xml.dist --filter ErrorResponseTest
11 + ```
12 +
13 + `composer test` and `make test` run PHPUnit (since 1.2). In Docker (`make up-d`, container `php_<PROJECT_NAME>`):
14 +
15 + ```bash
16 + docker exec php_rest vendor/bin/phpunit -c phpunit.xml.dist
17 + ```
18 +
19 + `cebe/php-openapi` emits PHP 8.4 deprecation warnings about implicitly nullable parameters; this is expected.
20 +
21 + ## Structure
22 +
23 + | Directory | Type | What it checks |
24 + | --- | --- | --- |
25 + | `tests/Unit` | no kernel | `RestServiceMap` route rules, `RpcRestRouteLoader`, `RpcFromRest` parameters and type casting, `RestErrorNormalizer` and REST exceptions, listeners, `RestRouteImport`, OpenAPI and Postman builders, `RestBundleExtension`, `Package` |
26 + | `tests/Integration` | container services | `RestRequestParser` (groups, versions, HTTP methods, tokens), listener priorities |
27 + | `tests/Functional` | HTTP through the kernel | routes and aliases of multiple imports, execution, versions, parameters, RFC 9457 errors, documents and translations, security, `rpc.post_response`, coexistence with another `IApiRouteImport` adapter |
28 + | `tests/Fixtures` | | RPC procedures, routes file, translations, a second adapter, an `rpc.post_response` recorder |
29 +
30 + `tests/TestKernel.php` loads FrameworkBundle, SecurityBundle, JsonRpcBundle and this bundle. The kernel cache lives in `<tmp>/ufo-rest-tests`; a test sets `TestKernel::$security` before `bootKernel()` to get a container with a different security configuration. Functional tests extend `FunctionalTestCase` (`send()`, `json()`).
31 +
32 + ## Notes
33 +
34 + * If a test sees a stale container after a quick fixture change, delete `<tmp>/ufo-rest-tests`.
35 + * Add a functional test for any change to routes, statuses, problem documents or documentation: this is the REST contract.