File: InMemoryCacheTest.php

package info (click to toggle)
phpmyadmin-motranslator 5.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,928 kB
  • sloc: php: 1,760; makefile: 9
file content (81 lines) | stat: -rw-r--r-- 2,331 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php

declare(strict_types=1);

namespace PhpMyAdmin\MoTranslator\Tests\Cache;

use PhpMyAdmin\MoTranslator\Cache\InMemoryCache;
use PhpMyAdmin\MoTranslator\MoParser;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(InMemoryCache::class)]
class InMemoryCacheTest extends TestCase
{
    public function testConstructorParsesCache(): void
    {
        $expected = 'Pole';
        $parser = new MoParser(__DIR__ . '/../data/little.mo');
        $cache = new InMemoryCache($parser);
        $actual = $cache->get('Column');
        self::assertSame($expected, $actual);
    }

    public function testGetReturnsMsgidForCacheMiss(): void
    {
        $expected = 'Column';
        $cache = new InMemoryCache(new MoParser(null));
        $actual = $cache->get($expected);
        self::assertSame($expected, $actual);
    }

    public function testSetSetsMsgstr(): void
    {
        $expected = 'Pole';
        $msgid = 'Column';
        $cache = new InMemoryCache(new MoParser(null));
        $cache->set($msgid, $expected);
        $actual = $cache->get($msgid);
        self::assertSame($expected, $actual);
    }

    public function testHasReturnsFalse(): void
    {
        $cache = new InMemoryCache(new MoParser(null));
        $actual = $cache->has('Column');
        self::assertFalse($actual);
    }

    public function testHasReturnsTrue(): void
    {
        $cache = new InMemoryCache(new MoParser(__DIR__ . '/../data/little.mo'));
        $actual = $cache->has('Column');
        self::assertTrue($actual);
    }

    public function testSetAllSetsTranslations(): void
    {
        $translations = [
            'foo' => 'bar',
            'and' => 'another',
        ];
        $cache = new InMemoryCache(new MoParser(null));
        $cache->setAll($translations);
        foreach ($translations as $msgid => $expected) {
            $actual = $cache->get($msgid);
            self::assertSame($expected, $actual);
        }
    }

    public function testGetAllReturnsTranslations(): void
    {
        $expected = [
            'foo' => 'bar',
            'and' => 'another',
        ];
        $cache = new InMemoryCache(new MoParser(null));
        $cache->setAll($expected);
        $actual = $cache->getAll();
        self::assertSame($expected, $actual);
    }
}