'Array']); $this->cache = Cache::pool('orm_cache'); $this->connection = ConnectionManager::get('test'); $this->connection->cacheMetadata('orm_cache'); } /** * Teardown * * @return void */ public function tearDown(): void { parent::tearDown(); $this->connection->cacheMetadata(false); unset($this->connection); Cache::drop('orm_cache'); } /** * Test that clear enables the cache if it was disabled. * * @return void */ public function testClearEnablesMetadataCache() { $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. * * @return void */ public function testBuildEnablesMetadataCache() { $this->connection->cacheMetadata(false); $ormCache = new SchemaCache($this->connection); $ormCache->build(); $this->assertInstanceOf(CachedCollection::class, $this->connection->getSchemaCollection()); } /** * Test build() with no args. * * @return void */ public function testBuildNoArgs() { $ormCache = new SchemaCache($this->connection); $ormCache->build(); $this->assertNotEmpty($this->cache->get('test_articles')); } /** * Test build() with one arg. * * @return void */ public function testBuildNamedModel() { $ormCache = new SchemaCache($this->connection); $ormCache->build('articles'); $this->assertNotEmpty($this->cache->get('test_articles')); } /** * Test build() overwrites cached data. * * @return void */ public function testBuildOverwritesExistingData() { $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. * * @return void */ public function testClearNoArgs() { $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. * * @return void */ public function testClearNamedModel() { $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 * * @return void */ public function testGetSchemaWithConnectionInstance() { $ormCache = new SchemaCache($this->connection); $result = $ormCache->getSchema($this->connection); $this->assertInstanceOf(CachedCollection::class, $result); } }