Skip to content

Commit 8a6ef6d

Browse files
committed
Rename assertMessageCount to seeDispatchedMessageCount
In this module the assert* prefix is reserved for direct ports of Symfony's own test assertions (assertEmailCount, assertResponseIsSuccessful, ...). Messenger has no upstream Symfony web-test assertion, so the count check should follow the module-native see* idiom, matching its Messenger-based siblings (seeEmailIsSent, seeNotificationIsSent). Drop the assert-only $message parameter accordingly and keep the methods in alphabetical order.
1 parent 84577df commit 8a6ef6d

2 files changed

Lines changed: 31 additions & 31 deletions

File tree

src/Codeception/Module/Symfony/MessengerAssertionsTrait.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,6 @@
1515

1616
trait MessengerAssertionsTrait
1717
{
18-
/**
19-
* Asserts that the given number of messages were dispatched through the Messenger buses.
20-
* Optionally pass a bus name (e.g. `messenger.bus.default`) to only count messages dispatched on that bus.
21-
*
22-
* ```php
23-
* <?php
24-
* $I->assertMessageCount(1);
25-
* $I->assertMessageCount(2, 'messenger.bus.default');
26-
* ```
27-
*/
28-
public function assertMessageCount(int $expectedCount, ?string $bus = null, string $message = ''): void
29-
{
30-
$messages = $this->grabMessengerCollector(__FUNCTION__)->getMessages($bus);
31-
32-
$this->assertCount(
33-
$expectedCount,
34-
$messages,
35-
$message !== '' ? $message : sprintf(
36-
'Expected %d message(s) to be dispatched%s, but %d were.',
37-
$expectedCount,
38-
$this->busSuffix($bus),
39-
count($messages),
40-
),
41-
);
42-
}
43-
4418
/**
4519
* Asserts that **no** message of the given class was dispatched through the Messenger buses.
4620
* Optionally restrict the check to a single bus.
@@ -82,6 +56,32 @@ public function grabDispatchedMessageClasses(?string $bus = null): array
8256
return $this->getDispatchedMessageClasses(__FUNCTION__, $bus);
8357
}
8458

59+
/**
60+
* Asserts that the given number of messages were dispatched through the Messenger buses.
61+
* Optionally pass a bus name (e.g. `messenger.bus.default`) to only count messages dispatched on that bus.
62+
*
63+
* ```php
64+
* <?php
65+
* $I->seeDispatchedMessageCount(1);
66+
* $I->seeDispatchedMessageCount(2, 'messenger.bus.default');
67+
* ```
68+
*/
69+
public function seeDispatchedMessageCount(int $expectedCount, ?string $bus = null): void
70+
{
71+
$messages = $this->grabMessengerCollector(__FUNCTION__)->getMessages($bus);
72+
73+
$this->assertCount(
74+
$expectedCount,
75+
$messages,
76+
sprintf(
77+
'Expected %d message(s) to be dispatched%s, but %d were.',
78+
$expectedCount,
79+
$this->busSuffix($bus),
80+
count($messages),
81+
),
82+
);
83+
}
84+
8585
/**
8686
* Asserts that at least one message of the given class was dispatched through the Messenger buses.
8787
* Optionally restrict the check to a single bus.

tests/MessengerAssertionsTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ final class MessengerAssertionsTest extends CodeceptTestCase
1313
{
1414
use MessengerAssertionsTrait;
1515

16-
public function testAssertMessageCount(): void
16+
public function testSeeDispatchedMessageCount(): void
1717
{
1818
$this->client->request('GET', '/dispatch-message');
1919

20-
$this->assertMessageCount(1);
21-
$this->assertMessageCount(1, 'messenger.bus.default');
22-
$this->assertMessageCount(0, 'non.existent.bus');
20+
$this->seeDispatchedMessageCount(1);
21+
$this->seeDispatchedMessageCount(1, 'messenger.bus.default');
22+
$this->seeDispatchedMessageCount(0, 'non.existent.bus');
2323
}
2424

2525
public function testSeeMessageDispatched(): void
@@ -53,7 +53,7 @@ public function testNoMessagesDispatched(): void
5353
{
5454
$this->client->request('GET', '/');
5555

56-
$this->assertMessageCount(0);
56+
$this->seeDispatchedMessageCount(0);
5757
$this->assertSame([], $this->grabDispatchedMessageClasses());
5858
}
5959
}

0 commit comments

Comments
 (0)