Browse files

more oo-ish version of it

  • Loading branch information...
1 parent dfed86f commit dc25f26152065cc6d4abb4396b69636046b6c207 Ulf Harnhammar committed Jun 18, 2012
View
40 tests/Composer/Test/Package/Dumper/DumperTest.php
@@ -15,21 +15,43 @@
abstract class DumperTest extends \PHPUnit_Framework_TestCase
{
- public function getPackageName()
+ protected $testdir = '';
+
+ function __construct()
+ {
+ $this->testdir = sys_get_temp_dir() . '/composer_dumpertest_git_repository' . mt_rand();
+ }
+
+ protected function getTestDir()
+ {
+ return $this->testdir;
+ }
+
+ protected function setupGitRepo()
{
- $testdir = '/tmp/composer_dumpertest_git_repository';
+ $td = $this->getTestDir();
+ system("rm -rf $td; mkdir $td");
+ system("cd $td; git init; echo 'a' > b; git add b; git commit -m test");
+ }
- system("rm -rf $testdir; mkdir $testdir");
- system("cd $testdir; git init; echo 'a' > b; git add b; git commit -m test");
+ protected function removeGitRepo()
+ {
+ $td = $this->getTestDir();
+ system("rm -rf $td");
+ }
+ protected function setupPackage()
+ {
+ $td = $this->getTestDir();
$package = new MemoryPackage('dumpertest/dumpertest', 'master', 'master');
- $package->setSourceUrl("file://$testdir");
+ $package->setSourceUrl("file://$td");
$package->setSourceReference('master');
$package->setSourceType('git');
+ return $package;
+ }
- $name = preg_replace('#[^a-z0-9_-]#', '-', $package->getUniqueName());
-
- $retu = array('package' => $package, 'name' => $name);
- return $retu;
+ protected function getPackageFileName(MemoryPackage $package)
+ {
+ return preg_replace('#[^a-z0-9_-]#', '-', $package->getUniqueName());
}
}
View
7 tests/Composer/Test/Package/Dumper/TarDumperTest.php
@@ -17,9 +17,9 @@ class TarDumperTest extends DumperTest
{
public function testThis()
{
- $retu = $this->getPackageName();
- $package = $retu['package'];
- $name = $retu['name'];
+ $this->setupGitRepo();
+ $package = $this->setupPackage();
+ $name = $this->getPackageFileName($package);
$temp = sys_get_temp_dir();
$tar = new TarDumper($temp);
@@ -30,6 +30,7 @@ public function testThis()
);
$this->assertFileExists($dist);
unlink($dist);
+ $this->removeGitRepo();
}
/**
View
7 tests/Composer/Test/Package/Dumper/ZipDumperTest.php
@@ -17,9 +17,9 @@ class ZipDumperTest extends DumperTest
{
public function testThis()
{
- $retu = $this->getPackageName();
- $package = $retu['package'];
- $name = $retu['name'];
+ $this->setupGitRepo();
+ $package = $this->setupPackage();
+ $name = $this->getPackageFileName($package);
$temp = sys_get_temp_dir();
$zip = new ZipDumper($temp);
@@ -30,6 +30,7 @@ public function testThis()
);
$this->assertFileExists($dist);
unlink($dist);
+ $this->removeGitRepo();
}
/**

0 comments on commit dc25f26

Please sign in to comment.