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
|
|
|
|