|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Behat\Gherkin\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Gherkin\Cache\MemoryCache; |
|
6
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
|
7
|
|
|
use Behat\Gherkin\Node\ScenarioNode; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class MemoryCacheTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
private $cache; |
|
13
|
|
|
|
|
14
|
|
|
public function testIsFreshWhenThereIsNoFile() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->assertFalse($this->cache->isFresh('unexisting', time() + 100)); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testIsFreshOnFreshFile() |
|
20
|
|
|
{ |
|
21
|
|
|
$feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null); |
|
22
|
|
|
|
|
23
|
|
|
$this->cache->write('some_path', $feature); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertFalse($this->cache->isFresh('some_path', time() + 100)); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testIsFreshOnOutdated() |
|
29
|
|
|
{ |
|
30
|
|
|
$feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null); |
|
31
|
|
|
|
|
32
|
|
|
$this->cache->write('some_path', $feature); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertTrue($this->cache->isFresh('some_path', time() - 100)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testCacheAndRead() |
|
38
|
|
|
{ |
|
39
|
|
|
$scenarios = array(new ScenarioNode('Some scenario', array(), array(), null, null)); |
|
40
|
|
|
$feature = new FeatureNode('Some feature', 'some description', array(), null, $scenarios, null, null, null, null); |
|
41
|
|
|
|
|
42
|
|
|
$this->cache->write('some_feature', $feature); |
|
43
|
|
|
$featureRead = $this->cache->read('some_feature'); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertEquals($feature, $featureRead); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function setUp() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->cache = new MemoryCache(); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|