12 require_once dirname(dirname(__FILE__)).
'/FilesystemHelper.php';
22 $nonce =
hash(
'sha256', uniqid(mt_rand(),
true));
23 $this->classname =
'__Twig_Tests_Cache_FilesystemTest_Template_'.$nonce;
24 $this->directory = sys_get_temp_dir().
'/twig-test';
30 if (file_exists($this->directory)) {
37 $key = $this->directory.
'/cache/cachefile.php';
40 @mkdir($dir, 0777,
true);
41 $this->assertTrue(is_dir($dir));
42 $this->assertFalse(class_exists($this->classname,
false));
45 file_put_contents(
$key, $content);
47 $this->cache->load(
$key);
49 $this->assertTrue(class_exists($this->classname,
false));
54 $key = $this->directory.
'/cache/cachefile.php';
56 $this->assertFalse(class_exists($this->classname,
false));
58 $this->cache->load(
$key);
60 $this->assertFalse(class_exists($this->classname,
false));
65 $key = $this->directory.
'/cache/cachefile.php';
68 $this->assertFileNotExists(
$key);
69 $this->assertFileNotExists($this->directory);
71 $this->cache->write(
$key, $content);
73 $this->assertFileExists($this->directory);
74 $this->assertFileExists(
$key);
75 $this->assertSame(file_get_contents(
$key), $content);
84 if (
defined(
'PHP_WINDOWS_VERSION_BUILD')) {
85 $this->markTestSkipped(
'Read-only directories not possible on Windows.');
88 $key = $this->directory.
'/cache/cachefile.php';
91 $this->assertFileNotExists(
$key);
94 @mkdir($this->directory, 0555,
true);
95 $this->assertTrue(is_dir($this->directory));
97 $this->cache->write(
$key, $content);
106 if (
defined(
'PHP_WINDOWS_VERSION_BUILD')) {
107 $this->markTestSkipped(
'Read-only directories not possible on Windows.');
110 $key = $this->directory.
'/cache/cachefile.php';
113 $this->assertFileNotExists(
$key);
116 @mkdir($this->directory, 0777,
true);
118 @mkdir($this->directory.
'/cache', 0555);
119 $this->assertTrue(is_dir($this->directory.
'/cache'));
121 $this->cache->write(
$key, $content);
130 $key = $this->directory.
'/cache/cachefile.php';
133 $this->assertFileNotExists(
$key);
136 @mkdir(
$key, 0777,
true);
137 $this->assertTrue(is_dir(
$key));
139 $this->cache->write(
$key, $content);
144 $key = $this->directory.
'/cache/cachefile.php';
146 $dir = dirname(
$key);
147 @mkdir($dir, 0777,
true);
148 $this->assertTrue(is_dir($dir));
151 touch(
$key, 1234567890);
153 $this->assertSame(1234567890, $this->cache->getTimestamp(
$key));
158 $key = $this->directory.
'/cache/cachefile.php';
159 $this->assertSame(0, $this->cache->getTimestamp(
$key));
170 $this->assertRegExp($expected,
$cache->generateKey(
'_test_', get_class($this)));
175 $pattern =
'#a/b/[a-zA-Z0-9]+/[a-zA-Z0-9]+.php$#';
178 array($pattern,
'a/b'),
179 array($pattern,
'a/b/'),
180 array($pattern,
'a/b\\'),
181 array($pattern,
'a/b\\/'),
182 array($pattern,
'a/b\\//'),
183 array(
'#/'.substr($pattern, 1),
'/a/b'),
189 return strtr(
'<?php class {{classname}} {}',
array(
190 '{{classname}}' => $this->classname,
testWriteFailWriteFile()
RuntimeException Failed to write cache file
testGenerateKey($expected, $input)
Test file cache is tolerant towards trailing (back)slashes on the configured cache directory...
testGetTimestampMissingFile()
Create styles array
The data for the language used.
testWriteFailDirWritable()
RuntimeException Unable to write in the cache directory
Implements a cache on the filesystem.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
testWriteFailMkdir()
RuntimeException Unable to create the cache directory