Skip to content

Commit

Permalink
add initial failing test for schemaCachingDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
albertborsos committed Aug 3, 2024
1 parent b2c129b commit 5a9d698
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/framework/db/CDbConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ public function testInitialized()
$this->assertTrue($db->isInitialized);
}

public function testSchemaCachingDuration($cachingDuration = 2)
{
$app = new TestApplication([
'id' => 'testApp',
'components' => [
'db' => [
'class' => 'CDbConnection',
'connectionString' => 'sqlite::memory:',
'schemaCachingDuration' => $cachingDuration,
],
'cache' => [
'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);
Expand Down

0 comments on commit 5a9d698

Please sign in to comment.