BoardApiControllerTest wrote get() tests.
Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
committed by
Julius Härtl
parent
fad579c4d3
commit
bd254fd261
@@ -75,16 +75,16 @@ class BoardApiController extends ApiController {
|
|||||||
*
|
*
|
||||||
* Return the board specified by $this->request->params['boardId'].
|
* Return the board specified by $this->request->params['boardId'].
|
||||||
*/
|
*/
|
||||||
public function get() {
|
public function get() {
|
||||||
|
|
||||||
if (is_numeric($this->request->params['boardId']) === false) {
|
if (is_numeric($this->request->getParam('boardId')) === false) {
|
||||||
return new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
|
return new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
$board = $this->service->find($this->request->params['boardId']);
|
$board = $this->service->find($this->request->getParam('boardId'));
|
||||||
|
|
||||||
if ($board === false || $board === null) {
|
if ($board === false || $board === null) {
|
||||||
return new DataResponse('Board not found', HTTP::STATUS_NOT_FOUND);
|
return new DataResponse('board not found', HTTP::STATUS_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DataResponse($board, HTTP::STATUS_OK);
|
return new DataResponse($board, HTTP::STATUS_OK);
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ class BoardApiControllerTest extends \Test\TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test to pass
|
|
||||||
public function testIndex() {
|
public function testIndex() {
|
||||||
$board = new Board();
|
$board = new Board();
|
||||||
$board->setId('1');
|
$board->setId('1');
|
||||||
@@ -68,18 +67,48 @@ class BoardApiControllerTest extends \Test\TestCase {
|
|||||||
|
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGet() {
|
||||||
|
$boardId = 25;
|
||||||
|
$board = new Board();
|
||||||
|
$board->setId($boardId);
|
||||||
|
$this->boardService->expects($this->once())
|
||||||
|
->method('find')
|
||||||
|
->willReturn($board);
|
||||||
|
|
||||||
|
$this->request->expects($this->any())
|
||||||
|
->method('getParam')
|
||||||
|
->with('boardId')
|
||||||
|
->will($this->returnValue($boardId));
|
||||||
|
|
||||||
|
$expected = new DataResponse($board, HTTP::STATUS_OK);
|
||||||
|
$actual = $this->controller->get();
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetBadRequest() {
|
||||||
|
|
||||||
|
$this->request->expects($this->any())
|
||||||
|
->method('getParam')
|
||||||
|
->with('boardId')
|
||||||
|
->will($this->returnValue('hello'));
|
||||||
|
|
||||||
// test for the bad request path
|
|
||||||
public function testIndexBadRequest() {
|
|
||||||
$expected = new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
|
$expected = new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||||
$actual = $this->controller->index();
|
$actual = $this->controller->get();
|
||||||
|
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Write testGet()
|
public function testGetNotFound() {
|
||||||
public function testGet() {
|
$this->request->expects($this->any())
|
||||||
$this->assertEquals(false, true);
|
->method('getParam')
|
||||||
|
->with('boardId')
|
||||||
|
->will($this->returnValue('999'));
|
||||||
|
|
||||||
|
$expected = new DataResponse('board not found', HTTP::STATUS_NOT_FOUND);
|
||||||
|
$actual = $this->controller->get();
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Write testCreate()
|
// TODO: Write testCreate()
|
||||||
|
|||||||
Reference in New Issue
Block a user