Passed
Push — main ( a6c8e7...369ff3 )
by Chema
02:57
created

DocBlockResolverCacheTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 55
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_with_project_cached_enabled() 0 14 1
A setUp() 0 8 1
A test_no_project_cached_enabled_and_cached() 0 9 1
A test_no_project_cached_enabled() 0 7 1
A saveInMemoryEvent() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Integration\Framework\DocBlockResolver;
6
7
use Gacela\Framework\Bootstrap\GacelaConfig;
8
use Gacela\Framework\Bootstrap\SetupGacela;
9
use Gacela\Framework\Config\Config;
10
use Gacela\Framework\DocBlockResolver\DocBlockResolverCache;
11
use Gacela\Framework\Event\ClassResolver\Cache\CustomServicesCacheCachedEvent;
12
use Gacela\Framework\Event\ClassResolver\Cache\CustomServicesInMemoryCacheCreatedEvent;
13
use Gacela\Framework\Event\ClassResolver\Cache\CustomServicesPhpCacheCreatedEvent;
14
use Gacela\Framework\Event\GacelaEventInterface;
15
use Gacela\Framework\Gacela;
16
use PHPUnit\Framework\TestCase;
17
18
final class DocBlockResolverCacheTest extends TestCase
19
{
20
    /** @var list<class-string> */
21
    private static array $inMemoryEvents = [];
22
23
    public function setUp(): void
24
    {
25
        self::$inMemoryEvents = [];
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type GacelaTest\Integration\F...k\DocBlockResolver\list of property $inMemoryEvents.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
26
27
        Gacela::bootstrap(__DIR__, function (GacelaConfig $config): void {
28
            $config->resetInMemoryCache();
29
30
            $config->registerGenericListener([$this, 'saveInMemoryEvent']);
31
        });
32
    }
33
34
    public function saveInMemoryEvent(GacelaEventInterface $event): void
35
    {
36
        self::$inMemoryEvents[] = $event::class;
37
    }
38
39
    public function test_no_project_cached_enabled(): void
40
    {
41
        DocBlockResolverCache::getCacheInstance();
42
43
        self::assertEquals([
44
            CustomServicesInMemoryCacheCreatedEvent::class,
45
        ], self::$inMemoryEvents);
46
    }
47
48
    public function test_no_project_cached_enabled_and_cached(): void
49
    {
50
        DocBlockResolverCache::getCacheInstance();
51
        DocBlockResolverCache::getCacheInstance();
52
53
        self::assertEquals([
54
            CustomServicesInMemoryCacheCreatedEvent::class,
55
            CustomServicesCacheCachedEvent::class,
56
        ], self::$inMemoryEvents);
57
    }
58
59
    public function test_with_project_cached_enabled(): void
60
    {
61
        Config::getInstance()
62
            ->getSetupGacela()
63
            ->combine(SetupGacela::fromCallable(function (GacelaConfig $config): void {
64
                $config->enableFileCache();
65
                $config->registerGenericListener([$this, 'saveInMemoryEvent']);
66
            }));
67
68
        DocBlockResolverCache::getCacheInstance();
69
70
        self::assertEquals([
71
            CustomServicesPhpCacheCreatedEvent::class,
72
        ], self::$inMemoryEvents);
73
    }
74
}
75