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 = []; |
|
|
|
|
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
|
|
|
|
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..