|
| 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