1 | <?php |
||
16 | abstract class AssertionRunner { |
||
17 | |||
18 | /** |
||
19 | * @var \Ingenerator\Mailhook\EmailListFilterer |
||
20 | */ |
||
21 | protected $filterer; |
||
22 | /** |
||
23 | * @var \Ingenerator\Mailhook\Mailhook |
||
24 | */ |
||
25 | protected $mailhook; |
||
26 | |||
27 | /** |
||
28 | * @param \Ingenerator\Mailhook\Mailhook $mailhook |
||
29 | * @param \Ingenerator\Mailhook\EmailListFilterer $filterer |
||
30 | */ |
||
31 | public function __construct(Mailhook $mailhook, EmailListFilterer $filterer) |
||
32 | { |
||
33 | $this->mailhook = $mailhook; |
||
34 | $this->filterer = $filterer; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Run assertions and throw if they do not pass |
||
39 | * |
||
40 | * @param EmailMatcher[] $matchers |
||
41 | * |
||
42 | * @return \Ingenerator\Mailhook\Email[] emails that matched the assertion |
||
43 | */ |
||
44 | public function assert($matchers = array()) |
||
45 | { |
||
46 | $this->mailhook->refresh(); |
||
47 | $mails = $this->filterer->filterEmails($this->mailhook->getEmails(), $matchers); |
||
48 | $this->do_assert($mails, $matchers); |
||
49 | |||
50 | return $mails; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param Email[] $matched_mails |
||
55 | * @param EmailMatcher[] $matchers |
||
56 | * |
||
57 | * @return mixed |
||
58 | */ |
||
59 | abstract protected function do_assert($matched_mails, $matchers); |
||
60 | } |
||
61 |