InMemoryCacheTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 37
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetSetsMsgstr() 0 8 1
A testConstructorParsesCache() 0 7 1
A testGetAllReturnsTranslations() 0 10 1
A testHasReturnsTrue() 0 5 1
A testGetReturnsMsgidForCacheMiss() 0 6 1
A testHasReturnsFalse() 0 5 1
A testSetAllSetsTranslations() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\MoTranslator\Tests\Cache;
6
7
use PhpMyAdmin\MoTranslator\Cache\InMemoryCache;
8
use PhpMyAdmin\MoTranslator\MoParser;
9
use PHPUnit\Framework\TestCase;
10
11
/** @covers \PhpMyAdmin\MoTranslator\Cache\InMemoryCache */
12
class InMemoryCacheTest extends TestCase
13
{
14
    public function testConstructorParsesCache(): void
15
    {
16
        $expected = 'Pole';
17
        $parser = new MoParser(__DIR__ . '/../data/little.mo');
18
        $cache = new InMemoryCache($parser);
19
        $actual = $cache->get('Column');
20
        self::assertSame($expected, $actual);
21
    }
22
23
    public function testGetReturnsMsgidForCacheMiss(): void
24
    {
25
        $expected = 'Column';
26
        $cache = new InMemoryCache(new MoParser(null));
27
        $actual = $cache->get($expected);
28
        self::assertSame($expected, $actual);
29
    }
30
31
    public function testSetSetsMsgstr(): void
32
    {
33
        $expected = 'Pole';
34
        $msgid = 'Column';
35
        $cache = new InMemoryCache(new MoParser(null));
36
        $cache->set($msgid, $expected);
37
        $actual = $cache->get($msgid);
38
        self::assertSame($expected, $actual);
39
    }
40
41
    public function testHasReturnsFalse(): void
42
    {
43
        $cache = new InMemoryCache(new MoParser(null));
44
        $actual = $cache->has('Column');
45
        self::assertFalse($actual);
46
    }
47
48
    public function testHasReturnsTrue(): void
49
    {
50
        $cache = new InMemoryCache(new MoParser(__DIR__ . '/../data/little.mo'));
51
        $actual = $cache->has('Column');
52
        self::assertTrue($actual);
53
    }
54
55
    public function testSetAllSetsTranslations(): void
56
    {
57
        $translations = [
58
            'foo' => 'bar',
59
            'and' => 'another',
60
        ];
61
        $cache = new InMemoryCache(new MoParser(null));
62
        $cache->setAll($translations);
63
        foreach ($translations as $msgid => $expected) {
64
            $actual = $cache->get($msgid);
65
            self::assertSame($expected, $actual);
66
        }
67
    }
68
69
    public function testGetAllReturnsTranslations(): void
70
    {
71
        $expected = [
72
            'foo' => 'bar',
73
            'and' => 'another',
74
        ];
75
        $cache = new InMemoryCache(new MoParser(null));
76
        $cache->setAll($expected);
77
        $actual = $cache->getAll();
78
        self::assertSame($expected, $actual);
79
    }
80
}
81