From bd254fd2618aa82ef9a92957dc2a7efe45376467 Mon Sep 17 00:00:00 2001 From: Ryan Fletcher Date: Sat, 14 Jul 2018 21:57:16 -0400 Subject: [PATCH] BoardApiControllerTest wrote get() tests. Signed-off-by: Ryan Fletcher --- lib/Controller/BoardApiController.php | 8 ++-- .../controller/BoardApiControllerTest.php | 43 ++++++++++++++++--- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/lib/Controller/BoardApiController.php b/lib/Controller/BoardApiController.php index 0822822a7..5b5a82e6f 100644 --- a/lib/Controller/BoardApiController.php +++ b/lib/Controller/BoardApiController.php @@ -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); diff --git a/tests/unit/controller/BoardApiControllerTest.php b/tests/unit/controller/BoardApiControllerTest.php index 34231739f..323f3d10b 100644 --- a/tests/unit/controller/BoardApiControllerTest.php +++ b/tests/unit/controller/BoardApiControllerTest.php @@ -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()