Skip to content

Commit

Permalink
upd: ApiPlatformTestCase & doc
Browse files Browse the repository at this point in the history
  • Loading branch information
j-schumann committed May 11, 2024
1 parent 99542ab commit 0c597de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,21 @@ asserts this number of messages to be dispatched to the message bus
<tr>
<td>dispatchedMessages</td>
<td>
array of message classes, asserts that at least one instance of each given class
has been dispatched to the message bus
Array of message classes, asserts that at least one instance of each given class
has been dispatched to the message bus. An Element can also be an array of
[FQCN, callable], in that case the callback is called for each matching message
with that message as first parameter and the JSON response as second parameter,
to trigger additional assertions for the message.
</td>
<td>

```php
'dispatchedMessages' => [
TenantCreatedMessage::class,

[TenantCreatedMessage::class, function (object $message, array $data): void {
self::assertSame($data['id'], $message->tenantId);
}]
],
```

Expand Down
8 changes: 6 additions & 2 deletions src/PHPUnit/ApiPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ abstract class ApiPlatformTestCase extends ApiTestCase
public const HYDRA_PROBLEM_403 = [
'@id' => '/errors/403',
'@type' => 'hydra:Error',
'hydra:description' => '@todo',
// 'hydra:description' => '', // varies
'hydra:title' => 'An error occurred',
] + self::PROBLEM_403;
public const HYDRA_PROBLEM_ACCESS_DENIED = [
Expand Down Expand Up @@ -211,7 +211,11 @@ abstract class ApiPlatformTestCase extends ApiTestCase
* messageCount: asserts this number of messages to be dispatched
* to the message bus
* dispatchedMessages: array of message classes, asserts that at least one instance
* of each given class has been dispatched to the message bus
* of each given class has been dispatched to the message bus.
* Instead of class names the elements can be an array of
* [classname, callable]. This callback will be called
* (for each matching message) with the message as first
* parameter and the returned JSON as second parameter.
* skipRefresh: if true the database will not be refreshed before
* the operation, to allow calling testOperation()
* multiple times after each other in one testcase
Expand Down

0 comments on commit 0c597de

Please sign in to comment.