Skip to content

Commit 91dc899

Browse files
committed
feature #50200 [Mailer] Adds assertEmailSubjectContains and assertEmailSubjectNotContains methods (johanadivare)
This PR was merged into the 6.4 branch. Discussion ---------- [Mailer] Adds `assertEmailSubjectContains` and `assertEmailSubjectNotContains` methods > Adds assertEmailSubjectContains and assertEmailSubjectNotContains | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | No | New feature? | yes | Deprecations? | No | Tickets | Fix #49939 | License | MIT | Doc PR | symfony/symfony-docs#18269 <!-- Replace this notice by a short README for your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the latest branch. - For new features, provide some code snippets to help understand usage. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Commits ------- 55ba7b8f22 [Mailer] Add EmailSubjectContains constraint (#49939)
2 parents cbcc242 + 97bd01e commit 91dc899

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mime\Test\Constraint;
13+
14+
use PHPUnit\Framework\Constraint\Constraint;
15+
use Symfony\Component\Mime\Email;
16+
17+
final class EmailSubjectContains extends Constraint
18+
{
19+
public function __construct(
20+
private readonly string $expectedSubjectValue,
21+
) {
22+
}
23+
24+
public function toString(): string
25+
{
26+
return sprintf('contains subject with value "%s"', $this->expectedSubjectValue);
27+
}
28+
29+
protected function matches($other): bool
30+
{
31+
if (!$other instanceof Email) {
32+
throw new \LogicException('Can only test a message subject on a Email instance.');
33+
}
34+
35+
return str_contains((string) $other->getSubject(), $this->expectedSubjectValue);
36+
}
37+
38+
protected function failureDescription($other): string
39+
{
40+
$message = 'The email subject '.$this->toString();
41+
if ($other instanceof Email) {
42+
$message .= sprintf('. The subject was: "%s"', $other->getSubject() ?? '<empty>');
43+
}
44+
45+
return $message;
46+
}
47+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy