diff --git a/tests/PhpseclibTestCase.php b/tests/PhpseclibTestCase.php index 3369ad16..f0f75d9a 100644 --- a/tests/PhpseclibTestCase.php +++ b/tests/PhpseclibTestCase.php @@ -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