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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.