1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\MonitorBundle\Tests\Helper; |
4
|
|
|
|
5
|
|
|
use Laminas\Diagnostics\Check\CheckInterface; |
6
|
|
|
use Laminas\Diagnostics\Result\AbstractResult; |
7
|
|
|
use Laminas\Diagnostics\Result\Collection; |
8
|
|
|
use Laminas\Diagnostics\Result\Failure; |
9
|
|
|
use Laminas\Diagnostics\Result\ResultInterface; |
10
|
|
|
use Laminas\Diagnostics\Result\Skip; |
11
|
|
|
use Laminas\Diagnostics\Result\Success; |
12
|
|
|
use Laminas\Diagnostics\Result\Warning; |
13
|
|
|
use Liip\MonitorBundle\Helper\SwiftMailerReporter; |
14
|
|
|
use Prophecy\Argument; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Kevin Bond <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class SwiftMailerReporterTest extends \PHPUnit\Framework\TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @dataProvider sendNoEmailProvider |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function testSendNoEmail(ResultInterface $result, $sendOnWarning) |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$mailer = $this->prophesize('Swift_Mailer'); |
27
|
|
|
$mailer->send()->shouldNotBeCalled(); |
28
|
|
|
|
29
|
|
|
$results = new Collection(); |
30
|
|
|
$results[$this->prophesize(CheckInterface::class)->reveal()] = $result; |
31
|
|
|
|
32
|
|
|
$reporter = new SwiftMailerReporter($mailer->reveal(), '[email protected]', '[email protected]', 'foo bar', $sendOnWarning); |
33
|
|
|
$reporter->onFinish($results); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider sendEmailProvider |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
public function testSendEmail(ResultInterface $result, $sendOnWarning) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$mailer = $this->prophesize('Swift_Mailer'); |
42
|
|
|
$mailer->send(Argument::type('Swift_Message'))->shouldBeCalled(); |
43
|
|
|
|
44
|
|
|
$results = new Collection(); |
45
|
|
|
$results[$this->prophesize(CheckInterface::class)->reveal()] = $result; |
46
|
|
|
|
47
|
|
|
$reporter = new SwiftMailerReporter($mailer->reveal(), '[email protected]', '[email protected]', 'foo bar', $sendOnWarning); |
48
|
|
|
$reporter->onFinish($results); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function sendEmailProvider() |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
[new Failure(), true], |
55
|
|
|
[new Warning(), true], |
56
|
|
|
[new Unknown(), true], |
57
|
|
|
[new Failure(), false], |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function sendNoEmailProvider() |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
[new Success(), true], |
65
|
|
|
[new Skip(), true], |
66
|
|
|
[new Warning(), false], |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
class Unknown extends AbstractResult |
72
|
|
|
{ |
73
|
|
|
} |
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.