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\DocBlockService\CustomServicesCache; |
9
|
|
|
use Gacela\Framework\Gacela; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
final class DocBlockResolverCustomServicesAwareTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public static function setUpBeforeClass(): void |
15
|
|
|
{ |
16
|
|
|
CustomServicesCache::resetCache(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function setUp(): void |
20
|
|
|
{ |
21
|
|
|
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { |
22
|
|
|
$config->addAppConfig('config/custom-services/*.php'); |
23
|
|
|
}); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function test_existing_service(): void |
27
|
|
|
{ |
28
|
|
|
$dummy = new DummyDocBlockResolverAware(); |
29
|
|
|
$actual = $dummy->getRepository()->findName(); |
30
|
|
|
|
31
|
|
|
self::assertCount(1, CustomServicesCache::getAll()); |
32
|
|
|
self::assertSame('name', $actual); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @depends test_existing_service |
37
|
|
|
*/ |
38
|
|
|
public function test_existing_service_cached(): void |
39
|
|
|
{ |
40
|
|
|
self::assertCount(1, CustomServicesCache::getAll()); |
41
|
|
|
|
42
|
|
|
$dummy = new DummyDocBlockResolverAware(); |
43
|
|
|
$dummy->getRepository()->findName(); |
44
|
|
|
$dummy->getRepository()->findName(); |
45
|
|
|
|
46
|
|
|
self::assertCount(1, CustomServicesCache::getAll()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function test_non_existing_service(): void |
50
|
|
|
{ |
51
|
|
|
$this->expectExceptionMessage('Missing the concrete return type for the method `getRepository()`'); |
52
|
|
|
|
53
|
|
|
$dummy = new BadDummyDocBlockResolverAware(); |
54
|
|
|
$dummy->getRepository(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|