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