SwiftMailerReporterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 43.14 %

Coupling/Cohesion

Components 0
Dependencies 10

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 10
dl 22
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSendNoEmail() 11 11 1
A testSendEmail() 11 11 1
A sendEmailProvider() 0 9 1
A sendNoEmailProvider() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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