ConfigFileScriptCacheTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 96%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 66
ccs 24
cts 25
cp 0.96
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 2
A testInstance() 0 4 1
A testSetGetClear() 0 14 1
A tearDown() 0 8 2
1
<?php
2
3
namespace Dekalee\AdbackAnalytics\Tests\Unit\Driver;
4
5
use Dekalee\AdbackAnalytics\Driver\ScriptCacheInterface;
6
use Dekalee\AdbackAnalyticsBundle\Driver\ConfigFileScriptCache;
7
use Symfony\Component\Filesystem\Filesystem;
8
9
/**
10
 * Class ConfigFileScriptCacheTest
11
 */
12
class ConfigFileScriptCacheTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @var ConfigFileScriptCache
16
     */
17
    protected $cache;
18
19
    /**
20
     * @var Filesystem
21
     */
22
    protected $fs;
23
    protected $cacheDir;
24
25
    /**
26
     * Set up the test
27
     */
28 2
    public function setUp()
29
    {
30 2
        $this->fs = new Filesystem();
31 2
        $this->cacheDir = __DIR__ . '/cache';
32 2
        if ($this->fs->exists($this->cacheDir)) {
33
            $this->fs->remove($this->cacheDir);
34
        }
35
36 2
        $this->cache = new ConfigFileScriptCache($this->cacheDir, true);
37 2
    }
38
39
    /**
40
     * Test instance
41
     */
42 1
    public function testInstance()
43
    {
44 1
        $this->assertInstanceOf(ScriptCacheInterface::CLASS, $this->cache);
45 1
    }
46
47
    /**
48
     * Test set, get and clear
49
     */
50 1
    public function testSetGetClear()
51
    {
52 1
        $cacheFile = $this->cacheDir . '/adback/apiCache.php';
53
54 1
        $this->cache->setAnalyticsScript('foo');
55 1
        $this->assertTrue($this->fs->exists($cacheFile));
56 1
        $this->assertSame(json_encode(['adback_analytics_script' => 'foo']), file_get_contents($cacheFile));
57
58 1
        $this->assertSame('foo', $this->cache->getAnalyticsScript());
59
60 1
        $this->cache->clearAnalyticsData();
61 1
        $this->assertTrue($this->fs->exists($cacheFile));
62 1
        $this->assertSame(json_encode([]), file_get_contents($cacheFile));
63 1
    }
64
65
    /**
66
     * Tears down the fixture, for example, close a network connection.
67
     * This method is called after a test is executed.
68
     */
69 2
    protected function tearDown()
70
    {
71 2
        parent::tearDown();
72
73 2
        if ($this->fs->exists($this->cacheDir)) {
74 2
            $this->fs->remove($this->cacheDir);
75
        }
76 2
    }
77
}
78