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

ServiceResolverInMemoryAwareTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
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\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