Passed
Pull Request — main (#340)
by Chema
07:33 queued 03:19
created

test_existing_service()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Integration\Framework\ServiceResolverAware;
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 ServiceResolverCustomServicesAwareTest 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 {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

31
            $config->registerGenericListener(static function (/** @scrutinizer ignore-unused */ GacelaEventInterface $event): void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
                // dump('Triggered -> ' . \get_class($event)); # useful for debugging
33
            });
34
        });
35
    }
36
37
    public function test_existing_service(): void
38
    {
39
        $dummy = new DummyServiceResolverAware();
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 DummyServiceResolverAware();
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 BadDummyServiceResolverAware();
63
        $dummy->getRepository();
64
    }
65
}
66