aboutsummaryrefslogtreecommitdiff
path: root/tests/CacheTest.php
blob: 491db75a08b435ca400ef73396ec64c4b1b85286 (plain) (blame)
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
<?php

namespace RssBridge\Tests;

use PHPUnit\Framework\TestCase;

class CacheTest extends TestCase
{
    public function testConfig()
    {
        $sut = new \FileCache(new \NullLogger(), ['path' => '/tmp/']);
        $this->assertSame(['path' => '/tmp/', 'enable_purge' => true], $sut->getConfig());

        $sut = new \FileCache(new \NullLogger(), ['path' => '/', 'enable_purge' => false]);
        $this->assertSame(['path' => '/', 'enable_purge' => false], $sut->getConfig());

        $sut = new \FileCache(new \NullLogger(), ['path' => '/tmp', 'enable_purge' => true]);
        $this->assertSame(['path' => '/tmp/', 'enable_purge' => true], $sut->getConfig());
    }

    public function testFileCache()
    {
        $temporaryFolder = sprintf('%s/rss_bridge_%s/', sys_get_temp_dir(), create_random_string());
        mkdir($temporaryFolder);

        $sut = new \FileCache(new \NullLogger(), [
            'path' => $temporaryFolder,
            'enable_purge' => true,
        ]);
        $sut->clear();

        $this->assertNull($sut->get('key'));

        $sut->set('key', 'data', 5);
        $this->assertSame('data', $sut->get('key'));
        $sut->clear();

        // Intentionally not deleting the temp folder
    }
}