Skip to content

Commit

Permalink
Add tests for DocBlockResolverCache
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Jul 29, 2023
1 parent a6c8e7a commit 369ff30
Showing 1 changed file with 74 additions and 0 deletions.
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);
}
}

0 comments on commit 369ff30

Please sign in to comment.