From be1d95e4325776fc46f50b4026a9613a0f0ac446 Mon Sep 17 00:00:00 2001 From: Albert Borsos Date: Sat, 3 Aug 2024 14:52:18 +0200 Subject: [PATCH] add initial failing test for schemaCachingDuration --- tests/framework/db/CDbConnectionTest.php | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/framework/db/CDbConnectionTest.php b/tests/framework/db/CDbConnectionTest.php index 54c7495706..1f4293a738 100644 --- a/tests/framework/db/CDbConnectionTest.php +++ b/tests/framework/db/CDbConnectionTest.php @@ -45,6 +45,34 @@ public function testInitialized() $this->assertTrue($db->isInitialized); } + public function testSchemaCachingDuration($cachingDuration = 2) + { + $app = new TestApplication(array( + 'id' => 'testApp', + 'components' => array( + 'db' => array( + 'class' => 'CDbConnection', + 'connectionString' => 'sqlite::memory:', + 'schemaCachingDuration' => $cachingDuration, + ), + 'cache' => array( + 'class' => 'CFileCache', + ), + ), + )); + $app->db->pdoInstance->exec(file_get_contents(dirname(__FILE__) . '/data/sqlite.sql')); + $this->assertEquals($cachingDuration, $app->db->schemaCachingDuration); + $cachedSchema = $app->db->schema->getTable('posts'); + $this->assertFalse(in_array('update_time', $cachedSchema->columnNames), '`posts`.`update_time` column should not be in cached schema yet'); + $app->db->pdoInstance->exec('ALTER TABLE posts ADD COLUMN update_time TIMESTAMP'); + $cachedSchema = $app->db->schema->getTable('posts'); + $this->assertFalse(in_array('update_time', $cachedSchema->columnNames), '`posts`.`update_time` column should not be in cached schema'); + sleep($cachingDuration + 1); +// $app->db->schema->refresh(); + $cachedSchema = $app->db->schema->getTable('posts'); + $this->assertTrue(in_array('update_time', $cachedSchema->columnNames), '`posts`.`update_time` column should be in cached schema'); + } + public function testActive() { $this->assertFalse($this->_connection->active);