MemoryCacheTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 43
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsFreshWhenThereIsNoFile() 0 4 1
A testIsFreshOnFreshFile() 0 8 1
A testIsFreshOnOutdated() 0 8 1
A testCacheAndRead() 0 10 1
A setUp() 0 4 1
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