Completed
Push — master ( 662efc...619ed4 )
by ophelie
7s
created

ComposeManagerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 18.67 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 22
Bugs 1 Features 18
Metric Value
wmc 7
c 22
b 1
f 18
lcom 0
cbo 0
dl 14
loc 75
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testStop() 0 5 1
A testStopWithOneComposeFileSpecified() 0 6 1
A testStopWithTwoComposeFilesSpecified() 0 6 1
A testStopThrowComposeFileNotFound() 7 7 1
A testStopThrowDockerHostConnexionErrorException() 7 7 1
A testStopThrowDockerInstallationMissingException() 0 5 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 DockerCompose\Tests\Manager;
4
5
use PHPUnit_Framework_TestCase;
6
use DockerCompose\ComposeFile;
7
use DockerCompose\ComposeFileCollection;
8
9
10
class ComposeManagerTest 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 stop whithout error
21
     */
22
    public function testStop()
23
    {
24
        $this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0));
25
        $this->assertEquals($this->mockedManager->stop(), 'ok');
26
    }
27
28
    /**
29
     * Test stop success with one compose file
30
     */
31
    public function testStopWithOneComposeFileSpecified()
32
    {
33
34
        $this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0));
35
        $this->assertEquals($this->mockedManager->stop('docker-compose.test.yml'), 'ok');
36
    }
37
38
    /**
39
     * Test stop success with two compose files
40
     */
41
    public function testStopWithTwoComposeFilesSpecified()
42
    {
43
44
        $this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0));
45
        $this->assertEquals($this->mockedManager->stop(['docker-compose.yml', 'docker-compose.test.yml']), 'ok');
46
    }
47
48
    /**
49
     * Test stop with ComposeFileNotFoundException
50
     *
51
     * @expectedException \DockerCompose\Exception\ComposeFileNotFoundException
52
     */
53 View Code Duplication
    public function testStopThrowComposeFileNotFound()
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...
54
    {
55
        $error = 'Can\'t find a suitable configuration file in this directory or any parent. Are you in the right directory?\n';
56
        $error .= 'Supported filenames: docker-compose.yml, docker-compose.yaml, fig.yml, fig.yaml';
57
        $this->mockedManager->method('execute')->willReturn(array('output' => $error, 'code' => 1));
58
        $this->mockedManager->stop();
59
    }
60
61
    /**
62
     * Test stop with DockerHostConnexionErrorException
63
     *
64
     * @expectedException \DockerCompose\Exception\DockerHostConnexionErrorException
65
     */
66 View Code Duplication
    public function testStopThrowDockerHostConnexionErrorException()
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...
67
    {
68
        $error = 'Couldn\'t connect to Docker daemon at http+docker://localunixsocket - is it running?\n';
69
        $error .= 'If it\'s at a non-standard location, specify the URL with the DOCKER_HOST environment variable.';
70
        $this->mockedManager->method('execute')->willReturn(array('output' => $error, 'code' => 1));
71
        $this->mockedManager->stop();
72
    }
73
74
    /**
75
     * Test stop with DockerInstallationMissingException
76
     *
77
     * @expectedException \DockerCompose\Exception\DockerInstallationMissingException
78
     */
79
    public function testStopThrowDockerInstallationMissingException()
80
    {
81
        $this->mockedManager->method('execute')->willReturn(array('output' => '', 'code' => 127));
82
        $this->mockedManager->stop();
83
    }
84
}
85