|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GacelaTest\Integration\Framework\DocBlockResolverAware; |
|
6
|
|
|
|
|
7
|
|
|
use Gacela\Framework\Bootstrap\GacelaConfig; |
|
8
|
|
|
use Gacela\Framework\ClassResolver\Cache\CustomServicesPhpCache; |
|
9
|
|
|
use Gacela\Framework\ClassResolver\Cache\GacelaFileCache; |
|
10
|
|
|
use Gacela\Framework\Event\GacelaEventInterface; |
|
11
|
|
|
use Gacela\Framework\Gacela; |
|
12
|
|
|
use GacelaTest\Feature\Util\DirectoryUtil; |
|
13
|
|
|
use PHPUnit\Framework\Attributes\Depends; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
final class DocBlockResolverCustomServicesAwareTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
private const CACHE_DIR = __DIR__ . DIRECTORY_SEPARATOR . '.gacela'; |
|
19
|
|
|
|
|
20
|
|
|
public static function setUpBeforeClass(): void |
|
21
|
|
|
{ |
|
22
|
|
|
DirectoryUtil::removeDir(self::CACHE_DIR); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
protected function setUp(): void |
|
26
|
|
|
{ |
|
27
|
|
|
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { |
|
28
|
|
|
$config->resetInMemoryCache(); |
|
29
|
|
|
$config->enableFileCache(self::CACHE_DIR); |
|
30
|
|
|
$config->addAppConfigKeyValue(GacelaFileCache::KEY_ENABLED, true); |
|
31
|
|
|
$config->registerGenericListener(static function (GacelaEventInterface $event): void { |
|
|
|
|
|
|
32
|
|
|
// dump('Triggered -> ' . \get_class($event)); # useful for debugging |
|
33
|
|
|
}); |
|
34
|
|
|
}); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function test_existing_service(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$dummy = new DummyDocBlockResolverAware(); |
|
40
|
|
|
$actual = $dummy->getRepository()->findName(); |
|
41
|
|
|
|
|
42
|
|
|
self::assertCount(1, CustomServicesPhpCache::all()); |
|
43
|
|
|
self::assertSame('name', $actual); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
#[Depends('test_existing_service')] |
|
47
|
|
|
public function test_existing_service_cached(): void |
|
48
|
|
|
{ |
|
49
|
|
|
self::assertCount(1, CustomServicesPhpCache::all()); |
|
50
|
|
|
|
|
51
|
|
|
$dummy = new DummyDocBlockResolverAware(); |
|
52
|
|
|
$dummy->getRepository()->findName(); |
|
53
|
|
|
$dummy->getRepository()->findName(); |
|
54
|
|
|
|
|
55
|
|
|
self::assertCount(1, CustomServicesPhpCache::all()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function test_non_existing_service(): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->expectExceptionMessage('Missing the concrete return type for the method `getRepository()`'); |
|
61
|
|
|
|
|
62
|
|
|
$dummy = new BadDummyDocBlockResolverAware(); |
|
63
|
|
|
$dummy->getRepository(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.