Completed
Push — master ( 07aa67...ce71ee )
by Michael
03:29
created

DeploymentTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
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(
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