@@ -18,13 +18,13 @@ |
||
18 | 18 | |
19 | 19 | switch ($driver) { |
20 | 20 | case 'sqlite': |
21 | - $dsn = $driver.'::memory:'; |
|
21 | + $dsn = $driver . '::memory:'; |
|
22 | 22 | break; |
23 | 23 | case 'mysql': |
24 | 24 | case 'postgres': |
25 | - if(strcasecmp($driver, 'postgres') == 0) $driver="pgsql"; |
|
26 | - $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME']; |
|
27 | - if(isset($config['PORT'])) $dsn .= ';port='.$config['PORT']; |
|
25 | + if (strcasecmp($driver, 'postgres') == 0) $driver = "pgsql"; |
|
26 | + $dsn = $driver . ':host=' . $config['HOSTNAME'] . ';dbname=' . $config['DBNAME']; |
|
27 | + if (isset($config['PORT'])) $dsn .= ';port=' . $config['PORT']; |
|
28 | 28 | break; |
29 | 29 | default: |
30 | 30 | throw new DatabaseDriverNotSupportedException; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function getTableName() |
67 | 67 | { |
68 | 68 | $className = explode('\\', get_called_class()); |
69 | - $table = strtolower(end($className) .'s'); |
|
69 | + $table = strtolower(end($className) . 's'); |
|
70 | 70 | return $table; |
71 | 71 | } |
72 | 72 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $sqlStatement = $this->databaseConnection->prepare($sql); |
96 | 96 | $sqlStatement->setFetchMode($this->databaseConnection::FETCH_CLASS, get_called_class()); |
97 | 97 | $sqlStatement->execute(); |
98 | - if($sqlStatement->rowCount() < 1){ |
|
98 | + if ($sqlStatement->rowCount() < 1) { |
|
99 | 99 | throw new ModelNotFoundException($id); |
100 | 100 | } |
101 | 101 | return $sqlStatement->fetch(); |
@@ -135,15 +135,15 @@ discard block |
||
135 | 135 | { |
136 | 136 | |
137 | 137 | $bindNameParameters = []; |
138 | - $sqlUpdate = "UPDATE " . $this->getTableName() . " SET " ; |
|
138 | + $sqlUpdate = "UPDATE " . $this->getTableName() . " SET "; |
|
139 | 139 | foreach ($this->properties as $columnName => $columnValue) { |
140 | - if($columnName == 'id') continue; |
|
140 | + if ($columnName == 'id') continue; |
|
141 | 141 | $bindColumnName = ':' . $columnName; |
142 | 142 | $sqlUpdate .= "$columnName = $bindColumnName,"; |
143 | 143 | $bindNameParameters[$bindColumnName] = $columnValue; |
144 | 144 | } |
145 | 145 | //Remove the last comma in sql command then join it to the other query part. |
146 | - $sqlUpdate = substr($sqlUpdate, 0, -1)." WHERE id = :id"; |
|
146 | + $sqlUpdate = substr($sqlUpdate, 0, -1) . " WHERE id = :id"; |
|
147 | 147 | $sqlStatement = $this->databaseConnection->prepare($sqlUpdate); |
148 | 148 | $sqlStatement->bindValue(":id", $this->properties['id']); |
149 | 149 | $sqlStatement->execute($bindNameParameters); |
@@ -161,19 +161,19 @@ discard block |
||
161 | 161 | $columnNames = ""; |
162 | 162 | $columnValues = ""; |
163 | 163 | $bindNameParameters = []; |
164 | - $sqlCreate = "INSERT" . " INTO " . $this->getTableName()." ("; |
|
164 | + $sqlCreate = "INSERT" . " INTO " . $this->getTableName() . " ("; |
|
165 | 165 | foreach ($this->properties as $columnName => $columnValue) { |
166 | 166 | |
167 | 167 | $bindColumnName = ':' . $columnName; |
168 | - $columnNames .= $columnName.","; |
|
169 | - $columnValues .= $bindColumnName.","; |
|
168 | + $columnNames .= $columnName . ","; |
|
169 | + $columnValues .= $bindColumnName . ","; |
|
170 | 170 | $bindNameParameters[$bindColumnName] = $columnValue; |
171 | 171 | } |
172 | 172 | // Remove ending comma and whitespace. |
173 | 173 | $columnNames = substr($columnNames, 0, -1); |
174 | 174 | $columnValues = substr($columnValues, 0, -1); |
175 | 175 | |
176 | - $sqlCreate .= $columnNames.') VALUES (' .$columnValues.')'; |
|
176 | + $sqlCreate .= $columnNames . ') VALUES (' . $columnValues . ')'; |
|
177 | 177 | $sqlStatement = $this->databaseConnection->prepare($sqlCreate); |
178 | 178 | $sqlStatement->execute($bindNameParameters); |
179 | 179 | return $sqlStatement->rowCount(); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function delete($id) |
210 | 210 | { |
211 | - $sql = "DELETE" . " FROM " . self::getTableName()." WHERE id = ". $id; |
|
211 | + $sql = "DELETE" . " FROM " . self::getTableName() . " WHERE id = " . $id; |
|
212 | 212 | $sqlStatment = $this->databaseConnection->prepare($sql); |
213 | 213 | $sqlStatment->execute(); |
214 | 214 | return ($sqlStatment->rowCount() > 0) ? true : false; |
@@ -26,21 +26,21 @@ discard block |
||
26 | 26 | |
27 | 27 | public function testCreateDatabaseSourceStringReturnsCorrectPostgresDatabaseSourceString() |
28 | 28 | { |
29 | - $this->config['DRIVER']= 'postgres'; |
|
29 | + $this->config['DRIVER'] = 'postgres'; |
|
30 | 30 | $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config); |
31 | 31 | $this->assertEquals("pgsql:host=localhost;dbname=Pyjac", $dsn); |
32 | 32 | } |
33 | 33 | |
34 | 34 | public function testCreateDatabaseSourceStringReturnsCorrectMYSqlDatabaseSourceString() |
35 | 35 | { |
36 | - $this->config['DRIVER']= 'mysql'; |
|
36 | + $this->config['DRIVER'] = 'mysql'; |
|
37 | 37 | $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config); |
38 | 38 | $this->assertEquals("mysql:host=localhost;dbname=Pyjac", $dsn); |
39 | 39 | } |
40 | 40 | |
41 | 41 | public function testCreateDatabaseSourceStringReturnsCorrectSQLiteDatabaseSourceString() |
42 | 42 | { |
43 | - $this->config['DRIVER']= 'sqlite'; |
|
43 | + $this->config['DRIVER'] = 'sqlite'; |
|
44 | 44 | $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config); |
45 | 45 | $this->assertEquals("sqlite::memory:", $dsn); |
46 | 46 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function testCreateDatabaseSourceStringThrowsDatabaseDriverNotSupportedExceptionWhenUnknownDriverIsPassed() |
52 | 52 | { |
53 | - $this->config['DRIVER']= 'pyjac'; |
|
53 | + $this->config['DRIVER'] = 'pyjac'; |
|
54 | 54 | $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config); |
55 | 55 | } |
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | |
14 | 14 | |
15 | - public function setUp(){ |
|
15 | + public function setUp() { |
|
16 | 16 | $databaseConnectionStringFactory = |
17 | 17 | m::mock('Pyjac\ORM\DatabaseConnectionStringFactoryInterface'); |
18 | 18 | $databaseConnectionStringFactory->shouldReceive('createDatabaseSourceString') |
@@ -6,26 +6,26 @@ |
||
6 | 6 | { |
7 | 7 | protected $model; |
8 | 8 | |
9 | - public function setUp(){ |
|
10 | - $this->model = $this->getMockForAbstractClass('Pyjac\ORM\Model'); |
|
9 | + public function setUp() { |
|
10 | + $this->model = $this->getMockForAbstractClass('Pyjac\ORM\Model'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | public function testGetTableNameReturnsCorrectTableName() |
14 | 14 | { |
15 | 15 | $this->model->expects($this->any()) |
16 | 16 | ->method('getTableName') |
17 | - ->will($this->returnValue(strtolower(get_class($this->model).'s'))); |
|
17 | + ->will($this->returnValue(strtolower(get_class($this->model) . 's'))); |
|
18 | 18 | |
19 | - $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model).'s')); |
|
19 | + $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model) . 's')); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function testGetTableNameReturnsCorrectTableName2() |
23 | 23 | { |
24 | 24 | $this->model->expects($this->any()) |
25 | 25 | ->method('getTableName') |
26 | - ->will($this->returnValue(strtolower(get_class($this->model).'s'))); |
|
26 | + ->will($this->returnValue(strtolower(get_class($this->model) . 's'))); |
|
27 | 27 | |
28 | - $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model).'s')); |
|
28 | + $this->assertEquals($this->model->getTableName(), strtolower(get_class($this->model) . 's')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | } |
32 | 32 | \ No newline at end of file |