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
@@ -90,11 +90,15 @@ class StackApiController extends ApiController {
|
|||||||
if ($boardError) {
|
if ($boardError) {
|
||||||
return new DataResponse($boardError['message'], $boardError['status']);
|
return new DataResponse($boardError['message'], $boardError['status']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stack = $this->service->find($this->request->params['stackId']);
|
|
||||||
|
|
||||||
if ($stack == false || $stack == null) {
|
if (is_numeric($this->request->getParam('stackId')) === false) {
|
||||||
return new DataResponse("Stack not found", HTTP::STATUS_NOT_FOUND);
|
return new DataResponse('stack id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
$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);
|
return new DataResponse($stack, HTTP::STATUS_OK);
|
||||||
@@ -150,7 +154,7 @@ class StackApiController extends ApiController {
|
|||||||
return new DataResponse($boardError['message'], $boardError['status']);
|
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);
|
return new DataResponse('stack id must be a number', HTTP::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,10 +163,10 @@ class StackApiController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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) {
|
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);
|
return new DataResponse($stack, HTTP::STATUS_OK);
|
||||||
@@ -176,7 +180,7 @@ class StackApiController extends ApiController {
|
|||||||
* @CORS
|
* @CORS
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*
|
*
|
||||||
* Delete the stack specified by $this->request->params['stackId'].
|
* Delete the stack specified by $this->request->getParam('stackId').
|
||||||
*/
|
*/
|
||||||
public function delete() {
|
public function delete() {
|
||||||
|
|
||||||
@@ -186,11 +190,11 @@ class StackApiController extends ApiController {
|
|||||||
return new DataResponse($boardError['message'], $boardError['status']);
|
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);
|
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) {
|
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);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class StackApiControllerTest extends \Test\TestCase {
|
|||||||
$this->stackService = $this->createMock(StackService::class);
|
$this->stackService = $this->createMock(StackService::class);
|
||||||
|
|
||||||
$this->exampleStack['id'] = 345;
|
$this->exampleStack['id'] = 345;
|
||||||
$this->exampleStack['boardId'] = 245;
|
$this->exampleStack['boardId'] = $this->exampleBoard['boardId'];
|
||||||
$this->exampleStack['order'] = 0;
|
$this->exampleStack['order'] = 0;
|
||||||
|
|
||||||
$this->exampleBoard['boardId'] = '89';
|
$this->exampleBoard['boardId'] = '89';
|
||||||
@@ -65,7 +65,7 @@ class StackApiControllerTest extends \Test\TestCase {
|
|||||||
$stack = new Stack();
|
$stack = new Stack();
|
||||||
$stack->setId($this->exampleStack['id']);
|
$stack->setId($this->exampleStack['id']);
|
||||||
$stack->setBoardId($this->exampleStack['boardId']);
|
$stack->setBoardId($this->exampleStack['boardId']);
|
||||||
$stack->setOrder($this->exampleStack['order']);
|
$stack->setOrder($this->exampleStack['order']);
|
||||||
$stacks = [$stack];
|
$stacks = [$stack];
|
||||||
|
|
||||||
$board = new Board();
|
$board = new Board();
|
||||||
@@ -110,4 +110,109 @@ class StackApiControllerTest extends \Test\TestCase {
|
|||||||
$this->assertEquals($expected, $actual);
|
$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