Completed
Push — master ( 7bf61f...fe96af )
by Konstantin
9s
created

FileCacheTest::testUnwriteableCacheDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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
10
class FileCacheTest extends \PHPUnit_Framework_TestCase
11
{
12
    private $path;
13
    private $cache;
14
15
    public function testIsFreshWhenThereIsNoFile()
16
    {
17
        $this->assertFalse($this->cache->isFresh('unexisting', time() + 100));
18
    }
19
20
    public function testIsFreshOnFreshFile()
21
    {
22
        $feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null);
23
24
        $this->cache->write('some_path', $feature);
25
26
        $this->assertFalse($this->cache->isFresh('some_path', time() + 100));
27
    }
28
29
    public function testIsFreshOnOutdated()
30
    {
31
        $feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null);
32
33
        $this->cache->write('some_path', $feature);
34
35
        $this->assertTrue($this->cache->isFresh('some_path', time() - 100));
36
    }
37
38
    public function testCacheAndRead()
39
    {
40
        $scenarios = array(new ScenarioNode('Some scenario', array(), array(), null, null));
41
        $feature = new FeatureNode('Some feature', 'some description', array(), null, $scenarios, null, null, null, null);
42
43
        $this->cache->write('some_feature', $feature);
44
        $featureRead = $this->cache->read('some_feature');
45
46
        $this->assertEquals($feature, $featureRead);
47
    }
48
49
    public function testBrokenCacheRead()
50
    {
51
        $this->setExpectedException('Behat\Gherkin\Exception\CacheException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
52
53
        touch($this->path . '/v' . Gherkin::VERSION . '/' . md5('broken_feature') . '.feature.cache');
54
        $this->cache->read('broken_feature');
55
    }
56
57
    public function testUnwriteableCacheDir()
58
    {
59
        $this->setExpectedException('Behat\Gherkin\Exception\CacheException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
60
61
        new FileCache('/dev/null/gherkin-test');
62
    }
63
64
    protected function setUp()
65
    {
66
        $this->cache = new FileCache($this->path = sys_get_temp_dir() . '/gherkin-test');
67
    }
68
69
    protected function tearDown()
70
    {
71
        foreach (glob($this->path . '/*.feature.cache') as $file) {
72
            unlink((string) $file);
73
        }
74
    }
75
}
76