diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 5f678e5114d7..53e5dad1b351 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -258,14 +258,14 @@ abstract class BaseConnection implements ConnectionInterface * * @var float */ - protected $connectTime; + protected $connectTime = 0.0; /** * How long it took to establish connection. * * @var float */ - protected $connectDuration; + protected $connectDuration = 0.0; /** * If true, no queries will actually be diff --git a/tests/system/Database/BaseConnectionTest.php b/tests/system/Database/BaseConnectionTest.php index 7d2352a0e9b2..9bb8ddee1499 100644 --- a/tests/system/Database/BaseConnectionTest.php +++ b/tests/system/Database/BaseConnectionTest.php @@ -123,6 +123,16 @@ public function testStoresConnectionTimings() $this->assertGreaterThan(0.0, $db->getConnectDuration()); } + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/5535 + */ + public function testStoresConnectionTimingsNotConnected() + { + $db = new MockConnection($this->options); + + $this->assertSame('0.000000', $db->getConnectDuration()); + } + public function testMagicIssetTrue() { $db = new MockConnection($this->options);