Infrastructure for obtaining temporary files.

This commit is contained in:
Andreas Fischer 2014-12-05 23:24:52 +01:00
parent 630a71bee6
commit 4dc6179207

View File

@ -7,6 +7,32 @@
abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
{
protected $tempFilesToUnlinkOnTearDown = array();
public function tearDown()
{
foreach ($this->tempFilesToUnlinkOnTearDown as $filename) {
if (!file_exists($filename) || unlink($filename)) {
unset($this->tempFilesToUnlinkOnTearDown[$filename]);
}
}
parent::tearDown();
}
/**
* Creates a temporary file on the local filesystem and returns its path.
* All files created using this method will be deleted from the filesystem
* on tearDown(), i.e. after each test method was run.
*
* @return string
*/
protected function createTempFile()
{
$filename = tempnam(sys_get_temp_dir(), 'phpseclib-test-');
$this->tempFilesToUnlinkOnTearDown[] = $filename;
return $filename;
}
/**
* @param string $constant
* @param mixed $expected