File: PSR6CacheTest.php

package info (click to toggle)
matomo-device-detector 6.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,684 kB
  • sloc: php: 7,758; xml: 79; makefile: 15; sh: 3
file content (63 lines) | stat: -rw-r--r-- 1,718 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
<?php

/**
 * Device Detector - The Universal Device Detection library for parsing User Agents
 *
 * @link https://matomo.org
 *
 * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
 */

declare(strict_types=1);

namespace DeviceDetector\Tests\Cache;

use DeviceDetector\Cache\PSR6Bridge;
use MatthiasMullie\Scrapbook\Adapters\MemoryStore;
use MatthiasMullie\Scrapbook\Psr6\Pool;
use PHPUnit\Framework\TestCase;

class PSR6CacheTest extends TestCase
{
    protected function setUp(): void
    {
        if (!\class_exists('\MatthiasMullie\Scrapbook\Adapters\MemoryStore')) {
            $this->markTestSkipped('class \MatthiasMullie\Scrapbook\Adapters\MemoryStore required for tests');

            return;
        }

        $cache = new PSR6Bridge(new Pool(new MemoryStore()));
        $cache->flushAll();
    }

    public function testSetNotPresent(): void
    {
        $cache = new PSR6Bridge(new Pool(new MemoryStore()));
        $this->assertFalse($cache->fetch('NotExistingKey'));
    }

    public function testSetAndGet(): void
    {
        $cache = new PSR6Bridge(new Pool(new MemoryStore()));

        // add entry
        $cache->save('key', 'value');
        $this->assertEquals('value', $cache->fetch('key'));

        // change entry
        $cache->save('key', 'value2');
        $this->assertEquals('value2', $cache->fetch('key'));

        // remove entry
        $cache->delete('key');
        $this->assertFalse($cache->fetch('key'));

        // flush all entries
        $cache->save('key', 'value2');
        $cache->save('key3', 'value2');
        $cache->flushAll();
        $this->assertFalse($cache->fetch('key'));
        $this->assertFalse($cache->fetch('key3'));
    }
}