Skip to content

Commit

Permalink
Set temp directory for each single test.
Browse files Browse the repository at this point in the history
  • Loading branch information
derhasi committed Jan 7, 2015
1 parent de8581c commit b4c1923
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions tests/PathPreserverTest.php
Expand Up @@ -28,32 +28,32 @@ class PathPreserverTest extends \PHPUnit_Framework_TestCase {
public function setUp() {
$this->fs = new Filesystem();
$this->io = $this->getMock('Composer\IO\IOInterface');
$this->workingDirectory = new TempDirectory('path-preserver-test-working');
$this->cacheDirectory = new TempDirectory('path-preserver-test-cache');
}

/**
* test that the directory is created
* Tests that the directory is created
*/
public function testPreserveAndRollback() {
$workingDirectory = new TempDirectory(__METHOD__);
$cacheDirectory = new TempDirectory(__METHOD__ . '-cache');

// Create directory to test.
$folder1 = $this->workingDirectory->getPath('folder1');
$folder1 = $workingDirectory->getPath('folder1');
mkdir($folder1);
$file1 = $this->workingDirectory->getPath('file1.txt');
$file1 = $workingDirectory->getPath('file1.txt');
file_put_contents($file1, 'Test content');

// We simulate creation of
$installPaths = array(
$this->workingDirectory->getRoot()
$workingDirectory->getRoot()
);

$preservePaths = array(
$folder1,
$file1,
);

$preserver = new PathPreserver($installPaths, $preservePaths, $this->cacheDirectory->getRoot(), $this->fs, $this->io);
$preserver = new PathPreserver($installPaths, $preservePaths, $cacheDirectory->getRoot(), $this->fs, $this->io);
$this->assertIsDir($folder1, 'Folder created.');
$this->assertFileExists($file1, 'File created.');
$preserver->preserve();
Expand All @@ -66,14 +66,15 @@ public function testPreserveAndRollback() {
}

/**
* Test file_exists() restrictions on non executable directories.
* Tests file_exists() restrictions on non executable directories.
*/
public function testFileExists() {
$workingDirectory = new TempDirectory(__METHOD__);

$folder1 = $this->workingDirectory->getPath('folder1');
$subfolder1 = $this->workingDirectory->getPath('folder1/subfolder1');
$file1 = $this->workingDirectory->getPath('folder1/subfolder1/file1.txt');
$file2 = $this->workingDirectory->getPath('folder1/file2.txt');
$folder1 = $workingDirectory->getPath('folder1');
$subfolder1 = $workingDirectory->getPath('folder1/subfolder1');
$file1 = $workingDirectory->getPath('folder1/subfolder1/file1.txt');
$file2 = $workingDirectory->getPath('folder1/file2.txt');

mkdir($folder1);
mkdir($subfolder1);
Expand All @@ -96,22 +97,24 @@ public function testFileExists() {
}

/**
* Test perservation and rollback on tricky path permissions.
* Tests preservation and rollback on tricky path permissions.
*
* @depends testPreserveAndRollback
*/
public function testFileModes() {
$workingDirectory = new TempDirectory(__METHOD__);
$cacheDirectory = new TempDirectory(__METHOD__ . '-cache');

// Create directory to test.
$folder1 = $this->workingDirectory->getPath('folder1');
$folder1 = $workingDirectory->getPath('folder1');
mkdir($folder1);

$subfolder1 = $this->workingDirectory->getPath('folder1/subfolder1');
$subfolder1 = $workingDirectory->getPath('folder1/subfolder1');
mkdir($subfolder1);

$file1 = $this->workingDirectory->getPath('folder1/file1.txt');
$file1 = $workingDirectory->getPath('folder1/file1.txt');
file_put_contents($file1, 'Test content');
$file2 = $this->workingDirectory->getPath('folder1/file2.txt');
$file2 = $workingDirectory->getPath('folder1/file2.txt');
file_put_contents($file2, 'Test content 2');

// After changing some permissions we test if the given paths can be
Expand All @@ -136,7 +139,7 @@ public function testFileModes() {
$file2,
);

$preserver = new PathPreserver($installPaths, $preservePaths, $this->cacheDirectory->getRoot(), $this->fs, $this->io);
$preserver = new PathPreserver($installPaths, $preservePaths, $cacheDirectory->getRoot(), $this->fs, $this->io);

// We check if preservation works even with restrictive permissions.
chmod($folder1, 0400);
Expand Down

0 comments on commit b4c1923

Please sign in to comment.