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

ServiceResolverInMemoryAwareTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 42
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 3 1
A test_existing_service_cached() 0 10 1
A test_non_existing_service() 0 6 1
A setUp() 0 5 1
A test_existing_service() 0 7 1
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\ClassResolver\Cache\InMemoryCache;
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 ServiceResolverInMemoryAwareTest extends TestCase
17
{
18
    public static function setUpBeforeClass(): void
19
    {
20
        DirectoryUtil::removeDir(__DIR__ . DIRECTORY_SEPARATOR . '.gacela');
21
    }
22
23
    protected function setUp(): void
24
    {
25
        Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
26
            $config->resetInMemoryCache();
27
            $config->addAppConfigKeyValue(GacelaFileCache::KEY_ENABLED, false);
28
        });
29
    }
30
31
    public function test_existing_service(): void
32
    {
33
        $dummy = new DummyServiceResolverAware();
34
        $actual = $dummy->getRepository()->findName();
35
36
        self::assertCount(1, InMemoryCache::getAllFromKey(CustomServicesPhpCache::class));
37
        self::assertSame('name', $actual);
38
    }
39
40
    #[Depends('test_existing_service')]
41
    public function test_existing_service_cached(): void
42
    {
43
        self::assertCount(0, InMemoryCache::getAllFromKey(CustomServicesPhpCache::class));
44
45
        $dummy = new DummyServiceResolverAware();
46
        $dummy->getRepository()->findName();
47
        $dummy->getRepository()->findName();
48
49
        self::assertCount(1, InMemoryCache::getAllFromKey(CustomServicesPhpCache::class));
50
    }
51
52
    public function test_non_existing_service(): void
53
    {
54
        $this->expectExceptionMessage('Missing the concrete return type for the method `getRepository()`');
55
56
        $dummy = new BadDummyServiceResolverAware();
57
        $dummy->getRepository();
58
    }
59
}
60