public function testRespondDoesParameters()
 {
     // parameters
     $status = 100;
     $headers = ['coolness' => '(awyeah)'];
     Response::shouldReceive('json')->with($this->data, $status, $headers)->once()->andReturn(true);
     expect($this->controller->respond($status, $headers))->true();
 }
Example #2
0
 public function testErrorHandlerWithExceptionAndMessageAndCode()
 {
     $exception = new \Exception('some exception', 1001);
     $error_handler = new \Vinelab\Api\ErrorHandler($this->responder);
     $expected = ['status' => 401, 'error' => ['code' => 1001, 'message' => 'some exception']];
     $response = M::mock('Illuminate\\Http\\Response');
     $response->original = $expected;
     Response::shouldReceive('json')->once()->with($expected, $expected['status'], [], 0)->andReturn($response);
     $response = $error_handler->handle($exception, $exception->getCode(), 401)->original;
     $this->assertEquals($expected, $response);
     $this->assertInternalType('int', $response['status']);
 }
Example #3
0
 public function testCallingMapperAsArrayWithInstance()
 {
     $mPost = M::mock('Post');
     $mPost->shouldReceive('setAttribute')->passthru();
     $mPost->id = 1;
     $mPost->text = 'Enim provident tempore reiciendis quit qui.';
     $mPost->active = true;
     $mPost->shouldReceive('getAttribute')->passthru();
     $expected = ['status' => 200, 'data' => ['id' => 1, 'text' => 'Enim provident tempore reiciendis quit qui.', 'active' => true]];
     $response = M::mock('Illuminate\\Http\\Response');
     $response->shouldReceive('getData')->once()->andReturn($expected);
     Response::shouldReceive('json')->once()->with($expected, 200, [], 0)->andReturn($response);
     $this->response_handler->setMapperNamespace('Vinelab\\Api\\Tests\\');
     $mapper = [new DummyMapper(), 'mapDatThing'];
     $result = $this->response_handler->content($mapper, $mPost);
     $this->assertInternalType('array', $result);
     $this->assertEquals($expected, $result);
 }