-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mailer] Add EmailSubjectContains constraint (#49939)
Adds assertEmailSubjectContains and assertEmailSubjectNotContains
- Loading branch information
1 parent
52a9292
commit 55ba7b8
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Symfony/Component/Mime/Test/Constraint/EmailSubjectContains.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mime\Test\Constraint; | ||
|
||
use PHPUnit\Framework\Constraint\Constraint; | ||
use Symfony\Component\Mime\Email; | ||
|
||
final class EmailSubjectContains extends Constraint | ||
{ | ||
public function __construct( | ||
private readonly string $expectedSubjectValue, | ||
) { | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return sprintf('contains subject with value "%s"', $this->expectedSubjectValue); | ||
} | ||
|
||
protected function matches($other): bool | ||
{ | ||
if (!$other instanceof Email) { | ||
throw new \LogicException('Can only test a message subject on a Email instance.'); | ||
} | ||
|
||
return str_contains((string) $other->getSubject(), $this->expectedSubjectValue); | ||
} | ||
|
||
protected function failureDescription($other): string | ||
{ | ||
$message = 'The email subject '.$this->toString(); | ||
if ($other instanceof Email) { | ||
$message .= sprintf('. The subject was: "%s"', $other->getSubject() ?? '<empty>'); | ||
} | ||
|
||
return $message; | ||
} | ||
} |