Skip to content

Commit 1a2c1a0

Browse files
committed
Add tests (100% coverage)
1 parent 42f269b commit 1a2c1a0

2 files changed

Lines changed: 121 additions & 4 deletions

File tree

src/Client.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function containerWait($container)
6161
*/
6262
public function containerStop($container, $t)
6363
{
64-
return $this->browser->post('/containers/' . $container . '/stop')->then(array($this, 'expectEmpty'));
64+
return $this->browser->post('/containers/' . $container . '/stop?t=' . $t)->then(array($this, 'expectEmpty'));
6565
}
6666

6767
/**
@@ -72,7 +72,7 @@ public function containerStop($container, $t)
7272
*/
7373
public function containerRestart($container, $t)
7474
{
75-
return $this->browser->post('/containers/' . $container . '/restart')->then(array($this, 'expectEmpty'));
75+
return $this->browser->post('/containers/' . $container . '/restart?t=' . $t)->then(array($this, 'expectEmpty'));
7676
}
7777

7878
public function containerKill($container, $signal = null)
@@ -99,12 +99,12 @@ public function containerUnpause($container)
9999
*/
100100
public function containerDelete($container, $v = false, $force = false)
101101
{
102-
return $this->browser->delete('/containers/' . $container)->then(array($this, 'expectEmpty'));
102+
return $this->browser->delete('/containers/' . $container . '?v=' . (int)$v . '&force=' . (int)$force)->then(array($this, 'expectEmpty'));
103103
}
104104

105105
public function containerResize($container, $w, $h)
106106
{
107-
return $this->browser->get('/container/' . $container . '/resize?w=' . $w . '&h=' . $h)->then(array($this, 'expectEmpty'));
107+
return $this->browser->get('/containers/' . $container . '/resize?w=' . $w . '&h=' . $h)->then(array($this, 'expectEmpty'));
108108
}
109109

110110
public function expectPlain(Response $response)

tests/ClientTest.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
use Clue\React\Buzz\Message\Response;
4+
use Clue\React\Buzz\Message\Body;
5+
use Clue\React\Docker\Client;
6+
use React\Promise\Deferred;
7+
8+
class ClientTest extends TestCase
9+
{
10+
private $browser;
11+
private $client;
12+
13+
public function setUp()
14+
{
15+
$this->browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
16+
$this->client = new Client($this->browser);
17+
}
18+
19+
public function testPing()
20+
{
21+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('/_ping'))->will($this->returnResponse('OK'));
22+
23+
$this->client->ping();
24+
}
25+
26+
public function testContainerInspect()
27+
{
28+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('/containers/123/json'))->will($this->returnResponse('{}'));
29+
30+
$this->client->containerInspect(123);
31+
}
32+
33+
public function testContainerTop()
34+
{
35+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('/containers/123/top'))->will($this->returnResponse('{}'));
36+
37+
$this->client->containerTop(123);
38+
}
39+
40+
public function testContainerWait()
41+
{
42+
$this->browser->expects($this->once())->method('post')->with($this->equalTo('/containers/123/wait'))->will($this->returnResponse('{}'));
43+
44+
$this->client->containerWait(123);
45+
}
46+
47+
public function testContainerKill()
48+
{
49+
$this->browser->expects($this->once())->method('post')->with($this->equalTo('/containers/123/kill?signal='))->will($this->returnResponse());
50+
51+
$this->client->containerKill(123);
52+
}
53+
54+
public function testContainerKillSignalName()
55+
{
56+
$this->browser->expects($this->once())->method('post')->with($this->equalTo('/containers/123/kill?signal=SIGKILL'))->will($this->returnResponse());
57+
58+
$this->client->containerKill(123, 'SIGKILL');
59+
}
60+
61+
public function testContainerKillSignalNumber()
62+
{
63+
$this->browser->expects($this->once())->method('post')->with($this->equalTo('/containers/123/kill?signal=9'))->will($this->returnResponse());
64+
65+
$this->client->containerKill(123, 9);
66+
}
67+
68+
public function testContainerStop()
69+
{
70+
$this->browser->expects($this->once())->method('post')->with($this->equalTo('/containers/123/stop?t=10'))->will($this->returnResponse());
71+
72+
$this->client->containerStop(123, 10);
73+
}
74+
75+
public function testContainerRestart()
76+
{
77+
$this->browser->expects($this->once())->method('post')->with($this->equalTo('/containers/123/restart?t=10'))->will($this->returnResponse());
78+
79+
$this->client->containerRestart(123, 10);
80+
}
81+
82+
public function testContainerPause()
83+
{
84+
$this->browser->expects($this->once())->method('post')->with($this->equalTo('/containers/123/pause'))->will($this->returnResponse());
85+
86+
$this->client->containerPause(123);
87+
}
88+
89+
public function testContainerUnpause()
90+
{
91+
$this->browser->expects($this->once())->method('post')->with($this->equalTo('/containers/123/unpause'))->will($this->returnResponse());
92+
93+
$this->client->containerUnpause(123);
94+
}
95+
96+
public function testContainerDelete()
97+
{
98+
$this->browser->expects($this->once())->method('delete')->with($this->equalTo('/containers/123?v=0&force=0'))->will($this->returnResponse());
99+
100+
$this->client->containerDelete(123, false, false);
101+
}
102+
103+
public function testContainerResize()
104+
{
105+
$this->browser->expects($this->once())->method('get')->with($this->equalTo('/containers/123/resize?w=800&h=600'))->will($this->returnResponse());
106+
107+
$this->client->containerResize(123, 800, 600);
108+
}
109+
110+
private function returnResponse($body = '')
111+
{
112+
$deferred = new Deferred();
113+
$deferred->resolve(new Response('HTTP/1.0', 200, 'OK', null, new Body($body)));
114+
115+
return $this->returnValue($deferred->promise());
116+
}
117+
}

0 commit comments

Comments
 (0)