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