Completed
Push — example/managing-articles ( cc835c...e93c5a )
by Loïc
02:50 queued 02:46
created

anEmailToVerifyYourEmailValidityShouldHaveBeenSentTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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
declare(strict_types=1);
13
14
namespace App\Behat\Context\Ui;
15
16
use Behat\Behat\Context\Context;
17
use App\Behat\Service\SharedStorageInterface;
18
use App\Behat\Service\EmailCheckerInterface;
19
use Webmozart\Assert\Assert;
20
21
final class EmailContext implements Context
22
{
23
    /**
24
     * @var SharedStorageInterface
25
     */
26
    private $sharedStorage;
27
28
    /**
29
     * @var EmailCheckerInterface
30
     */
31
    private $emailChecker;
32
33
    /**
34
     * @param SharedStorageInterface $sharedStorage
35
     * @param EmailCheckerInterface  $emailChecker
36
     */
37
    public function __construct(SharedStorageInterface $sharedStorage, EmailCheckerInterface $emailChecker)
38
    {
39
        $this->sharedStorage = $sharedStorage;
40
        $this->emailChecker = $emailChecker;
41
    }
42
43
    /**
44
     * @Then it should be sent to :recipient
45
     * @Then the email with reset token should be sent to :recipient
46
     * @Then the email with contact request should be sent to :recipient
47
     */
48
    public function anEmailShouldBeSentTo($recipient)
49
    {
50
        Assert::true($this->emailChecker->hasRecipient($recipient));
51
    }
52
53
    /**
54
     * @Then :count email(s) should be sent to :recipient
55
     */
56
    public function numberOfEmailsShouldBeSentTo($count, $recipient)
57
    {
58
        Assert::same($this->emailChecker->countMessagesTo($recipient), (int) $count);
59
    }
60
61
    /**
62
     * @Then an email to verify your email validity should have been sent to :recipient
63
     */
64
    public function anEmailToVerifyYourEmailValidityShouldHaveBeenSentTo($recipient)
65
    {
66
        $this->assertEmailContainsMessageTo('To verify your email address', $recipient);
67
    }
68
69
    /**
70
     * @Then a welcoming email should have been sent to :recipient
71
     */
72
    public function aWelcomingEmailShouldHaveBeenSentTo($recipient)
73
    {
74
        $this->assertEmailContainsMessageTo('Welcome to our website', $recipient);
75
    }
76
77
    /**
78
     * @param string $message
79
     * @param string $recipient
80
     */
81
    private function assertEmailContainsMessageTo($message, $recipient)
82
    {
83
        Assert::true($this->emailChecker->hasMessageTo($message, $recipient));
84
    }
85
}
86