Add a test for the OpenAPI spec for `/api/layout/{entityTypeId}/{entityId}`.
Open
requested to merge issue/experience_builder-3472632:3472632-approach-for-writing-tests-for-openapi-integration into 0.x
3 unresolved threads
Closes #3472632
Merge request reports
Activity
Filter activity
- Resolved by Travis Carden
- Resolved by Travis Carden
45 $psr7_request = $http_message_factory 46 ->createRequest($request); 47 48 try { 49 $validator->validate($psr7_request); 50 } 51 catch (ValidationFailed $e) { 52 self::fail($e->getMessage()); 53 } 54 55 self::assertTrue(TRUE, 'The request passes OpenAPI validation.'); 56 } 57 58 public static function providerValidRequest(): array { 59 return [ 60 'Post empty component tree' => [ 27 * @param array $files 28 * The request files (`$_FILES`). 29 * @param array $server 30 * The server parameters (`$_SERVER`). 31 * @param string $content 32 * The raw body data. 33 * 34 * @see \Symfony\Component\HttpFoundation\Request::create() 35 * 36 * @dataProvider providerValidRequest 37 */ 38 public function testValidRequest(string $method, array $parameters, array $cookies, array $files, array $server, string $content): void { 39 $validator_builder = self::getConfiguredValidatorBuilder(); 40 $validator = $validator_builder->getRequestValidator(); 41 42 $request = Request::create('api/preview/node/1', $method, $parameters, $cookies, $files, $server, $content); Tiny bug — the class-level docblock said:Tests `/api/layout/{entityTypeId}/{entityId}`.
Edited by Wim Leers
69 'nodeType' => 'root', 70 'name' => 'root', 71 'children' => [], 72 ], 73 'model' => [], 74 ], JSON_THROW_ON_ERROR), 75 ], 76 'Post component tree with single component' => [ 77 'method' => Request::METHOD_POST, 78 'parameters' => [], 79 'cookies' => [], 80 'files' => [], 81 'server' => ['CONTENT_TYPE' => 'application/json'], 82 'content' => json_encode([ 83 'layout' => [ 84 'uuid' => 'root', My #1 concern with this test currently is that it's too server-side-centric.
The goal is that both front-end developers and back-end developers can easily update this.
There are two mitigations I see/proposed:
- consuming the
examples
in/openapi.yml
⇒ people changing only an example in/openapi.yml
without touching a line of PHP get helpful feedback too -
helps only for valid examples (i.e. "the happy path"). For invalid examples, the ability to largely copy/paste JSON blobs without much additional stuff would help a lot too. So just seeing such JSON blobs in the*Test.php
file then sets the stage/example for others to copy/paste and just swap out the blob
- consuming the
Please register or sign in to reply