Randomize temp-dir and ignore IOException in tests

If the file pointer is not closed or some other program (like TGitcache.exe) is reading the file
the tests don't fail anymore.
This commit is contained in:
Sebastiaan Stok
2012-08-31 11:36:30 +02:00
parent 75a00574b5
commit 19feb0d87e
3 changed files with 33 additions and 15 deletions

View File

@@ -4,17 +4,16 @@ require 'vendor/autoload.php';
use Silex\WebTestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOException;
use GitList\Component\Git\Client;
class InterfaceTest extends WebTestCase
{
protected static $tmpdir = '/tmp/gitlist';
protected static $tmpdir;
public static function setUpBeforeClass()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
self::$tmpdir = getenv('TMP').'/gitlist';
}
self::$tmpdir = getenv('TMP').'/gitlist_' . md5(time() . mt_rand()) . '/';
$fs = new Filesystem();
$fs->mkdir(self::$tmpdir);
@@ -197,6 +196,11 @@ class InterfaceTest extends WebTestCase
public static function tearDownAfterClass()
{
$fs = new Filesystem();
$fs->remove(self::$tmpdir);
try {
$fs->remove(self::$tmpdir);
} catch (IOException $e) {
// Ignore, file is not closed yet
}
}
}