Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpFoundation] Add SessionHasFlashMessage test constraint#60008

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Pierstoval wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromPierstoval:session-flashbag-assertion

Conversation

Pierstoval
Copy link
Contributor

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
LicenseMIT

Eases the checks on the Session, to avoid the user having to do the checks themselves.

Before:

$request =$client->getRequest();self::assertTrue($request->hasSession());$session =$request->getSession();self::assertInstanceOf(FlashBagAwareSessionInterface::class,$session);$flashbag =$session->getFlashBag();self::assertContains($message,$flashbag->peek($messageType));

After:

self::assertSessionHasFlashMessage($messageType,$message);

{
public function __construct(
private readonly string $messageType,
private readonly string $message,
Copy link
Contributor

Choose a reason for hiding this comment

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

A message can be of any type (technically)https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php#L31

For thematches() part this should use the Constraint comparator.

Copy link
Contributor

Choose a reason for hiding this comment

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

A message is a string. The methodset allows an array of strings. This constraint constructor looks good to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad, referenced the wrong method.https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php#L26

/**     * Adds a flash message for the given type.     */publicfunction add(string$type,mixed$message):void;

https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php#L83 (set() method implementation).

Theset() method allows to set multiple messages for a type, but the type of a$message is mixed.
As it can also contain a Translatable object (Which I use in some projects), as long as there is a way to serialize the value, anything goes.

Copy link
Contributor

@SpomkySpomkyApr 18, 2025
edited
Loading

Choose a reason for hiding this comment

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

Indeed, if a string is the common type for messages, nothing prevent from using anything else.
I foundthis thread where it is suggested to use aMarkup object as message. Also, we can imagine that a Translatable object is used as well.
@Pierstoval would you mind to relax the message type?

Copy link
Contributor

@SpomkySpomky left a comment

Choose a reason for hiding this comment

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

Many thanks.
No specific remarks for this PR.
👍

{
public function __construct(
private readonly string $messageType,
private readonly string $message,
Copy link
Contributor

Choose a reason for hiding this comment

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

A message is a string. The methodset allows an array of strings. This constraint constructor looks good to me.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sstoksstoksstok left review comments

@SpomkySpomkyAwaiting requested review from Spomky

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

5 participants
@Pierstoval@sstok@Spomky@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp