Completed
Push — master ( d34b0d...4b6ea9 )
by Mark
24s queued 14s
created

EmailTrait::cleanupEmailTrait()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11
 * @link          https://cakephp.org CakePHP(tm) Project
12
 * @since         3.7.0
13
 * @license       https://opensource.org/licenses/mit-license.php MIT License
14
 */
15
namespace Cake\TestSuite;
16
17
use Cake\TestSuite\Constraint\Email\MailContains;
18
use Cake\TestSuite\Constraint\Email\MailContainsHtml;
19
use Cake\TestSuite\Constraint\Email\MailContainsText;
20
use Cake\TestSuite\Constraint\Email\MailCount;
21
use Cake\TestSuite\Constraint\Email\MailSentFrom;
22
use Cake\TestSuite\Constraint\Email\MailSentTo;
23
use Cake\TestSuite\Constraint\Email\MailSentWith;
24
use Cake\TestSuite\Constraint\Email\NoMailSent;
25
26
/**
27
 * Make assertions on emails sent through the Cake\TestSuite\TestEmailTransport
28
 *
29
 * After adding the trait to your test case, all mail transports will be replaced
30
 * with TestEmailTransport which is used for making assertions and will *not* actually
31
 * send emails.
32
 */
33
trait EmailTrait
34
{
35
    /**
36
     * Replaces all transports with the test transport during test setup
37
     *
38
     * @before
39
     * @return void
40
     */
41
    public function setupTransports()
42
    {
43
        TestEmailTransport::replaceAllTransports();
44
    }
45
46
    /**
47
     * Resets transport state
48
     *
49
     * @after
50
     * @return void
51
     */
52
    public function cleanupEmailTrait()
53
    {
54
        TestEmailTransport::clearEmails();
55
    }
56
57
    /**
58
     * Asserts an expected number of emails were sent
59
     *
60
     * @param int $count Email count
61
     * @param string $message Message
62
     * @return void
63
     */
64
    public function assertMailCount($count, $message = null)
65
    {
66
        $this->assertThat($count, new MailCount(), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
67
    }
68
    /**
69
     *
70
     * Asserts that no emails were sent
71
     *
72
     * @param string $message Message
73
     * @return void
74
     */
75
    public function assertNoMailSent($message = null)
76
    {
77
        $this->assertThat(null, new NoMailSent(), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
78
    }
79
80
    /**
81
     * Asserts an email at a specific index was sent to an address
82
     *
83
     * @param int $at Email index
84
     * @param int $address Email address
85
     * @param string $message Message
86
     * @return void
87
     */
88
    public function assertMailSentToAt($at, $address, $message = null)
89
    {
90
        $this->assertThat($address, new MailSentTo($at), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
91
    }
92
93
    /**
94
     * Asserts an email at a specific index was sent from an address
95
     *
96
     * @param int $at Email index
97
     * @param int $address Email address
98
     * @param string $message Message
99
     * @return void
100
     */
101
    public function assertMailSentFromAt($at, $address, $message = null)
102
    {
103
        $this->assertThat($address, new MailSentFrom($at), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
104
    }
105
106
    /**
107
     * Asserts an email at a specific index contains expected contents
108
     *
109
     * @param int $at Email index
110
     * @param int $contents Contents
111
     * @param string $message Message
112
     * @return void
113
     */
114
    public function assertMailContainsAt($at, $contents, $message = null)
115
    {
116
        $this->assertThat($contents, new MailContains($at), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
117
    }
118
119
    /**
120
     * Asserts an email at a specific index contains expected html contents
121
     *
122
     * @param int $at Email index
123
     * @param int $contents Contents
124
     * @param string $message Message
125
     * @return void
126
     */
127
    public function assertMailContainsHtmlAt($at, $contents, $message = null)
128
    {
129
        $this->assertThat($contents, new MailContainsHtml($at), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
130
    }
131
132
    /**
133
     * Asserts an email at a specific index contains expected text contents
134
     *
135
     * @param int $at Email index
136
     * @param int $contents Contents
137
     * @param string $message Message
138
     * @return void
139
     */
140
    public function assertMailContainsTextAt($at, $contents, $message = null)
141
    {
142
        $this->assertThat($contents, new MailContainsText($at), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
143
    }
144
145
    /**
146
     * Asserts an email at a specific index contains the expected value within an Email getter
147
     *
148
     * @param int $at Email index
149
     * @param int $expected Contents
150
     * @param int $parameter Email getter parameter (e.g. "cc", "subject")
151
     * @param string $message Message
152
     * @return void
153
     */
154
    public function assertMailSentWithAt($at, $expected, $parameter, $message = null)
155
    {
156
        $this->assertThat($expected, new MailSentWith($at, $parameter), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
157
    }
158
159
    /**
160
     * Asserts an email was sent to an address
161
     *
162
     * @param int $address Email address
163
     * @param string $message Message
164
     * @return void
165
     */
166
    public function assertMailSentTo($address, $message = null)
167
    {
168
        $this->assertThat($address, new MailSentTo(), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
169
    }
170
171
    /**
172
     * Asserts an email was sent from an address
173
     *
174
     * @param int $address Email address
175
     * @param string $message Message
176
     * @return void
177
     */
178
    public function assertMailSentFrom($address, $message = null)
179
    {
180
        $this->assertThat($address, new MailSentFrom(), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
181
    }
182
183
    /**
184
     * Asserts an email contains expected contents
185
     *
186
     * @param int $contents Contents
187
     * @param string $message Message
188
     * @return void
189
     */
190
    public function assertMailContains($contents, $message = null)
191
    {
192
        $this->assertThat($contents, new MailContains(), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
193
    }
194
195
    /**
196
     * Asserts an email contains expected html contents
197
     *
198
     * @param int $contents Contents
199
     * @param string $message Message
200
     * @return void
201
     */
202
    public function assertMailContainsHtml($contents, $message = null)
203
    {
204
        $this->assertThat($contents, new MailContainsHtml(), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
205
    }
206
207
    /**
208
     * Asserts an email contains expected text contents
209
     *
210
     * @param int $contents Contents
211
     * @param string $message Message
212
     * @return void
213
     */
214
    public function assertMailContainsText($contents, $message = null)
215
    {
216
        $this->assertThat($contents, new MailContainsText(), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
217
    }
218
219
    /**
220
     * Asserts an email contains the expected value within an Email getter
221
     *
222
     * @param int $expected Contents
223
     * @param int $parameter Email getter parameter (e.g. "cc", "subject")
224
     * @param string $message Message
225
     * @return void
226
     */
227
    public function assertMailSentWith($expected, $parameter, $message = null)
228
    {
229
        $this->assertThat($expected, new MailSentWith(null, $parameter), $message);
0 ignored issues
show
Bug introduced by
It seems like assertThat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
230
    }
231
}
232