Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / tests / Behat / Gherkin / Cache / FileCacheTest.php
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');
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');
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 }