Wrote unit tests against StackApiController -> get()
Signed-off-by: Ryan Fletcher <ryan.fletcher@codepassion.ca>
This commit is contained in:
committed by
Julius Härtl
parent
891fa7b7d5
commit
5719e9f134
@@ -91,10 +91,14 @@ class StackApiController extends ApiController {
|
||||
return new DataResponse($boardError['message'], $boardError['status']);
|
||||
}
|
||||
|
||||
$stack = $this->service->find($this->request->params['stackId']);
|
||||
if (is_numeric($this->request->getParam('stackId')) === false) {
|
||||
return new DataResponse('stack id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ($stack == false || $stack == null) {
|
||||
return new DataResponse("Stack not found", HTTP::STATUS_NOT_FOUND);
|
||||
$stack = $this->service->find($this->request->getParam('stackId'));
|
||||
|
||||
if ($stack === false || $stack === null) {
|
||||
return new DataResponse('stack not found', HTTP::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
return new DataResponse($stack, HTTP::STATUS_OK);
|
||||
@@ -150,7 +154,7 @@ class StackApiController extends ApiController {
|
||||
return new DataResponse($boardError['message'], $boardError['status']);
|
||||
}
|
||||
|
||||
if (is_numeric($this->request->params['stackId']) === false) {
|
||||
if (is_numeric($this->request->getParam('stackId')) === false) {
|
||||
return new DataResponse('stack id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
@@ -159,10 +163,10 @@ class StackApiController extends ApiController {
|
||||
}
|
||||
|
||||
try {
|
||||
$stack = $this->service->update($this->request->params['stackId'], $title, $this->request->getParam('boardId'), $order);
|
||||
$stack = $this->service->update($this->request->getParam('stackId'), $title, $this->request->getParam('boardId'), $order);
|
||||
|
||||
if ($stack === false || $stack === null) {
|
||||
return new DataResponse('Stack not found', HTTP::STATUS_NOT_FOUND);
|
||||
return new DataResponse('stack not found', HTTP::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
return new DataResponse($stack, HTTP::STATUS_OK);
|
||||
@@ -176,7 +180,7 @@ class StackApiController extends ApiController {
|
||||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* Delete the stack specified by $this->request->params['stackId'].
|
||||
* Delete the stack specified by $this->request->getParam('stackId').
|
||||
*/
|
||||
public function delete() {
|
||||
|
||||
@@ -186,11 +190,11 @@ class StackApiController extends ApiController {
|
||||
return new DataResponse($boardError['message'], $boardError['status']);
|
||||
}
|
||||
|
||||
if (is_numeric($this->request->params['stackId']) === false) {
|
||||
if (is_numeric($this->request->getParam('stackId')) === false) {
|
||||
return new DataResponse('stack id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$stack = $this->service->delete($this->request->params['stackId']);
|
||||
$stack = $this->service->delete($this->request->getParam('stackId'));
|
||||
|
||||
if ($stack == false || $stack == null) {
|
||||
return new DataResponse('Stack Not Found', HTTP::STATUS_NOT_FOUND);
|
||||
|
||||
@@ -48,7 +48,7 @@ class StackApiControllerTest extends \Test\TestCase {
|
||||
$this->stackService = $this->createMock(StackService::class);
|
||||
|
||||
$this->exampleStack['id'] = 345;
|
||||
$this->exampleStack['boardId'] = 245;
|
||||
$this->exampleStack['boardId'] = $this->exampleBoard['boardId'];
|
||||
$this->exampleStack['order'] = 0;
|
||||
|
||||
$this->exampleBoard['boardId'] = '89';
|
||||
@@ -110,4 +110,109 @@ class StackApiControllerTest extends \Test\TestCase {
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGet() {
|
||||
$stack = new Stack();
|
||||
$stack->setId($this->exampleStack['id']);
|
||||
$stack->setBoardId($this->exampleStack['boardId']);
|
||||
$stack->setOrder($this->exampleStack['order']);
|
||||
|
||||
$board = new Board();
|
||||
$board->setId($this->exampleBoard['boardId']);
|
||||
$this->boardService->expects($this->once())
|
||||
->method('find')
|
||||
->willReturn($board);
|
||||
|
||||
$this->stackService->expects($this->once())
|
||||
->method('find')
|
||||
->willReturn($stack);
|
||||
|
||||
$this->request->expects($this->exactly(3))
|
||||
->method('getParam')
|
||||
->withConsecutive(
|
||||
['boardId'],
|
||||
['stackId'],
|
||||
['stackId']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$this->returnValue($this->exampleBoard['boardId']),
|
||||
$this->returnValue($this->exampleStack['id']),
|
||||
$this->returnValue($this->exampleStack['id']));
|
||||
|
||||
$expected = new DataResponse($stack, HTTP::STATUS_OK);
|
||||
$actual = $this->controller->get();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetBadBoardId() {
|
||||
|
||||
$this->request->expects($this->any())
|
||||
->method('getParam')
|
||||
->with('boardId')
|
||||
->will($this->returnValue('NOT A BOARD ID'));
|
||||
|
||||
$expected = new DataResponse('board id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||
$actual = $this->controller->get();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetBoardNotFound() {
|
||||
$this->request->expects($this->any())
|
||||
->method('getParam')
|
||||
->with('boardId')
|
||||
->will($this->returnValue(9251));
|
||||
|
||||
$expected = new DataResponse('board not found', HTTP::STATUS_NOT_FOUND);
|
||||
$actual = $this->controller->get();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetStackBadStackId() {
|
||||
|
||||
$board = new Board();
|
||||
$board->setId($this->exampleBoard['boardId']);
|
||||
$this->boardService->expects($this->once())
|
||||
->method('find')
|
||||
->willReturn($board);
|
||||
|
||||
$this->request->expects($this->exactly(2))
|
||||
->method('getParam')
|
||||
->withConsecutive(
|
||||
['boardId'],
|
||||
['stackId']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$this->returnValue($this->exampleBoard['boardId']),
|
||||
$this->returnValue('not a stack id'),
|
||||
$this->returnValue('not a stack id'));
|
||||
|
||||
$expected = new DataResponse('stack id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||
$actual = $this->controller->get();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetStackNotFound() {
|
||||
|
||||
$board = new Board();
|
||||
$board->setId($this->exampleBoard['boardId']);
|
||||
$this->boardService->expects($this->once())
|
||||
->method('find')
|
||||
->willReturn($board);
|
||||
|
||||
$this->request->expects($this->exactly(3))
|
||||
->method('getParam')
|
||||
->withConsecutive(
|
||||
['boardId'],
|
||||
['stackId'],
|
||||
['stackId']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$this->returnValue($this->exampleBoard['boardId']),
|
||||
$this->returnValue(5),
|
||||
$this->returnValue(5));
|
||||
|
||||
$expected = new DataResponse('stack not found', HTTP::STATUS_NOT_FOUND);
|
||||
$actual = $this->controller->get();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user