From d4a1eed8ae917d631a47ee3706aca3240aa87fc6 Mon Sep 17 00:00:00 2001 From: Matthew Ross Date: Mon, 9 May 2016 06:33:48 -0400 Subject: [PATCH] WIP - build will fail --- src/api/models/BaseModel.php | 1 - src/api/models/Board.php | 6 ++++++ test/api/Mocks.php | 15 +++------------ test/api/controllers/BoardsTest.php | 9 ++++++--- test/api/models/BoardTest.php | 2 +- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/api/models/BaseModel.php b/src/api/models/BaseModel.php index 04e31de..bcf1da0 100644 --- a/src/api/models/BaseModel.php +++ b/src/api/models/BaseModel.php @@ -27,7 +27,6 @@ abstract class BaseModel { try { $id = R::store($this->bean); - assert($id === $this->id); $this->loadFromBean($this->bean); } catch (Exception $ex) { $this->logger->addError('Save Error: ', [ diff --git a/src/api/models/Board.php b/src/api/models/Board.php index 4ae0691..e6d6276 100644 --- a/src/api/models/Board.php +++ b/src/api/models/Board.php @@ -33,6 +33,10 @@ class Board extends BaseModel { } public function updateBean() { + if ($this->bean === null) { + return; + } + $bean = $this->bean; $bean->name = $this->name; @@ -66,6 +70,7 @@ class Board extends BaseModel { public function loadFromBean($bean) { if (!isset($bean->id) || $bean->id === 0) { + $this->bean = null; return; } @@ -103,6 +108,7 @@ class Board extends BaseModel { $obj = json_decode($json); if (!isset($obj->id) || $obj->id === 0) { + $this->bean = null; return; } diff --git a/test/api/Mocks.php b/test/api/Mocks.php index d8500c9..b0dab50 100644 --- a/test/api/Mocks.php +++ b/test/api/Mocks.php @@ -159,24 +159,15 @@ class ContainerMock { } class RequestMock { - public $board; + public $invalidPayload = false; public function getBody() { - if ($this->board) { - return json_encode($this->board); + if ($this->invalidPayload) { + return '{}'; } return json_encode(DataMock::getBoard()); } - -} - -class BadRequestMock { - - public function getBody() { - return '{}'; - } - } class ResponseMock { diff --git a/test/api/controllers/BoardsTest.php b/test/api/controllers/BoardsTest.php index b3414b9..c0329c6 100644 --- a/test/api/controllers/BoardsTest.php +++ b/test/api/controllers/BoardsTest.php @@ -67,7 +67,10 @@ class BoardsTest extends PHPUnit_Framework_TestCase { } public function testAddBadBoard() { - $response = $this->boards->addBoard(new BadRequestMock(), + $request = new RequestMock(); + $request->invalidPayload = true; + + $response = $this->boards->addBoard($request, new ResponseMock(), null); $this->assertTrue($response->status === 'failure'); @@ -93,13 +96,13 @@ class BoardsTest extends PHPUnit_Framework_TestCase { $args['id'] = $board->id; $request = new RequestMock(); - $request->board = $board; + $request->payload = $board; $response = $this->boards->updateBoard($request, new ResponseMock(), $args); $this->assertTrue($response->status === 'success'); - $request->board = new stdClass(); + $request->payload = new stdClass(); $response = $this->boards->updateBoard($request, new ResponseMock(), $args); $this->assertTrue($response->alerts[2]['type'] === 'error'); diff --git a/test/api/models/BoardTest.php b/test/api/models/BoardTest.php index dadca2c..dcfa770 100644 --- a/test/api/models/BoardTest.php +++ b/test/api/models/BoardTest.php @@ -99,7 +99,7 @@ class BoardTest extends PHPUnit_Framework_TestCase { $this->assertTrue($bean->id === 0); $this->assertArraySubset($bean->xownColumnList, []); - $board->save(); + $this->assertTrue($board->save()); $bean = $board->getBean(); $this->assertTrue((int)$bean->id === 1);