Example #1
0
 /**
  * Provide a temporary directory path to use for tests and always make sure it gets removed
  * @param callable $func (TestCase, String) => () Will do the stuff to the temporary directory
  */
 protected function doStuffWithTempDir($func)
 {
     $shell = new Shell();
     $dir = $shell->mktempdir();
     try {
         $func($this, $dir);
     } catch (\Exception $e) {
         @unlink($dir);
         throw $e;
     }
     @unlink($dir);
 }
Example #2
0
 public function test_chdir()
 {
     try {
         $shell = new Shell();
         $dir = $shell->mktempdir();
         $this->assertTrue(file_exists($dir), 'Temp dir was not created');
         $success = $shell->chdir($dir);
         $this->assertTrue($success, "Could not chdir {$dir}");
         $non_existent_dir = "/a/non/existent/{$dir}";
         // @ to prevent E_WARNING from being thrown
         $failure = @$shell->chdir($non_existent_dir);
         $this->assertFalse($failure, "chdir to {$non_existent_dir} should have failed");
         @rmdir($dir);
         // Clean up
     } catch (\Exception $e) {
         if ($dir) {
             @rmdir($dir);
             // Clean up
         }
         throw $e;
     }
 }