Source of file YamlConfigTest.php
Size: 3,288 Bytes - Last Modified: 2021-12-24T06:50:57+00:00
/var/www/docs.ssmods.com/process/src/tests/Configs/YamlConfigTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 | <?php namespace Heyday\CacheInclude\Configs; use Symfony\Component\Cache\Simple\ArrayCache; use Symfony\Component\Yaml\Yaml; class YamlConfigTest extends \PHPUnit_Framework_TestCase { protected $validYamlData; protected $invalidYamlData; protected function setUp() { $this->validYamlData = <<<YAML Something: expires: +1 week contains: - Page - HomePage YAML; $this->invalidYamlData = <<<YAML "missing colon" foo: bar YAML; } /** * @expectedException \Symfony\Component\Yaml\Exception\ParseException */ public function testYamlException() { new YamlConfig($this->invalidYamlData); } public function testYamlParse() { $config = new YamlConfig($this->validYamlData); $this->assertEquals(array( 'expires' => '+1 week', 'contains' => array( 'Page', 'HomePage' ) ), $config['Something']); } public function testYamlParseReadFile() { $path = __DIR__ . '/test.yml'; file_put_contents($path, $this->validYamlData); $key = md5($this->validYamlData); $cacheMock = $this->getMockBuilder(ArrayCache::class) ->setMethods(array('has', 'get')) ->getMock(); $cacheMock->expects($this->once()) ->method('has') ->with($key) ->will($this->returnValue(true)); $cacheMock->expects($this->once()) ->method('get') ->with($key) ->will($this->returnValue(Yaml::parse($this->validYamlData))); $config = new YamlConfig($path, $cacheMock); $this->assertEquals( array( 'expires' => '+1 week', 'contains' => array( 'Page', 'HomePage' ) ), $config['Something'] ); unlink($path); } public function testYamlCacheHit() { $cacheMock = $this->getMockBuilder(ArrayCache::class) ->setMethods(array('has', 'get')) ->getMock(); $cacheMock->expects($this->once()) ->method('has') ->will($this->returnValue(true)); $cacheMock->expects($this->once()) ->method('get') ->will($this->returnValue(Yaml::parse($this->validYamlData))); new YamlConfig($this->validYamlData, $cacheMock); } public function testYamlCacheMiss() { $cacheMock = $this->getMockBuilder(ArrayCache::class) ->setMethods(array('has', 'set')) ->getMock(); $cacheMock->expects($this->once()) ->method('has') ->will($this->returnValue(false)); $cacheMock->expects($this->once()) ->method('set') ->with( md5($this->validYamlData), array( 'Something' => array( 'expires' => '+1 week', 'contains' => array( 'Page', 'HomePage' ) ) ) ); new YamlConfig($this->validYamlData, $cacheMock); } } |