File tree Expand file tree Collapse file tree 3 files changed +102
-0
lines changed Expand file tree Collapse file tree 3 files changed +102
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ CHANGELOG
4
4
4.4.0
5
5
-----
6
6
7
+ * Added PHPUnit constraints
7
8
* Added ` MessageDataCollector `
8
9
* Added ` MessageEvents ` and ` MessageLoggerListener ` to allow collecting sent emails
9
10
* [ BC BREAK] ` TransportInterface ` has a new ` getName() ` method
Original file line number Diff line number Diff line change
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 \Mailer \Test \Constraint ;
13
+
14
+ use PHPUnit \Framework \Constraint \Constraint ;
15
+ use Symfony \Component \Mailer \Event \MessageEvents ;
16
+
17
+ final class EmailCount extends Constraint
18
+ {
19
+ private $ expectedValue ;
20
+ private $ transport ;
21
+
22
+ public function __construct (int $ expectedValue , string $ transport = null )
23
+ {
24
+ $ this ->expectedValue = $ expectedValue ;
25
+ $ this ->transport = $ transport ;
26
+ }
27
+
28
+ /**
29
+ * {@inheritdoc}
30
+ */
31
+ public function toString (): string
32
+ {
33
+ return sprintf ('%shas sent "%d" emails ' , $ this ->transport ? $ this ->transport .' ' : '' , $ this ->expectedValue );
34
+ }
35
+
36
+ /**
37
+ * @param MessageEvents $events
38
+ *
39
+ * {@inheritdoc}
40
+ */
41
+ protected function matches ($ events ): bool
42
+ {
43
+ return $ this ->expectedValue === \count ($ events ->getEvents ($ this ->transport ));
44
+ }
45
+
46
+ /**
47
+ * @param MessageEvents $events
48
+ *
49
+ * {@inheritdoc}
50
+ */
51
+ protected function failureDescription ($ events ): string
52
+ {
53
+ return sprintf ('the Transport %s (%d sent) ' , $ this ->toString (), \count ($ events ->getEvents ($ this ->transport )));
54
+ }
55
+ }
Original file line number Diff line number Diff line change
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 \Mailer \Test \Constraint ;
13
+
14
+ use PHPUnit \Framework \Constraint \Constraint ;
15
+ use Symfony \Component \Mailer \Event \MessageEvent ;
16
+
17
+ final class EmailIsQueued extends Constraint
18
+ {
19
+ /**
20
+ * {@inheritdoc}
21
+ */
22
+ public function toString (): string
23
+ {
24
+ return 'is queued ' ;
25
+ }
26
+
27
+ /**
28
+ * @param MessageEvent $event
29
+ *
30
+ * {@inheritdoc}
31
+ */
32
+ protected function matches ($ event ): bool
33
+ {
34
+ return $ event ->isQueued ();
35
+ }
36
+
37
+ /**
38
+ * @param MessageEvent $event
39
+ *
40
+ * {@inheritdoc}
41
+ */
42
+ protected function failureDescription ($ event ): string
43
+ {
44
+ return 'the Email ' .$ this ->toString ();
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments