testStartThrowUnknownException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace DockerCompose\Tests\Manager;
4
5
use PHPUnit_Framework_TestCase;
6
use DockerCompose\ComposeFile;
7
use DockerCompose\ComposeFileCollection;
8
9
10
class ComposeManagerStartTest extends PHPUnit_Framework_TestCase
11
{
12
    public function setUp()
13
    {
14
        $this->mockedManager = $this->getMockBuilder('\DockerCompose\Manager\ComposeManager')
15
            ->setMethods(['execute'])
16
            ->getMock();
17
    }
18
19
    /**
20
     * Test simple start without error
21
     */
22
    public function testStart()
23
    {
24
        $this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0));
25
        $this->assertEquals($this->mockedManager->start(), 'ok');
26
    }
27
28
    /**
29
     * Test start success with one compose file
30
     */
31
    public function testStartWithOneComposeFileSpecified()
32
    {
33
        $this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0));
34
        $this->assertEquals($this->mockedManager->start('docker-compose-test.yml'), 'ok');
35
    }
36
37
    /**
38
     * Test start success with two compose files
39
     */
40
    public function testStartWithTwoComposeFilesSpecified()
41
    {
42
        $this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0));
43
        $this->assertEquals($this->mockedManager->start(['docker-compose.yml', 'docker-compose.test.yml']), 'ok');
44
    }
45
46
    /**
47
     * Test start with project option
48
     */
49
    public function testStartWithprojectOption()
50
    {
51
        $composeFiles = new ComposeFileCollection(['docker-compose.test.yml']);
52
        $composeFiles->setProjectName('unittest');
53
54
        $this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0));
55
56
        $this->assertEquals($this->mockedManager->start($composeFiles), 'ok');
57
58
    }
59
60
    /**
61
     * Test start with ComposeFileNotFoundException
62
     *
63
     * @expectedException \DockerCompose\Exception\ComposeFileNotFoundException
64
     */
65 View Code Duplication
    public function testStartThrowComposeFileNotFound()
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...
66
    {
67
        $error = 'Can\'t find a suitable configuration file in this directory or any parent. Are you in the right directory?\n';
68
        $error .= 'Supported filenames: docker-compose.yml, docker-compose.yaml, fig.yml, fig.yaml';
69
        $this->mockedManager->method('execute')->willReturn(array('output' => $error, 'code' => 1));
70
        $this->mockedManager->start();
71
    }
72
73
    /**
74
     * Test start with DockerHostConnexionErrorException
75
     *
76
     * @expectedException \DockerCompose\Exception\DockerHostConnexionErrorException
77
     */
78 View Code Duplication
    public function testStartThrowDockerHostConnexionErrorException()
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...
79
    {
80
        $error = 'Couldn\'t connect to Docker daemon at http+docker://localunixsocket - is it running?\n';
81
        $error .= 'If it\'s at a non-standard location, specify the URL with the DOCKER_HOST environment variable.';
82
        $this->mockedManager->method('execute')->willReturn(array('output' => $error, 'code' => 1));
83
        $this->mockedManager->start();
84
    }
85
86
    /**
87
     * Test start with DockerInstallationMissingException
88
     *
89
     * @expectedException \DockerCompose\Exception\DockerInstallationMissingException
90
     */
91
    public function testStartThrowDockerInstallationMissingException()
92
    {
93
        $this->mockedManager->method('execute')->willReturn(array('output' => '', 'code' => 127));
94
        $this->mockedManager->start();
95
    }
96
97
    /**
98
     * Test start with DockerInstallationMissingException
99
     *
100
     * @expectedException \Exception
101
     */
102
    public function testStartThrowUnknownException()
103
    {
104
        $this->mockedManager->method('execute')->willReturn(array('output' => '', 'code' => 1));
105
        $this->mockedManager->start();
106
    }
107
}
108