ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Tests_Cache_FilesystemTest Class Reference
+ Inheritance diagram for Twig_Tests_Cache_FilesystemTest:
+ Collaboration diagram for Twig_Tests_Cache_FilesystemTest:

Public Member Functions

 testLoad ()
 
 testLoadMissing ()
 
 testWrite ()
 
 testWriteFailMkdir ()
 RuntimeException Unable to create the cache directory More...
 
 testWriteFailDirWritable ()
 RuntimeException Unable to write in the cache directory More...
 
 testWriteFailWriteFile ()
 RuntimeException Failed to write cache file More...
 
 testGetTimestamp ()
 
 testGetTimestampMissingFile ()
 
 testGenerateKey ($expected, $input)
 Test file cache is tolerant towards trailing (back)slashes on the configured cache directory. More...
 
 provideDirectories ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Private Member Functions

 generateSource ()
 

Private Attributes

 $classname
 
 $directory
 
 $cache
 

Detailed Description

Definition at line 14 of file FilesystemTest.php.

Member Function Documentation

◆ generateSource()

Twig_Tests_Cache_FilesystemTest::generateSource ( )
private

Definition at line 187 of file FilesystemTest.php.

Referenced by testLoad(), testWrite(), testWriteFailDirWritable(), testWriteFailMkdir(), and testWriteFailWriteFile().

188  {
189  return strtr('<?php class {{classname}} {}', array(
190  '{{classname}}' => $this->classname,
191  ));
192  }
+ Here is the caller graph for this function:

◆ provideDirectories()

Twig_Tests_Cache_FilesystemTest::provideDirectories ( )

Definition at line 173 of file FilesystemTest.php.

174  {
175  $pattern = '#a/b/[a-zA-Z0-9]+/[a-zA-Z0-9]+.php$#';
176 
177  return array(
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'),
184  );
185  }

◆ setUp()

Twig_Tests_Cache_FilesystemTest::setUp ( )
protected

Definition at line 20 of file FilesystemTest.php.

References GuzzleHttp\Psr7\hash().

21  {
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';
25  $this->cache = new Twig_Cache_Filesystem($this->directory);
26  }
Implements a cache on the filesystem.
Definition: Filesystem.php:17
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
+ Here is the call graph for this function:

◆ tearDown()

Twig_Tests_Cache_FilesystemTest::tearDown ( )
protected

Definition at line 28 of file FilesystemTest.php.

References Twig_Tests_FilesystemHelper\removeDir().

29  {
30  if (file_exists($this->directory)) {
32  }
33  }
+ Here is the call graph for this function:

◆ testGenerateKey()

Twig_Tests_Cache_FilesystemTest::testGenerateKey (   $expected,
  $input 
)

Test file cache is tolerant towards trailing (back)slashes on the configured cache directory.

provideDirectories

Definition at line 167 of file FilesystemTest.php.

References $cache, and $input.

168  {
170  $this->assertRegExp($expected, $cache->generateKey('_test_', get_class($this)));
171  }
Implements a cache on the filesystem.
Definition: Filesystem.php:17

◆ testGetTimestamp()

Twig_Tests_Cache_FilesystemTest::testGetTimestamp ( )

Definition at line 142 of file FilesystemTest.php.

References $key.

143  {
144  $key = $this->directory.'/cache/cachefile.php';
145 
146  $dir = dirname($key);
147  @mkdir($dir, 0777, true);
148  $this->assertTrue(is_dir($dir));
149 
150  // Create the file with a specific modification time.
151  touch($key, 1234567890);
152 
153  $this->assertSame(1234567890, $this->cache->getTimestamp($key));
154  }
$key
Definition: croninfo.php:18

◆ testGetTimestampMissingFile()

Twig_Tests_Cache_FilesystemTest::testGetTimestampMissingFile ( )

Definition at line 156 of file FilesystemTest.php.

References $key.

157  {
158  $key = $this->directory.'/cache/cachefile.php';
159  $this->assertSame(0, $this->cache->getTimestamp($key));
160  }
$key
Definition: croninfo.php:18

◆ testLoad()

Twig_Tests_Cache_FilesystemTest::testLoad ( )

Definition at line 35 of file FilesystemTest.php.

References $key, and generateSource().

