Completed
Push — master ( 6b1ea1...07aa67 )
by Michael
02:51
created

DeploymentTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 89
wmc 6
lcom 1
cbo 8
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 17 1
A testGetEnvironment() 0 7 1
A testGetPreviousVersion() 0 7 1
A testGetCurrentVersion() 0 7 1
A testGetServer() 0 7 1
B testGetChanges() 0 29 1
1
<?php
2
3
namespace ParityBit\DeploymentNotifier;
4
5
use ParityBit\DeploymentNotifier\ChangeInspectors\ChangeInspector;
6
7
class DeploymentTest extends \PHPUnit_Framework_TestCase
8
{
9
    protected $faker;
10
    protected $previousVersion;
11
    protected $currentVersion;
12
    protected $environment;
13
    protected $server;
14
    protected $changeInspector;
15
16
    public function setUp()
17
    {
18
        $this->faker = \Faker\Factory::create();
19
        $this->previousVersion = new Version($this->faker->word);
20
        $this->currentVersion = new Version($this->faker->word);
21
        $this->environment = new Environment($this->faker->word);
22
        $this->server = new Server($this->faker->word);
23
        $this->changeInspector = $this->getMock(ChangeInspector::class);
24
25
        $this->deployment = new Deployment(
0 ignored issues
show
Bug introduced by
The property deployment does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
            $this->environment,
27
            $this->previousVersion,
28
            $this->currentVersion,
29
            $this->server,
30
            $this->changeInspector
31
        );
32
    }
33
34
    public function testGetEnvironment()
35
    {
36
        $this->assertEquals(
37
            $this->environment,
38
            $this->deployment->getEnvironment()
39
        );
40
    }
41
42
    public function testGetPreviousVersion()
43
    {
44
        $this->assertEquals(
45
            $this->previousVersion,
46
            $this->deployment->getPreviousVersion()
47
        );
48
    }
49
50
    public function testGetCurrentVersion()
51
    {
52
        $this->assertEquals(
53
            $this->currentVersion,
54
            $this->deployment->getCurrentVersion()
55
        );
56
    }
57
58
    public function testGetServer()
59
    {
60
        $this->assertEquals(
61
            $this->server,
62
            $this->deployment->getServer()
63
        );
64
    }
65
66
    public function testGetChanges()
67
    {
68
        $changes = [
69
            $this->faker->word,
70
            $this->faker->word,
71
            $this->faker->word,
72
        ];
73
74
        $this->changeInspector = $this->getMockBuilder(ChangeInspector::class)
75
                                      ->disableOriginalConstructor()
76
                                      ->setMethods(['getChangesFromDeployment'])
77
                                      ->getMock();
78
        $this->changeInspector->expects($this->once())
79
                              ->method('getChangesFromDeployment')
80
                              ->with($this->callback(function ($subject) {
81
                                  return $subject == $this->deployment;
82
                              }))
83
                              ->will($this->returnValue($changes));
84
85
        $this->deployment = new Deployment(
86
            $this->environment,
87
            $this->previousVersion,
88
            $this->currentVersion,
89
            $this->server,
90
            $this->changeInspector
91
        );
92
93
        $this->assertEquals($changes, $this->deployment->getChanges());
94
    }
95
}
96