Fix #18590: Fix yii\web\UrlManager to instantiate cache only when it's actually needed

This commit is contained in:
Bizley
2021-04-10 12:02:23 +02:00
committed by GitHub
parent 5ad809e815
commit a6dba47963
3 changed files with 49 additions and 15 deletions

View File

@ -837,4 +837,25 @@ class UrlManagerCreateUrlTest extends TestCase
$this->assertInstanceOf(UrlRule::className(), $urlManager->rules[0]);
$this->assertInstanceOf(CachedUrlRule::className(), $cachedUrlManager->rules[0]);
}
public function testNotEnsuringCacheForEmptyRuleset()
{
$this->mockWebApplication([
'components' => [
'cache' => ArrayCache::className(),
],
]);
// no rules - don't ensure cache
$urlManager = $this->getUrlManager([
'cache' => 'cache',
'rules' => [],
]);
$this->assertSame('cache', $urlManager->cache);
// with rules - ensure cache
$urlManager = $this->getUrlManager([
'cache' => 'cache',
'rules' => ['/' => 'site/index'],
]);
$this->assertInstanceOf(ArrayCache::className(), $urlManager->cache);
}
}