36  {
37  $key = $this->directory.'/cache/cachefile.php';
38 
39  $dir = dirname($key);
40  @mkdir($dir, 0777, true);
41  $this->assertTrue(is_dir($dir));
42  $this->assertFalse(class_exists($this->classname, false));
43 
44  $content = $this->generateSource();
45  file_put_contents($key, $content);
46 
47  $this->cache->load($key);
48 
49  $this->assertTrue(class_exists($this->classname, false));
50  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ testLoadMissing()

Twig_Tests_Cache_FilesystemTest::testLoadMissing ( )

Definition at line 52 of file FilesystemTest.php.

References $key.

53  {
54  $key = $this->directory.'/cache/cachefile.php';
55 
56  $this->assertFalse(class_exists($this->classname, false));
57 
58  $this->cache->load($key);
59 
60  $this->assertFalse(class_exists($this->classname, false));
61  }
$key
Definition: croninfo.php:18

◆ testWrite()

Twig_Tests_Cache_FilesystemTest::testWrite ( )

Definition at line 63 of file FilesystemTest.php.

References $key, and generateSource().

64  {
65  $key = $this->directory.'/cache/cachefile.php';
66  $content = $this->generateSource();
67 
68  $this->assertFileNotExists($key);
69  $this->assertFileNotExists($this->directory);
70 
71  $this->cache->write($key, $content);
72 
73  $this->assertFileExists($this->directory);
74  $this->assertFileExists($key);
75  $this->assertSame(file_get_contents($key), $content);
76  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ testWriteFailDirWritable()

Twig_Tests_Cache_FilesystemTest::testWriteFailDirWritable ( )

RuntimeException Unable to write in the cache directory

Definition at line 104 of file FilesystemTest.php.

References $key, and generateSource().

105  {
106  if (defined('PHP_WINDOWS_VERSION_BUILD')) {
107  $this->markTestSkipped('Read-only directories not possible on Windows.');
108  }
109 
110  $key = $this->directory.'/cache/cachefile.php';
111  $content = $this->generateSource();
112 
113  $this->assertFileNotExists($key);
114 
115  // Create root directory.
116  @mkdir($this->directory, 0777, true);
117  // Create read-only subdirectory.
118  @mkdir($this->directory.'/cache', 0555);
119  $this->assertTrue(is_dir($this->directory.'/cache'));
120 
121  $this->cache->write($key, $content);
122  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ testWriteFailMkdir()

Twig_Tests_Cache_FilesystemTest::testWriteFailMkdir ( )

RuntimeException Unable to create the cache directory

Definition at line 82 of file FilesystemTest.php.

References $key, and generateSource().

83  {
84  if (defined('PHP_WINDOWS_VERSION_BUILD')) {
85  $this->markTestSkipped('Read-only directories not possible on Windows.');
86  }
87 
88  $key = $this->directory.'/cache/cachefile.php';
89  $content = $this->generateSource();
90 
91  $this->assertFileNotExists($key);
92 
93  // Create read-only root directory.
94  @mkdir($this->directory, 0555, true);
95  $this->assertTrue(is_dir($this->directory));
96 
97  $this->cache->write($key, $content);
98  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ testWriteFailWriteFile()

Twig_Tests_Cache_FilesystemTest::testWriteFailWriteFile ( )

RuntimeException Failed to write cache file

Definition at line 128 of file FilesystemTest.php.

References $key, and generateSource().

129  {
130  $key = $this->directory.'/cache/cachefile.php';
131  $content = $this->generateSource();
132 
133  $this->assertFileNotExists($key);
134 
135  // Create a directory in the place of the cache file.
136  @mkdir($key, 0777, true);
137  $this->assertTrue(is_dir($key));
138 
139  $this->cache->write($key, $content);
140  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

Field Documentation

◆ $cache

Twig_Tests_Cache_FilesystemTest::$cache
private

Definition at line 18 of file FilesystemTest.php.

Referenced by testGenerateKey().

◆ $classname

Twig_Tests_Cache_FilesystemTest::$classname
private

Definition at line 16 of file FilesystemTest.php.

◆ $directory

Twig_Tests_Cache_FilesystemTest::$directory
private

Definition at line 17 of file FilesystemTest.php.


The documentation for this class was generated from the following file: