Completed
Pull Request — master (#112)
by Christophe
02:50
created

MemoryCacheTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsFreshWhenThereIsNoFile() 0 4 1
A setUp() 0 4 1
A testIsFreshOnFreshFile() 0 8 1
A testIsFreshOnOutdated() 0 8 1
A testCacheAndRead() 0 10 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
9
class MemoryCacheTest extends \PHPUnit_Framework_TestCase
10
{
11
    private $cache;
12
13
    public function testIsFreshWhenThereIsNoFile()
14
    {
15
        $this->assertFalse($this->cache->isFresh('unexisting', time() + 100));
16
    }
17
18
    public function testIsFreshOnFreshFile()
19
    {
20
        $feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null);
21
22
        $this->cache->write('some_path', $feature);
23
24
        $this->assertFalse($this->cache->isFresh('some_path', time() + 100));
25
    }
26
27
    public function testIsFreshOnOutdated()
28
    {
29
        $feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null);
30
31
        $this->cache->write('some_path', $feature);
32
33
        $this->assertTrue($this->cache->isFresh('some_path', time() - 100));
34
    }
35
36
    public function testCacheAndRead()
37
    {
38
        $scenarios = array(new ScenarioNode('Some scenario', array(), array(), null, null));
39
        $feature = new FeatureNode('Some feature', 'some description', array(), null, $scenarios, null, null, null, null);
40
41
        $this->cache->write('some_feature', $feature);
42
        $featureRead = $this->cache->read('some_feature');
43
44
        $this->assertEquals($feature, $featureRead);
45
    }
46
47
    protected function setUp()
48
    {
49
        $this->cache = new MemoryCache();
50
    }
51
}
52