@@ -13,21 +13,21 @@ discard block |
||
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Store instance of database connection used. |
16 | - * @var [type] |
|
17 | - */ |
|
16 | + * @var [type] |
|
17 | + */ |
|
18 | 18 | protected $databaseConnection; |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * The id of the model. |
22 | 22 | * |
23 | 23 | * @property string $id |
24 | - */ |
|
24 | + */ |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Create a model instance. |
28 | 28 | * |
29 | 29 | */ |
30 | - public function __construct(DatabaseConnectionInterface $databaseConnection = null) |
|
30 | + public function __construct(DatabaseConnectionInterface $databaseConnection = null) |
|
31 | 31 | { |
32 | 32 | if($databaseConnection == null){ |
33 | 33 | $this->databaseConnection = DatabaseConnection::getInstance()->databaseConnection; |
@@ -37,19 +37,19 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * Sets into $properties the $key => $value pairs |
39 | 39 | * |
40 | - * @param string $key |
|
41 | - * @param string $val |
|
42 | - * |
|
43 | - */ |
|
40 | + * @param string $key |
|
41 | + * @param string $val |
|
42 | + * |
|
43 | + */ |
|
44 | 44 | public function __set($key, $val) |
45 | 45 | { |
46 | 46 | $this->properties[$key] = $val; |
47 | 47 | } |
48 | 48 | /** |
49 | - * @param string $key |
|
50 | - * |
|
51 | - * @return array |
|
52 | - */ |
|
49 | + * @param string $key |
|
50 | + * |
|
51 | + * @return array |
|
52 | + */ |
|
53 | 53 | public function __get($key) |
54 | 54 | { |
55 | 55 | return $this->properties[$key]; |
@@ -59,24 +59,24 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return array |
61 | 61 | */ |
62 | - public function getProperties() |
|
63 | - { |
|
64 | - return $this->properties; |
|
65 | - } |
|
62 | + public function getProperties() |
|
63 | + { |
|
64 | + return $this->properties; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Set model properties. |
|
67 | + /** |
|
68 | + * Set model properties. |
|
69 | + * |
|
70 | + */ |
|
71 | + public function setProperties(array $properties) |
|
72 | + { |
|
73 | + $this->properties = $properties; |
|
74 | + } |
|
75 | + /** |
|
76 | + * Gets the name of the child class with a 's'. |
|
69 | 77 | * |
78 | + * @return string |
|
70 | 79 | */ |
71 | - public function setProperties(array $properties) |
|
72 | - { |
|
73 | - $this->properties = $properties; |
|
74 | - } |
|
75 | - /** |
|
76 | - * Gets the name of the child class with a 's'. |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | 80 | public function getTableName() |
81 | 81 | { |
82 | 82 | $className = explode('\\', get_called_class()); |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | return $table; |
85 | 85 | } |
86 | 86 | /** |
87 | - * Find the particular model with the passed id. |
|
88 | - * |
|
89 | - * @param int $id |
|
90 | - * |
|
91 | - * @return object |
|
92 | - */ |
|
87 | + * Find the particular model with the passed id. |
|
88 | + * |
|
89 | + * @param int $id |
|
90 | + * |
|
91 | + * @return object |
|
92 | + */ |
|
93 | 93 | public static function find($id) |
94 | 94 | { |
95 | 95 | $model = new static; |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | - * Get the particular model with the passed id. |
|
101 | - * |
|
102 | - * @param int $id |
|
103 | - * |
|
104 | - * @return object |
|
105 | - */ |
|
100 | + * Get the particular model with the passed id. |
|
101 | + * |
|
102 | + * @param int $id |
|
103 | + * |
|
104 | + * @return object |
|
105 | + */ |
|
106 | 106 | public function get($id) |
107 | 107 | { |
108 | 108 | $sql = "SELECT * FROM {$this->getTableName()} WHERE id={$id}"; |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | - * Get all the models from the database. |
|
120 | - * |
|
121 | - * @return array |
|
122 | - */ |
|
119 | + * Get all the models from the database. |
|
120 | + * |
|
121 | + * @return array |
|
122 | + */ |
|
123 | 123 | public static function getAll() |
124 | 124 | { |
125 | 125 | $model = new static; |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | - * Returns all the models from the database. |
|
131 | - * |
|
132 | - * @return array |
|
133 | - */ |
|
130 | + * Returns all the models from the database. |
|
131 | + * |
|
132 | + * @return array |
|
133 | + */ |
|
134 | 134 | public function all() |
135 | 135 | { |
136 | 136 | $sql = "SELECT * FROM {$this->getTableName()}"; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * Update the model in the database. |
145 | 145 | * |
146 | 146 | * @return int |
147 | - */ |
|
147 | + */ |
|
148 | 148 | public function update() |
149 | 149 | { |
150 | 150 | |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | - * Insert the model values into the database. |
|
169 | - * |
|
170 | - * @return int |
|
171 | - */ |
|
168 | + * Insert the model values into the database. |
|
169 | + * |
|
170 | + * @return int |
|
171 | + */ |
|
172 | 172 | public function create() |
173 | 173 | { |
174 | 174 | |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | return isset($this->properties['id']) ? $this->update() : $this->create(); |
204 | 204 | } |
205 | 205 | |
206 | - /** |
|
207 | - * Delete a model from the database. |
|
208 | - * @param int $id |
|
209 | - * @return boolean |
|
210 | - */ |
|
206 | + /** |
|
207 | + * Delete a model from the database. |
|
208 | + * @param int $id |
|
209 | + * @return boolean |
|
210 | + */ |
|
211 | 211 | public static function destroy($id) |
212 | 212 | { |
213 | 213 | $model = new static; |
@@ -5,86 +5,86 @@ |
||
5 | 5 | |
6 | 6 | class DatabaseConnectionTest extends PHPUnit_Framework_TestCase |
7 | 7 | { |
8 | - /** |
|
9 | - * Instance of DatabaseConnection used in test. |
|
10 | - */ |
|
11 | - protected $databaseConnection; |
|
8 | + /** |
|
9 | + * Instance of DatabaseConnection used in test. |
|
10 | + */ |
|
11 | + protected $databaseConnection; |
|
12 | 12 | |
13 | 13 | |
14 | 14 | |
15 | - public function setUp(){ |
|
16 | - $databaseConnectionStringFactory = |
|
15 | + public function setUp(){ |
|
16 | + $databaseConnectionStringFactory = |
|
17 | 17 | m::mock('Pyjac\ORM\DatabaseConnectionStringFactoryInterface'); |
18 | 18 | $databaseConnectionStringFactory->shouldReceive('createDatabaseSourceString') |
19 | - ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:'); |
|
19 | + ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:'); |
|
20 | 20 | |
21 | 21 | $this->databaseConnection = new DatabaseConnection($databaseConnectionStringFactory); |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - public function testCreateConnectionReturnsDatabaseConnection() |
|
25 | - { |
|
26 | - $dbInstance = $this->databaseConnection->createConnection('sqlite::memory:'); |
|
24 | + public function testCreateConnectionReturnsDatabaseConnection() |
|
25 | + { |
|
26 | + $dbInstance = $this->databaseConnection->createConnection('sqlite::memory:'); |
|
27 | 27 | |
28 | - $this->assertInstanceOf('PDO', $dbInstance); |
|
28 | + $this->assertInstanceOf('PDO', $dbInstance); |
|
29 | 29 | |
30 | - } |
|
30 | + } |
|
31 | 31 | |
32 | - public function testGetInstanceReturnsCorrectInstance() |
|
33 | - { |
|
34 | - $dbInstance = DatabaseConnection::getInstance(); |
|
32 | + public function testGetInstanceReturnsCorrectInstance() |
|
33 | + { |
|
34 | + $dbInstance = DatabaseConnection::getInstance(); |
|
35 | 35 | |
36 | - $this->assertInstanceOf('Pyjac\ORM\DatabaseConnection', $dbInstance); |
|
36 | + $this->assertInstanceOf('Pyjac\ORM\DatabaseConnection', $dbInstance); |
|
37 | 37 | |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - public function testSetOptionsAndGetOptionsReturnsCorrectValue() |
|
41 | - { |
|
42 | - $options = [ |
|
43 | - PDO::ATTR_CASE => PDO::CASE_NATURAL, |
|
44 | - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
|
45 | - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, |
|
46 | - PDO::ATTR_STRINGIFY_FETCHES => false, |
|
47 | - PDO::ATTR_EMULATE_PREPARES => false, |
|
48 | - ]; |
|
49 | - $this->databaseConnection->setDefaultOptions($options); |
|
40 | + public function testSetOptionsAndGetOptionsReturnsCorrectValue() |
|
41 | + { |
|
42 | + $options = [ |
|
43 | + PDO::ATTR_CASE => PDO::CASE_NATURAL, |
|
44 | + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
|
45 | + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, |
|
46 | + PDO::ATTR_STRINGIFY_FETCHES => false, |
|
47 | + PDO::ATTR_EMULATE_PREPARES => false, |
|
48 | + ]; |
|
49 | + $this->databaseConnection->setDefaultOptions($options); |
|
50 | 50 | |
51 | - $this->assertEquals($this->databaseConnection->getDefaultOptions(), $options); |
|
52 | - } |
|
51 | + $this->assertEquals($this->databaseConnection->getDefaultOptions(), $options); |
|
52 | + } |
|
53 | 53 | |
54 | - public function testTryAgainIfCausedByLostConnectionCreateNewConnectionWhenReasonForExceptionIsConnectionLoss() |
|
55 | - { |
|
56 | - $e = new \Exception("Error while sending"); |
|
57 | - $result = $this->invokeMethod($this->databaseConnection, 'tryAgainIfCausedByLostConnection', [$e, 'sqlite::memory:', '', '', []]); |
|
54 | + public function testTryAgainIfCausedByLostConnectionCreateNewConnectionWhenReasonForExceptionIsConnectionLoss() |
|
55 | + { |
|
56 | + $e = new \Exception("Error while sending"); |
|
57 | + $result = $this->invokeMethod($this->databaseConnection, 'tryAgainIfCausedByLostConnection', [$e, 'sqlite::memory:', '', '', []]); |
|
58 | 58 | |
59 | - $this->assertInstanceOf('PDO', $result); |
|
60 | - } |
|
59 | + $this->assertInstanceOf('PDO', $result); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
62 | + /** |
|
63 | 63 | * @expectedException \Exception |
64 | 64 | */ |
65 | - public function testTryAgainIfCausedByLostConnectionThrowsExceptionWhenReasonForExceptionIsNotConnectionLoss() |
|
66 | - { |
|
67 | - $e = new \Exception("PHP Rocks !!!"); |
|
68 | - $result = $this->invokeMethod($this->databaseConnection, 'tryAgainIfCausedByLostConnection', [$e, 'sqlite::memory:', '', '', []]); |
|
69 | - |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Reference: https://jtreminio.com/2013/03/unit-testing-tutorial-part-3-testing-protected-private-methods-coverage-reports-and-crap/ |
|
74 | - * Call protected/private method of a class. |
|
75 | - * |
|
76 | - * @param object &$object Instantiated object that we will run method on. |
|
77 | - * @param string $methodName Method name to call |
|
78 | - * @param array $parameters Array of parameters to pass into method. |
|
79 | - * |
|
80 | - * @return mixed Method return. |
|
81 | - */ |
|
82 | - public function invokeMethod(&$object, $methodName, array $parameters = array()) |
|
83 | - { |
|
84 | - $reflection = new \ReflectionClass(get_class($object)); |
|
85 | - $method = $reflection->getMethod($methodName); |
|
86 | - $method->setAccessible(true); |
|
87 | - |
|
88 | - return $method->invokeArgs($object, $parameters); |
|
89 | - } |
|
65 | + public function testTryAgainIfCausedByLostConnectionThrowsExceptionWhenReasonForExceptionIsNotConnectionLoss() |
|
66 | + { |
|
67 | + $e = new \Exception("PHP Rocks !!!"); |
|
68 | + $result = $this->invokeMethod($this->databaseConnection, 'tryAgainIfCausedByLostConnection', [$e, 'sqlite::memory:', '', '', []]); |
|
69 | + |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Reference: https://jtreminio.com/2013/03/unit-testing-tutorial-part-3-testing-protected-private-methods-coverage-reports-and-crap/ |
|
74 | + * Call protected/private method of a class. |
|
75 | + * |
|
76 | + * @param object &$object Instantiated object that we will run method on. |
|
77 | + * @param string $methodName Method name to call |
|
78 | + * @param array $parameters Array of parameters to pass into method. |
|
79 | + * |
|
80 | + * @return mixed Method return. |
|
81 | + */ |
|
82 | + public function invokeMethod(&$object, $methodName, array $parameters = array()) |
|
83 | + { |
|
84 | + $reflection = new \ReflectionClass(get_class($object)); |
|
85 | + $method = $reflection->getMethod($methodName); |
|
86 | + $method->setAccessible(true); |
|
87 | + |
|
88 | + return $method->invokeArgs($object, $parameters); |
|
89 | + } |
|
90 | 90 | } |
91 | 91 | \ No newline at end of file |
@@ -5,23 +5,23 @@ discard block |
||
5 | 5 | |
6 | 6 | class ModelTest extends PHPUnit_Framework_TestCase |
7 | 7 | { |
8 | - /** |
|
9 | - * Instance of DatabaseConnection used in test. |
|
10 | - */ |
|
11 | - protected $databaseConnection; |
|
8 | + /** |
|
9 | + * Instance of DatabaseConnection used in test. |
|
10 | + */ |
|
11 | + protected $databaseConnection; |
|
12 | 12 | |
13 | - protected $model; |
|
13 | + protected $model; |
|
14 | 14 | |
15 | - protected $sqlStatement; |
|
15 | + protected $sqlStatement; |
|
16 | 16 | |
17 | - public function setUp(){ |
|
17 | + public function setUp(){ |
|
18 | 18 | |
19 | 19 | |
20 | - $databaseConnectionStringFactory = |
|
20 | + $databaseConnectionStringFactory = |
|
21 | 21 | m::mock('Pyjac\ORM\DatabaseConnectionStringFactoryInterface'); |
22 | 22 | |
23 | 23 | $databaseConnectionStringFactory->shouldReceive('createDatabaseSourceString') |
24 | - ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:'); |
|
24 | + ->with(['DRIVER' => 'sqlite', 'HOSTNAME' => '127.0.0.1', 'USERNAME' => '', 'PASSWORD' => '', 'DBNAME' => 'potatoORM', 'PORT' => '54320'])->once()->andReturn('sqlite::memory:'); |
|
25 | 25 | |
26 | 26 | $this->databaseConnection = m::mock('Pyjac\ORM\DatabaseConnection'); |
27 | 27 | |
@@ -30,88 +30,88 @@ discard block |
||
30 | 30 | /*$this->databaseConnection = m::mock('Pyjac\ORM\DatabaseConnection[getInstance,createConnection]',array($databaseConnectionStringFactory));*/ |
31 | 31 | $this->model = $this->getMockForAbstractClass('Pyjac\ORM\Model',[$this->databaseConnection]); |
32 | 32 | //= new DatabaseConnection($databaseConnectionStringFactory); |
33 | - } |
|
33 | + } |
|
34 | 34 | |
35 | - public function testGetTableNameReturnsCorrectTableName() |
|
35 | + public function testGetTableNameReturnsCorrectTableName() |
|
36 | 36 | { |
37 | - $this->databaseConnection->shouldReceive('createConnection')->with('sqlite::memory:')->once()->andReturn(""); |
|
37 | + $this->databaseConnection->shouldReceive('createConnection')->with('sqlite::memory:')->once()->andReturn(""); |
|
38 | 38 | $this->model->expects($this->any()) |
39 | - ->method('getTableName') |
|
40 | - ->will($this->returnValue(strtolower(get_class($this->model).'s'))); |
|
39 | + ->method('getTableName') |
|
40 | + ->will($this->returnValue(strtolower(get_class($this->model).'s'))); |
|
41 | 41 | |
42 | 42 | $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model).'s')); |
43 | 43 | } |
44 | 44 | |
45 | 45 | public function testGetReturnsAnObjectWhenIdIsFoundInDatabase() |
46 | 46 | { |
47 | - $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
48 | - $this->sqlStatement->shouldReceive('setFetchMode'); |
|
49 | - $this->sqlStatement->shouldReceive('execute'); |
|
50 | - $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
51 | - $this->sqlStatement->shouldReceive('fetch')->once()->andReturn(new stdClass); |
|
47 | + $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
48 | + $this->sqlStatement->shouldReceive('setFetchMode'); |
|
49 | + $this->sqlStatement->shouldReceive('execute'); |
|
50 | + $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
51 | + $this->sqlStatement->shouldReceive('fetch')->once()->andReturn(new stdClass); |
|
52 | 52 | |
53 | - $this->assertInstanceOf('stdClass', $this->model->get(1)); |
|
53 | + $this->assertInstanceOf('stdClass', $this->model->get(1)); |
|
54 | 54 | } |
55 | 55 | /** |
56 | 56 | * @expectedException Pyjac\ORM\Exception\ModelNotFoundException |
57 | 57 | */ |
58 | 58 | public function testGetThrowsModelNotFoundExceptionWhenIdNotFoundInDatabase() |
59 | 59 | { |
60 | - $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
61 | - $this->sqlStatement->shouldReceive('setFetchMode'); |
|
62 | - $this->sqlStatement->shouldReceive('execute'); |
|
63 | - $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0); |
|
60 | + $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
61 | + $this->sqlStatement->shouldReceive('setFetchMode'); |
|
62 | + $this->sqlStatement->shouldReceive('execute'); |
|
63 | + $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0); |
|
64 | 64 | |
65 | - $this->assertInstanceOf('stdClass', $this->model->get(1)); |
|
65 | + $this->assertInstanceOf('stdClass', $this->model->get(1)); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | public function testAllReturnsAnArrayOfObjectsWhenValuesAreInDatabase() |
69 | 69 | { |
70 | - $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
71 | - $this->sqlStatement->shouldReceive('execute'); |
|
72 | - $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]); |
|
73 | - $this->assertContainsOnlyInstancesOf('stdClass', $this->model->all()); |
|
70 | + $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
71 | + $this->sqlStatement->shouldReceive('execute'); |
|
72 | + $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]); |
|
73 | + $this->assertContainsOnlyInstancesOf('stdClass', $this->model->all()); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public function testUpdateChangesTheValueOfObjectInDatabase() |
77 | 77 | { |
78 | - $this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']); |
|
79 | - $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
80 | - $this->sqlStatement->shouldReceive('execute'); |
|
81 | - $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]); |
|
82 | - $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
78 | + $this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']); |
|
79 | + $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
80 | + $this->sqlStatement->shouldReceive('execute'); |
|
81 | + $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]); |
|
82 | + $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
83 | 83 | |
84 | - $this->assertEquals(1, $this->model->update()); |
|
84 | + $this->assertEquals(1, $this->model->update()); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | public function testCreateObjectInDatabase() |
88 | 88 | { |
89 | - $this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']); |
|
90 | - $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
91 | - $this->sqlStatement->shouldReceive('execute'); |
|
92 | - $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]); |
|
93 | - $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
89 | + $this->model->setProperties(['id' => 2, 'name' => 'pyjac', 'age' => '419']); |
|
90 | + $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
91 | + $this->sqlStatement->shouldReceive('execute'); |
|
92 | + $this->sqlStatement->shouldReceive('fetchAll')->once()->andReturn([new stdClass,new stdClass]); |
|
93 | + $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
94 | 94 | |
95 | - $this->assertEquals(1, $this->model->create()); |
|
95 | + $this->assertEquals(1, $this->model->create()); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | 99 | public function testDeleteReturnsTrueWhenModelIsSuccessfullyRemovedFromDatabase() |
100 | 100 | { |
101 | - $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
102 | - $this->sqlStatement->shouldReceive('execute'); |
|
103 | - $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
101 | + $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
102 | + $this->sqlStatement->shouldReceive('execute'); |
|
103 | + $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(1); |
|
104 | 104 | |
105 | - $this->assertEquals(true, $this->model->delete(1)); |
|
105 | + $this->assertEquals(true, $this->model->delete(1)); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | public function testDeleteReturnsFalseWhenModelWasNotDeletedFromDatabase() |
109 | 109 | { |
110 | - $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
111 | - $this->sqlStatement->shouldReceive('execute'); |
|
112 | - $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0); |
|
110 | + $this->databaseConnection->shouldReceive('prepare')->once()->andReturn($this->sqlStatement); |
|
111 | + $this->sqlStatement->shouldReceive('execute'); |
|
112 | + $this->sqlStatement->shouldReceive('rowCount')->once()->andReturn(0); |
|
113 | 113 | |
114 | - $this->assertEquals(false, $this->model->delete(1)); |
|
114 | + $this->assertEquals(false, $this->model->delete(1)); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | } |
118 | 118 | \ No newline at end of file |