Skip to content

Commit 7c1932f

Browse files
authored
Avoid deprecated direct access to driver and dbh property (#81)
1 parent 16021a8 commit 7c1932f

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

tests/unit/Codeception/Module/Db/AbstractDbTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ public function testConnectionIsKeptForTheWholeSuite()
4646
$this->module->_before($testCase1);
4747
// Save these object instances IDs
4848
$driverAndConn1 = [
49-
$this->module->driver,
50-
$this->module->dbh
49+
$this->module->_getDriver(),
50+
$this->module->_getDbh()
5151
];
5252
$this->module->_after($testCase1);
5353

5454
// Simulate a second test that runs
5555
$this->module->_before($testCase2);
5656

5757
$driverAndConn2 = [
58-
$this->module->driver,
59-
$this->module->dbh
58+
$this->module->_getDriver(),
59+
$this->module->_getDbh()
6060
];
6161
$this->module->_after($testCase2);
6262
$this->assertSame($driverAndConn2, $driverAndConn1);
@@ -157,8 +157,8 @@ public function testHaveInDatabaseWithCompositePrimaryKey()
157157
{
158158
$insertQuery = 'INSERT INTO composite_pk (group_id, id, status) VALUES (?, ?, ?)';
159159
//this test checks that module does not delete columns by partial primary key
160-
$this->module->driver->executeQuery($insertQuery, [1, 2, 'test']);
161-
$this->module->driver->executeQuery($insertQuery, [2, 1, 'test2']);
160+
$this->module->_getDriver()->executeQuery($insertQuery, [1, 2, 'test']);
161+
$this->module->_getDriver()->executeQuery($insertQuery, [2, 1, 'test2']);
162162

163163
$testData = ['id' => 2, 'group_id' => 2, 'status' => 'test3'];
164164
$this->module->haveInDatabase('composite_pk', $testData);

tests/unit/Codeception/Module/Db/MySqlDbTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ public function testConnectionIsResetOnEveryTestWhenReconnectIsTrue()
4949
// Simulate a test that runs
5050
$this->module->_before($testCase1);
5151

52-
$connection1 = $this->module->dbh->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
52+
$connection1 = $this->module->_getDbh()->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
5353
$this->module->_after($testCase1);
5454

5555
// Simulate a second test that runs
5656
$this->module->_before($testCase2);
5757

58-
$connection2 = $this->module->dbh->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
58+
$connection2 = $this->module->_getDbh()->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
5959
$this->module->_after($testCase2);
6060
$this->module->_afterSuite();
6161

6262
$this->module->_setConfig(['reconnect' => true]);
6363

6464
$this->module->_before($testCase3);
6565

66-
$connection3 = $this->module->dbh->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
66+
$connection3 = $this->module->_getDbh()->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_COLUMN);
6767
$this->module->_after($testCase3);
6868

6969
$this->assertSame($connection1, $connection2);
@@ -81,7 +81,7 @@ public function testInitialQueriesAreExecuted()
8181
$this->module->_reconfigure($config);
8282
$this->module->_before(Stub::makeEmpty(TestInterface::class));
8383

84-
$usedDatabaseName = $this->module->dbh->query('SELECT DATABASE();')->fetch(PDO::FETCH_COLUMN);
84+
$usedDatabaseName = $this->module->_getDbh()->query('SELECT DATABASE();')->fetch(PDO::FETCH_COLUMN);
8585

8686
$this->assertSame($dbName, $usedDatabaseName);
8787
}

tests/unit/Codeception/Module/Db/SqliteDbTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ public function testConnectionIsResetOnEveryTestWhenReconnectIsTrue()
4040
// Simulate a test that runs
4141
$this->module->_before($testCase1);
4242

43-
$connection1 = spl_object_hash($this->module->dbh);
43+
$connection1 = spl_object_hash($this->module->_getDbh());
4444
$this->module->_after($testCase1);
4545

4646
// Simulate a second test that runs
4747
$this->module->_before($testCase2);
4848

49-
$connection2 = spl_object_hash($this->module->dbh);
49+
$connection2 = spl_object_hash($this->module->_getDbh());
5050
$this->module->_after($testCase2);
5151
$this->module->_afterSuite();
5252

5353
$this->module->_setConfig(['reconnect' => true]);
5454

5555
$this->module->_before($testCase3);
5656

57-
$connection3 = spl_object_hash($this->module->dbh);
57+
$connection3 = spl_object_hash($this->module->_getDbh());
5858
$this->module->_after($testCase3);
5959

6060
$this->assertSame($connection1, $connection2);

0 commit comments

Comments
 (0)