-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6c8e7a
commit 369ff30
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
tests/Integration/Framework/DocBlockResolver/DocBlockResolverCacheTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GacelaTest\Integration\Framework\DocBlockResolver; | ||
|
||
use Gacela\Framework\Bootstrap\GacelaConfig; | ||
use Gacela\Framework\Bootstrap\SetupGacela; | ||
use Gacela\Framework\Config\Config; | ||
use Gacela\Framework\DocBlockResolver\DocBlockResolverCache; | ||
use Gacela\Framework\Event\ClassResolver\Cache\CustomServicesCacheCachedEvent; | ||
use Gacela\Framework\Event\ClassResolver\Cache\CustomServicesInMemoryCacheCreatedEvent; | ||
use Gacela\Framework\Event\ClassResolver\Cache\CustomServicesPhpCacheCreatedEvent; | ||
use Gacela\Framework\Event\GacelaEventInterface; | ||
use Gacela\Framework\Gacela; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class DocBlockResolverCacheTest extends TestCase | ||
{ | ||
/** @var list<class-string> */ | ||
private static array $inMemoryEvents = []; | ||
|
||
public function setUp(): void | ||
{ | ||
self::$inMemoryEvents = []; | ||
|
||
Gacela::bootstrap(__DIR__, function (GacelaConfig $config): void { | ||
$config->resetInMemoryCache(); | ||
|
||
$config->registerGenericListener([$this, 'saveInMemoryEvent']); | ||
}); | ||
} | ||
|
||
public function saveInMemoryEvent(GacelaEventInterface $event): void | ||
{ | ||
self::$inMemoryEvents[] = $event::class; | ||
} | ||
|
||
public function test_no_project_cached_enabled(): void | ||
{ | ||
DocBlockResolverCache::getCacheInstance(); | ||
|
||
self::assertEquals([ | ||
CustomServicesInMemoryCacheCreatedEvent::class, | ||
], self::$inMemoryEvents); | ||
} | ||
|
||
public function test_no_project_cached_enabled_and_cached(): void | ||
{ | ||
DocBlockResolverCache::getCacheInstance(); | ||
DocBlockResolverCache::getCacheInstance(); | ||
|
||
self::assertEquals([ | ||
CustomServicesInMemoryCacheCreatedEvent::class, | ||
CustomServicesCacheCachedEvent::class, | ||
], self::$inMemoryEvents); | ||
} | ||
|
||
public function test_with_project_cached_enabled(): void | ||
{ | ||
Config::getInstance() | ||
->getSetupGacela() | ||
->combine(SetupGacela::fromCallable(function (GacelaConfig $config): void { | ||
$config->enableFileCache(); | ||
$config->registerGenericListener([$this, 'saveInMemoryEvent']); | ||
})); | ||
|
||
DocBlockResolverCache::getCacheInstance(); | ||
|
||
self::assertEquals([ | ||
CustomServicesPhpCacheCreatedEvent::class, | ||
], self::$inMemoryEvents); | ||
} | ||
} |