| Conditions | 2 |
| Paths | 2 |
| Total Lines | 77 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 22 | public function testPreparedStatements() |
||
| 23 | { |
||
| 24 | if (!(DB::get_connector() instanceof PDOConnector)) { |
||
| 25 | $this->markTestSkipped('This test requires the current DB connector is PDO'); |
||
| 26 | } |
||
| 27 | |||
| 28 | // Test preparation of equivalent statemetns |
||
| 29 | $result1 = DB::get_connector()->preparedQuery( |
||
| 30 | 'SELECT "Sort", "Title" FROM "MySQLDatabaseTest_Data" WHERE "Sort" > ? ORDER BY "Sort"', |
||
| 31 | array(0) |
||
| 32 | ); |
||
| 33 | |||
| 34 | $result2 = DB::get_connector()->preparedQuery( |
||
| 35 | 'SELECT "Sort", "Title" FROM "MySQLDatabaseTest_Data" WHERE "Sort" > ? ORDER BY "Sort"', |
||
| 36 | array(2) |
||
| 37 | ); |
||
| 38 | $this->assertInstanceOf(PDOQuery::class, $result1); |
||
| 39 | $this->assertInstanceOf(PDOQuery::class, $result2); |
||
| 40 | |||
| 41 | // Also select non-prepared statement |
||
| 42 | $result3 = DB::get_connector()->query('SELECT "Sort", "Title" FROM "MySQLDatabaseTest_Data" ORDER BY "Sort"'); |
||
| 43 | $this->assertInstanceOf(PDOQuery::class, $result3); |
||
| 44 | |||
| 45 | // Iterating one level should not buffer, but return the right result |
||
| 46 | $this->assertEquals( |
||
| 47 | array( |
||
| 48 | 'Sort' => 1, |
||
| 49 | 'Title' => 'First Item' |
||
| 50 | ), |
||
| 51 | $result1->next() |
||
| 52 | ); |
||
| 53 | $this->assertEquals( |
||
| 54 | array( |
||
| 55 | 'Sort' => 2, |
||
| 56 | 'Title' => 'Second Item' |
||
| 57 | ), |
||
| 58 | $result1->next() |
||
| 59 | ); |
||
| 60 | |||
| 61 | // Test first |
||
| 62 | $this->assertEquals( |
||
| 63 | array( |
||
| 64 | 'Sort' => 1, |
||
| 65 | 'Title' => 'First Item' |
||
| 66 | ), |
||
| 67 | $result1->first() |
||
| 68 | ); |
||
| 69 | |||
| 70 | // Test seek |
||
| 71 | $result1->seek(1); |
||
| 72 | $this->assertEquals( |
||
| 73 | array( |
||
| 74 | 'Sort' => 2, |
||
| 75 | 'Title' => 'Second Item' |
||
| 76 | ), |
||
| 77 | $result1->next() |
||
| 78 | ); |
||
| 79 | |||
| 80 | // Test count |
||
| 81 | $this->assertEquals(4, $result1->numRecords()); |
||
| 82 | |||
| 83 | // Test second statement |
||
| 84 | $this->assertEquals( |
||
| 85 | array( |
||
| 86 | 'Sort' => 3, |
||
| 87 | 'Title' => 'Third Item' |
||
| 88 | ), |
||
| 89 | $result2->next() |
||
| 90 | ); |
||
| 91 | |||
| 92 | // Test non-prepared query |
||
| 93 | $this->assertEquals( |
||
| 94 | array( |
||
| 95 | 'Sort' => 1, |
||
| 96 | 'Title' => 'First Item' |
||
| 97 | ), |
||
| 98 | $result3->next() |
||
| 99 | ); |
||
| 124 |