@@ 61-69 (lines=9) @@ | ||
58 | } |
|
59 | ||
60 | ||
61 | public function testGetReturnNullWhenIdNotFoundInDatabase() |
|
62 | { |
|
63 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
64 | $this->sqlStatement->shouldReceive('setFetchMode'); |
|
65 | $this->sqlStatement->shouldReceive('execute'); |
|
66 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0); |
|
67 | ||
68 | $this->assertEquals(null, $this->model->get(1)); |
|
69 | } |
|
70 | ||
71 | public function testAllReturnsAnArrayOfObjectsWhenValuesAreInDatabase() |
|
72 | { |
|
@@ 89-96 (lines=8) @@ | ||
86 | $this->assertEquals(1, $this->model->update()); |
|
87 | } |
|
88 | ||
89 | public function testCreateObjectInDatabase() |
|
90 | { |
|
91 | $this->model->setProperties(['name' => 'pyjac', 'age' => '419']); |
|
92 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
93 | $this->sqlStatement->shouldReceive('execute'); |
|
94 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
95 | ||
96 | $this->assertEquals(1, $this->model->create()); |
|
97 | } |
|
98 | ||
99 | public function testSaveShouldCreateNewModelInDatabaseWhenIdNotPresent() |
|
@@ 125-132 (lines=8) @@ | ||
122 | $this->assertEquals($values, $this->model->getProperties()); |
|
123 | } |
|
124 | ||
125 | public function testDeleteReturnsTrueWhenModelIsSuccessfullyRemovedFromDatabase() |
|
126 | { |
|
127 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
128 | $this->sqlStatement->shouldReceive('execute'); |
|
129 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
130 | ||
131 | $this->assertEquals(true, $this->model->delete(1)); |
|
132 | } |
|
133 | ||
134 | public function testDeleteReturnsFalseWhenModelWasNotDeletedFromDatabase() |
|
135 | { |
|
@@ 134-141 (lines=8) @@ | ||
131 | $this->assertEquals(true, $this->model->delete(1)); |
|
132 | } |
|
133 | ||
134 | public function testDeleteReturnsFalseWhenModelWasNotDeletedFromDatabase() |
|
135 | { |
|
136 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
137 | $this->sqlStatement->shouldReceive('execute'); |
|
138 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0); |
|
139 | ||
140 | $this->assertEquals(false, $this->model->delete(1)); |
|
141 | } |
|
142 | ||
143 | public function testMagicMethodsReturnCorrectResult() |
|
144 | { |