|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Behat\Gherkin\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Gherkin\Cache\FileCache; |
|
6
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
|
7
|
|
|
use Behat\Gherkin\Node\ScenarioNode; |
|
8
|
|
|
use Behat\Gherkin\Gherkin; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class FileCacheTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
private $path; |
|
14
|
|
|
private $cache; |
|
15
|
|
|
|
|
16
|
|
|
public function testIsFreshWhenThereIsNoFile() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->assertFalse($this->cache->isFresh('unexisting', time() + 100)); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testIsFreshOnFreshFile() |
|
22
|
|
|
{ |
|
23
|
|
|
$feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null); |
|
24
|
|
|
|
|
25
|
|
|
$this->cache->write('some_path', $feature); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertFalse($this->cache->isFresh('some_path', time() + 100)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testIsFreshOnOutdated() |
|
31
|
|
|
{ |
|
32
|
|
|
$feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null); |
|
33
|
|
|
|
|
34
|
|
|
$this->cache->write('some_path', $feature); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertTrue($this->cache->isFresh('some_path', time() - 100)); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testCacheAndRead() |
|
40
|
|
|
{ |
|
41
|
|
|
$scenarios = array(new ScenarioNode('Some scenario', array(), array(), null, null)); |
|
42
|
|
|
$feature = new FeatureNode('Some feature', 'some description', array(), null, $scenarios, null, null, null, null); |
|
43
|
|
|
|
|
44
|
|
|
$this->cache->write('some_feature', $feature); |
|
45
|
|
|
$featureRead = $this->cache->read('some_feature'); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertEquals($feature, $featureRead); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testBrokenCacheRead() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->expectException('Behat\Gherkin\Exception\CacheException'); |
|
53
|
|
|
|
|
54
|
|
|
touch($this->path . '/v' . Gherkin::VERSION . '/' . md5('broken_feature') . '.feature.cache'); |
|
55
|
|
|
$this->cache->read('broken_feature'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testUnwriteableCacheDir() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->expectException('Behat\Gherkin\Exception\CacheException'); |
|
61
|
|
|
|
|
62
|
|
|
new FileCache('/dev/null/gherkin-test'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function setUp() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->cache = new FileCache($this->path = sys_get_temp_dir() . '/gherkin-test'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function tearDown() |
|
71
|
|
|
{ |
|
72
|
|
|
foreach (glob($this->path . '/*.feature.cache') as $file) { |
|
73
|
|
|
unlink((string) $file); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|