Skip to content

Commit

Permalink
made AssetBundle tests less cryptic
Browse files Browse the repository at this point in the history
cleanup step was added in setUp() so this will still work.

split test functions filehelper test
  • Loading branch information
cebe committed May 8, 2017
1 parent 5e8e684 commit 3e79d56
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
36 changes: 27 additions & 9 deletions tests/framework/helpers/FileHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,13 +791,7 @@ public function testCopyDirectoryExclude()
}
}

/**
* @see https://github.com/yiisoft/yii2/issues/9669
*
* @depends testCopyDirectory
* @depends testFindFiles
*/
public function testCopyDirectoryEmptyDirectories()
private function setupCopyEmptyDirectoriesTest()
{
$srcDirName = 'test_empty_src_dir';
$this->createFileStructure([
Expand All @@ -814,8 +808,21 @@ public function testCopyDirectoryEmptyDirectories()
],
]);

$basePath = $this->testFilePath;
$srcDirName = $basePath . DIRECTORY_SEPARATOR . $srcDirName;
return [
$this->testFilePath, // basePath
$this->testFilePath . DIRECTORY_SEPARATOR . $srcDirName,
];
}

/**
* @see https://github.com/yiisoft/yii2/issues/9669
*
* @depends testCopyDirectory
* @depends testFindFiles
*/
public function testCopyDirectoryEmptyDirectories()
{
list($basePath, $srcDirName) = $this->setupCopyEmptyDirectoriesTest();

// copy with empty directories
$dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_empty_dst_dir';
Expand All @@ -830,6 +837,17 @@ public function testCopyDirectoryEmptyDirectories()
$this->assertFileExists($dstDirName . DIRECTORY_SEPARATOR . 'dir1' . DIRECTORY_SEPARATOR . 'file2.txt');
$this->assertFileExists($dstDirName . DIRECTORY_SEPARATOR . 'dir2');
$this->assertFileExists($dstDirName . DIRECTORY_SEPARATOR . 'dir3');
}

/**
* @see https://github.com/yiisoft/yii2/issues/9669
*
* @depends testCopyDirectory
* @depends testFindFiles
*/
public function testCopyDirectoryNoEmptyDirectories()
{
list($basePath, $srcDirName) = $this->setupCopyEmptyDirectoriesTest();

// copy without empty directories
$dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_empty_dst_dir2';
Expand Down
15 changes: 6 additions & 9 deletions tests/framework/web/AssetBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public function testSourcesPublish()
$this->assertTrue(is_dir($bundle->basePath));
$this->sourcesPublish_VerifyFiles('css', $bundle);
$this->sourcesPublish_VerifyFiles('js', $bundle);

$this->assertTrue(rmdir($bundle->basePath));
}

private function sourcesPublish_VerifyFiles($type, $bundle)
Expand All @@ -89,9 +87,8 @@ private function sourcesPublish_VerifyFiles($type, $bundle)
$sourceFile = $bundle->sourcePath . DIRECTORY_SEPARATOR . $filename;
$this->assertFileExists($publishedFile);
$this->assertFileEquals($publishedFile, $sourceFile);
$this->assertTrue(unlink($publishedFile));
}
$this->assertTrue(rmdir($bundle->basePath . DIRECTORY_SEPARATOR . $type));
$this->assertTrue(is_dir($bundle->basePath . DIRECTORY_SEPARATOR . $type));
}

public function testSourcesPublishedBySymlink()
Expand All @@ -109,7 +106,7 @@ public function testSourcesPublishedBySymlink_Issue9333()
}
]);
$bundle = $this->verifySourcesPublishedBySymlink($view);
$this->assertTrue(rmdir(dirname($bundle->basePath)));
$this->assertTrue(is_dir(dirname($bundle->basePath)));
}

public function testSourcesPublish_AssetManagerBeforeCopy()
Expand Down Expand Up @@ -165,15 +162,15 @@ public function testSourcesPublish_publishOptions_Only()
]);
$bundle->publish($am);

$notNeededFilesDir = $bundle->basePath . DIRECTORY_SEPARATOR . 'css';
$notNeededFilesDir = dirname($bundle->basePath . DIRECTORY_SEPARATOR . $bundle->css[0]);
$this->assertFileNotExists($notNeededFilesDir);

foreach ($bundle->js as $filename) {
$publishedFile = $bundle->basePath . DIRECTORY_SEPARATOR . $filename;
$this->assertTrue(unlink($publishedFile));
$this->assertFileExists($publishedFile);
}
$this->assertTrue(rmdir($bundle->basePath . DIRECTORY_SEPARATOR . 'js'));
$this->assertTrue(rmdir($bundle->basePath));
$this->assertTrue(is_dir(dirname($bundle->basePath . DIRECTORY_SEPARATOR . $bundle->js[0])));
$this->assertTrue(is_dir($bundle->basePath));
}

/**
Expand Down

0 comments on commit 3e79d56

Please sign in to comment.