MemoryCacheTest.php 1.4 KB

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