@@ -18,19 +18,21 @@ final class EmailCount extends Constraint
18
18
{
19
19
private $ expectedValue ;
20
20
private $ transport ;
21
+ private $ queued ;
21
22
22
- public function __construct (int $ expectedValue , string $ transport = null )
23
+ public function __construct (int $ expectedValue , string $ transport = null , bool $ queued = false )
23
24
{
24
25
$ this ->expectedValue = $ expectedValue ;
25
26
$ this ->transport = $ transport ;
27
+ $ this ->queued = $ queued ;
26
28
}
27
29
28
30
/**
29
31
* {@inheritdoc}
30
32
*/
31
33
public function toString (): string
32
34
{
33
- return sprintf ('%shas sent "%d" emails ' , $ this ->transport ? $ this ->transport .' ' : '' , $ this ->expectedValue );
35
+ return sprintf ('%shas %s "%d" emails ' , $ this ->transport ? $ this ->transport .' ' : '' , $ this -> queued ? ' queued ' : ' sent ' , $ this ->expectedValue );
34
36
}
35
37
36
38
/**
@@ -40,7 +42,7 @@ public function toString(): string
40
42
*/
41
43
protected function matches ($ events ): bool
42
44
{
43
- return $ this ->expectedValue === \count ( $ events -> getEvents ( $ this -> transport ) );
45
+ return $ this ->expectedValue === $ this -> countEmails ( $ events );
44
46
}
45
47
46
48
/**
@@ -50,6 +52,22 @@ protected function matches($events): bool
50
52
*/
51
53
protected function failureDescription ($ events ): string
52
54
{
53
- return sprintf ('the Transport %s (%d sent) ' , $ this ->toString (), \count ($ events ->getEvents ($ this ->transport )));
55
+ return sprintf ('the Transport %s (%d %s) ' , $ this ->toString (), $ this ->countEmails ($ events ), $ this ->queued ? 'queued ' : 'sent ' );
56
+ }
57
+
58
+ private function countEmails (MessageEvents $ events ): int
59
+ {
60
+ $ count = 0 ;
61
+ foreach ($ events ->getEvents ($ this ->transport ) as $ event ) {
62
+ if (
63
+ ($ this ->queued && $ event ->isQueued ())
64
+ ||
65
+ (!$ this ->queued && !$ event ->isQueued ())
66
+ ) {
67
+ ++$ count ;
68
+ }
69
+ }
70
+
71
+ return $ count ;
54
72
}
55
73
}
0 commit comments