Skip to content

[FrameworkBundle] PhpUnit assert Messenger #51964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 7.4
Choose a base branch
from

Conversation

marilenaRM
Copy link

@marilenaRM marilenaRM commented Oct 10, 2023

Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT

Hello,
This MessengerAssertionTrait is a Helper for those who want to be able to test the dispatched messages while working with Messenger.

$this->assertMessagesByBusCount(6);  //no busName = total count
$this->assertMessagesByBusCount(2, 'event.bus');
$this->assertMessagesByBusCount(4, 'query.bus');
$this->assertMessagesOfClassCount(2, DummyCommand::class);
$this->assertMessagesOfClassCount(3, DummyQuery::class);
$this->assertMessagesOfClassCount(1, DummyMessage::class);


/** @var DummyMessage[] $dummyMessages */
$dummyMessages = $this::getDispatchedMessagesByClassName(DummyMessage::class);
self::assertCount(1, $dummyMessages);
self::assertStringContainsString('dummy message text', $dummyMessages[0]->getMessage());

$messagesFromQueryBus = $this::getDispatchedMessagesByBusName('query.bus');
self::assertCount(4, $messagesFromQueryBus);

self::assertInstanceOf(DummyMessage::class, $messagesFromQueryBus[0]);

/** @var DummyQuery $firstQuery */
self::assertInstanceOf(DummyQuery::class, $firstQuery = $messagesFromQueryBus[1]);
self::assertStringContainsString('First Dummy Query message', $firstQuery->getMessage());

Hope this helps!
Regards,
Marilena Ruffelaere

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@marilenaRM marilenaRM force-pushed the feature/Add-Messenger-Assertion-Trait branch from 4fa419f to 35def9d Compare October 10, 2023 09:29
@stof
Copy link
Member

stof commented Oct 10, 2023

Labelling the PR as PhpUnitBridge is wrong as this adds the feature in FrameworkBundle.

@marilenaRM marilenaRM changed the title [PhpUnitBridge] PhpUnit assert Messenger [FrameworkBundle] PhpUnit assert Messenger Oct 10, 2023
@marilenaRM marilenaRM force-pushed the feature/Add-Messenger-Assertion-Trait branch 2 times, most recently from 34956ed to fbaeb1c Compare October 10, 2023 09:46
@marilenaRM marilenaRM force-pushed the feature/Add-Messenger-Assertion-Trait branch from fbaeb1c to 324586c Compare October 10, 2023 09:49
@marilenaRM marilenaRM force-pushed the feature/Add-Messenger-Assertion-Trait branch 3 times, most recently from 09e6f34 to 0398f6e Compare October 12, 2023 09:10
* @param string|null $busName The busName to consider
* @param string|null $messageFQCN The message object class name to consider
*/
public static function assertMessagesCount(int $count, string $busName = null, string $messageFQCN = null, string $message = ''): void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very small suggestion : I think assetMessageCount (without the 's') would be more 'correct' 😃

@marilenaRM marilenaRM force-pushed the feature/Add-Messenger-Assertion-Trait branch from 0398f6e to a96e01c Compare October 23, 2023 10:28
@marilenaRM marilenaRM force-pushed the feature/Add-Messenger-Assertion-Trait branch from a96e01c to 2ed780c Compare October 23, 2023 11:45
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot fabpot removed this from the 7.3 milestone May 26, 2025
@fabpot fabpot added this to the 7.4 milestone May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants