BoardApiControllerTest wrote get() tests.

Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
Ryan Fletcher
2018-07-14 21:57:16 -04:00
committed by Julius Härtl
parent fad579c4d3
commit bd254fd261
2 changed files with 40 additions and 11 deletions

View File

@@ -75,16 +75,16 @@ class BoardApiController extends ApiController {
*
* 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);
}
$board = $this->service->find($this->request->params['boardId']);
$board = $this->service->find($this->request->getParam('boardId'));
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);

View File

@@ -51,7 +51,6 @@ class BoardApiControllerTest extends \Test\TestCase {
}
// Test to pass
public function testIndex() {
$board = new Board();
$board->setId('1');
@@ -68,18 +67,48 @@ class BoardApiControllerTest extends \Test\TestCase {
$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);
$actual = $this->controller->index();
$actual = $this->controller->get();
$this->assertEquals($expected, $actual);
}
// TODO: Write testGet()
public function testGet() {
$this->assertEquals(false, true);
public function testGetNotFound() {
$this->request->expects($this->any())
->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()