Skip to content

Commit

Permalink
Add test to check that directories are created using the key hash fun…
Browse files Browse the repository at this point in the history
…ction.
  • Loading branch information
pwhelan committed Feb 19, 2013
1 parent e977ec9 commit 08f5b20
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/Stash/Test/Driver/FileSystemTest.php
Expand Up @@ -12,6 +12,12 @@
namespace Stash\Test\Driver;

use Stash\Driver\FileSystem;
use Stash\Item;

function strdup($str)
{
return $str;
}

/**
* @package Stash
Expand All @@ -38,4 +44,39 @@ public function testOptionKeyHashFunction()
{
$driver = new FileSystem(array('keyHashFunction' => 'md5'));
}

/**
* Test that the paths are created using the key hash function.
*/
public function testOptionKeyHashFunctionDirs()
{
$hashfunctions = array('Stash\Test\Driver\strdup', 'strrev', 'md5');
$paths = array('one', 'two', 'three', 'four');


foreach($hashfunctions as $hashfunction) {

$driver = new FileSystem(array(
'keyHashFunction' => $hashfunction,
'path' => sys_get_temp_dir().DIRECTORY_SEPARATOR.'stash',
'dirSplit' => 1
));

$rand = str_repeat(uniqid(), 32);

$item = new Item($driver, $paths);
$item->set($rand);

$allpaths = array_merge(array('cache'), $paths);
$predicted = sys_get_temp_dir().
DIRECTORY_SEPARATOR.
'stash'.
DIRECTORY_SEPARATOR.
implode(DIRECTORY_SEPARATOR,
array_map($hashfunction, $allpaths)).
'.php';

$this->assertFileExists($predicted);
}
}
}

0 comments on commit 08f5b20

Please sign in to comment.