*/ protected array $fixtures = ['core.Articles', 'core.Tags']; /** * Cache Engine Mock * * @var \Cake\Cache\CacheEngine */ protected $cache; /** * @var \Cake\Datasource\ConnectionInterface */ protected $connection; /** * setup method */ public function setUp(): void { parent::setUp(); Cache::setConfig('orm_cache', ['className' => 'Array']); $this->cache = Cache::pool('orm_cache'); $this->connection = ConnectionManager::get('test'); $this->connection->cacheMetadata('orm_cache'); } /** * Teardown */ public function tearDown(): void { $this->connection->cacheMetadata(false); parent::tearDown(); unset($this->connection); Cache::drop('orm_cache'); } /** * Test that clear enables the cache if it was disabled. */ public function testClearEnablesMetadataCache(): void { $this->connection->cacheMetadata(false); $ormCache = new SchemaCache($this->connection); $ormCache->clear(); $this->assertInstanceOf(CachedCollection::class, $this->connection->getSchemaCollection()); } /** * Test that build enables the cache if it was disabled. */ public function testBuildEnablesMetadataCache(): void { $this->connection->cacheMetadata(false); $ormCache = new SchemaCache($this->connection); $ormCache->build(); $this->assertInstanceOf(CachedCollection::class, $this->connection->getSchemaCollection()); } /** * Test build() with no args. */ public function testBuildNoArgs(): void { $ormCache = new SchemaCache($this->connection); $ormCache->build(); $this->assertNotEmpty($this->cache->get('test_articles')); } /** * Test build() with one arg. */ public function testBuildNamedModel(): void { $ormCache = new SchemaCache($this->connection); $ormCache->build('articles'); $this->assertNotEmpty($this->cache->get('test_articles')); } /** * Test build() overwrites cached data. */ public function testBuildOverwritesExistingData(): void { $this->cache->set('test_articles', 'dummy data'); $ormCache = new SchemaCache($this->connection); $ormCache->build('articles'); $this->assertNotSame('dummy data', $this->cache->get('test_articles')); } /** * Test clear() with no args. */ public function testClearNoArgs(): void { $this->cache->set('test_articles', 'dummy data'); $ormCache = new SchemaCache($this->connection); $ormCache->clear(); $this->assertFalse($this->cache->has('test_articles')); } /** * Test clear() with a model name. */ public function testClearNamedModel(): void { $this->cache->set('test_articles', 'dummy data'); $ormCache = new SchemaCache($this->connection); $ormCache->clear('articles'); $this->assertFalse($this->cache->has('test_articles')); } /** * Tests getting a schema config from a connection instance */ public function testGetSchemaWithConnectionInstance(): void { $ormCache = new SchemaCache($this->connection); $result = $ormCache->getSchema($this->connection); $this->assertInstanceOf(CachedCollection::class, $result); } }