public function testFail() { /** @var CM_Log_ContextFormatter_Interface $contextFormatter */ $contextFormatter = $this->mockInterface('CM_Log_ContextFormatter_Interface')->newInstanceWithoutConstructor(); /** @var GuzzleHttp\Client|\Mocka\AbstractClassTrait $httpClient */ $httpClient = $this->mockObject('GuzzleHttp\\Client'); /** @var \Mocka\FunctionMock $sendFailMethod */ $sendFailMethod = $httpClient->mockMethod('send')->set(function () { throw new GuzzleHttp\Exception\TransferException(); }); $location = $this->mockClass('CM_Geo_Point')->newInstanceWithoutConstructor(); /** @var CM_Geo_Point $location */ $server = new CM_Janus_Server(0, 'bar', 'http://cm-janus.dev:8080', 'ws://cm-janus.dev:8188', [], $location); $api = new CM_Janus_HttpApiClient($httpClient, $contextFormatter); $exception = $this->catchException(function () use($api, $server) { $api->fetchStatus($server); }); $this->assertInstanceOf('CM_Exception_Invalid', $exception); $this->assertStringStartsWith('Fetching contents from', $exception->getMessage()); $this->assertSame(1, $sendFailMethod->getCallCount()); $httpClient->mockMethod('send')->set(function () { $response = $this->mockClass('\\GuzzleHttp\\Message\\Response')->newInstanceWithoutConstructor(); $response->mockMethod('getBody')->set(null); return $response; }); $exception = $this->catchException(function () use($api, $server) { $api->fetchStatus($server); }); $this->assertInstanceOf('CM_Exception_Invalid', $exception); $this->assertSame('Empty response body', $exception->getMessage()); $this->assertSame(2, $sendFailMethod->getCallCount()); }
/** * @param CM_Model_Stream_Abstract $stream * @throws CM_Exception_Invalid * @throws CM_Janus_StopStreamError */ protected function _stopStream(CM_Model_Stream_Abstract $stream) { /** @var $streamChannel CM_Model_StreamChannel_Media */ $streamChannel = $stream->getStreamChannel(); $server = $this->_serverList->getById($streamChannel->getServerId()); $result = $this->_httpApiClient->stopStream($server, $stream->getKey()); if (array_key_exists('error', $result)) { throw new CM_Janus_StopStreamError($result['error']); } }