@@ 59-67 (lines=9) @@ | ||
56 | /** |
|
57 | * @expectedException Pyjac\ORM\Exception\ModelNotFoundException |
|
58 | */ |
|
59 | public function testGetThrowsModelNotFoundExceptionWhenIdNotFoundInDatabase() |
|
60 | { |
|
61 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
62 | $this->sqlStatement->shouldReceive('setFetchMode'); |
|
63 | $this->sqlStatement->shouldReceive('execute'); |
|
64 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0); |
|
65 | ||
66 | $this->assertInstanceOf('stdClass', $this->model->get(1)); |
|
67 | } |
|
68 | ||
69 | public function testAllReturnsAnArrayOfObjectsWhenValuesAreInDatabase() |
|
70 | { |
|
@@ 97-104 (lines=8) @@ | ||
94 | $this->assertEquals(1, $this->model->create()); |
|
95 | } |
|
96 | ||
97 | public function testSaveShouldCreateNewModelInDatabaseWhenIdNotPresent() |
|
98 | { |
|
99 | $this->model->setProperties(['name' => 'pyjac', 'age' => '419']); |
|
100 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
101 | $this->sqlStatement->shouldReceive('execute'); |
|
102 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
103 | $this->assertEquals(1, $this->model->save()); |
|
104 | } |
|
105 | ||
106 | public function testSaveShouldUpdateModelInDatabaseIfIdIsPresent() |
|
107 | { |
|
@@ 123-130 (lines=8) @@ | ||
120 | $this->assertEquals($values, $this->model->getProperties()); |
|
121 | } |
|
122 | ||
123 | public function testDeleteReturnsTrueWhenModelIsSuccessfullyRemovedFromDatabase() |
|
124 | { |
|
125 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
126 | $this->sqlStatement->shouldReceive('execute'); |
|
127 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
128 | ||
129 | $this->assertEquals(true, $this->model->delete(1)); |
|
130 | } |
|
131 | ||
132 | public function testDeleteReturnsFalseWhenModelWasNotDeletedFromDatabase() |
|
133 | { |
|
@@ 132-139 (lines=8) @@ | ||
129 | $this->assertEquals(true, $this->model->delete(1)); |
|
130 | } |
|
131 | ||
132 | public function testDeleteReturnsFalseWhenModelWasNotDeletedFromDatabase() |
|
133 | { |
|
134 | $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
135 | $this->sqlStatement->shouldReceive('execute'); |
|
136 | $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0); |
|
137 | ||
138 | $this->assertEquals(false, $this->model->delete(1)); |
|
139 | } |
|
140 | ||
141 | public function testMagicMethodsReturnCorrectResult() |
|
142 | { |