test_no_project_cached_enabled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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
    protected 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(function (GacelaEventInterface $event): void {
31
                $this->saveInMemoryEvent($event);
32
            });
33
        });
34
    }
35
36
    public function saveInMemoryEvent(GacelaEventInterface $event): void
37
    {
38
        self::$inMemoryEvents[] = $event::class;
39
    }
40
41
    public function test_no_project_cached_enabled(): void
42
    {
43
        DocBlockResolverCache::getCacheInstance();
44
45
        self::assertSame([
46
            CustomServicesInMemoryCacheCreatedEvent::class,
47
        ], self::$inMemoryEvents);
48
    }
49
50
    public function test_no_project_cached_enabled_and_cached(): void
51
    {
52
        DocBlockResolverCache::getCacheInstance();
53
        DocBlockResolverCache::getCacheInstance();
54
55
        self::assertSame([
56
            CustomServicesInMemoryCacheCreatedEvent::class,
57
            CustomServicesCacheCachedEvent::class,
58
        ], self::$inMemoryEvents);
59
    }
60
61
    public function test_with_project_cached_enabled(): void
62
    {
63
        Config::getInstance()
64
            ->getSetupGacela()
65
            ->merge(SetupGacela::fromCallable(static function (GacelaConfig $config): void {
66
                $config->enableFileCache();
67
            }));
68
69
        DocBlockResolverCache::getCacheInstance();
70
71
        self::assertSame([
72
            CustomServicesPhpCacheCreatedEvent::class,
73
        ], self::$inMemoryEvents);
74
    }
75
}
76