Skip to content

Commit

Permalink
proper test
Browse files Browse the repository at this point in the history
  • Loading branch information
indeyets committed Oct 24, 2013
1 parent 272f782 commit 22473c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/pake/pakeFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ function pake_read_file($file_or_url)

if (false === $retval) {
$err = error_get_last();
throw new pakeException("Couldn't get file: ".$err['message']);
throw new pakeException("Couldn't get file '{$file_or_url}': ".$err['message']);
}

return $retval;
Expand Down
29 changes: 16 additions & 13 deletions test/pakeFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,30 @@ private function _cleanup()

public function test_pake_replace_tokens()
{
$test_file_names = array( 'file1.tpl', 'file2.tpl', 'file3.tpl' );
foreach( $test_file_names as $test_file_name )
{
file_put_contents($this->test_dir.DIRECTORY_SEPARATOR.$test_file_name, '{token} {token2}');
}
$test_file_name = 'file1.tpl';
file_put_contents($this->test_dir.DIRECTORY_SEPARATOR.$test_file_name, '{token} {token2}');

pake_replace_tokens($test_file_name, $this->test_dir, '{', '}', array('token' => 'hello', 'token2' => 'world'));

pake_replace_tokens($test_file_names[0], $this->test_dir, '{', '}', array('token' => 'hello', 'token2' => 'world'));
$test_file = $this->test_dir.DIRECTORY_SEPARATOR.$test_file_names[0];
$test_file = $this->test_dir.DIRECTORY_SEPARATOR.$test_file_name;
$replaced = file_get_contents($test_file);
$this->assertEqual('hello world', $replaced);
unlink($test_file);
unset($test_file_names[0]);
}

$files = pakeFinder::type('file')->in($this->test_dir);
public function test_pake_replace_tokens_finder()
{
$test_file_names = array('file1.tpl', 'file2.tpl', 'file3.tpl');
foreach ($test_file_names as $test_file_name) {
file_put_contents($this->test_dir.DIRECTORY_SEPARATOR.$test_file_name, '{token} {token2}');
}

$files = pakeFinder::type('file')->relative()->in($this->test_dir);
pake_replace_tokens($files, $this->test_dir, '{', '}', array('token' => 'hello', 'token2' => 'world'));
foreach( $test_file_names as $test_file_name )
{

foreach ($test_file_names as $test_file_name) {
$test_file = $this->test_dir.DIRECTORY_SEPARATOR.$test_file_name;
$replaced = file_get_contents($test_file);
$this->assertEqual('hello world', $replaced);
unlink($test_file);
}
}
}

0 comments on commit 22473c1

Please sign in to comment.