Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

the .tar.gz dump functionality #4

Merged
merged 5 commits into from

1 participant

@ghost

the .tar dump functionality etc

@till till was assigned
@ghost

Here's a new one.

tests/Composer/Test/Package/Dumper/DumperTest.php
((3 lines not shown))
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ * Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Test\Package\Dumper;
+
+use Composer\Package\MemoryPackage;
+
+abstract class DumperTest extends \PHPUnit_Framework_TestCase
+{
+ public function getPackageName()
@till Owner
till added a note

Almost there, split this into:

  • protected function setupGitRepo()
  • protected function setupPackage() // returns the MemoryPackage
  • getPackageFileName(PackageInterface $package) // returns the preg_replace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/Composer/Test/Package/Dumper/DumperTest.php
((5 lines not shown))
+ * (c) Nils Adermann <naderman@naderman.de>
+ * Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Test\Package\Dumper;
+
+use Composer\Package\MemoryPackage;
+
+abstract class DumperTest extends \PHPUnit_Framework_TestCase
+{
+ public function getPackageName()
+ {
+ $testdir = '/tmp/composer_dumpertest_git_repository';
@till Owner
till added a note

Use sys_get_temp_dir() here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/Composer/Test/Package/Dumper/DumperTest.php
((4 lines not shown))
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ * Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Test\Package\Dumper;
+
+use Composer\Package\MemoryPackage;
+
+abstract class DumperTest extends \PHPUnit_Framework_TestCase
+{
+ public function getPackageName()
+ {
@till Owner
till added a note

Make this a protected class variable so you can clean it up after the test ran.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Ulf Harnhammar added some commits
@till till merged commit 3b72a04 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 18, 2012
  1. new functionality for dumping as .tar.gz

    Ulf Harnhammar authored
  2. tar instead of tar.gz, new abstract dumpertest class

    Ulf Harnhammar authored
  3. creates a local git repo instead of fetching a remote one

    Ulf Harnhammar authored
  4. more oo-ish version of it

    Ulf Harnhammar authored
  5. no constructor

    Ulf Harnhammar authored
This page is out of date. Refresh to see the latest.
View
52 src/Composer/Package/Dumper/TarDumper.php
@@ -0,0 +1,52 @@
+<?php
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ * Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Package\Dumper;
+
+use Composer\Package\Dumper\BaseDumper;
+use Composer\Package\Dumper\DumperInterface;
+use Composer\Package\PackageInterface;
+use Composer\Util\ProcessExecutor;
+
+/**
+ * @author Ulf Härnhammar <ulfharn@gmail.com>
+ */
+class TarDumper extends BaseDumper
+{
+ protected $format = 'tar';
+
+ public function dump(PackageInterface $package)
+ {
+ $workDir = $this->getAndEnsureWorkDirectory($package);
+
+ $fileName = $this->getFilename($package, 'tar');
+ $sourceType = $package->getSourceType();
+ $sourceRef = $package->getSourceReference();
+
+ switch ($sourceType) {
+ case 'git':
+ $this->downloadGit($package, $workDir);
+ $this->packageGit($fileName, $sourceRef, $workDir);
+ break;
+ case 'hg':
+ $this->downloadHg($package, $workDir);
+ $this->packageHg($fileName, $sourceRef, $workDir);
+ break;
+ case 'svn':
+ $dir = $workDir . (substr($sourceRef, 0, 1) !== '/')?'/':'' . $sourceRef;
+ $this->downloadSvn($package, $workDir);
+ $this->package($fileName, $dir, \Phar::TAR);
+ break;
+ default:
+ throw new \InvalidArgumentException("Unable to handle repositories of type '{$sourceType}'.");
+ }
+ }
+}
View
57 tests/Composer/Test/Package/Dumper/DumperTest.php
@@ -0,0 +1,57 @@
+<?php
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ * Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Test\Package\Dumper;
+
+use Composer\Package\MemoryPackage;
+
+abstract class DumperTest extends \PHPUnit_Framework_TestCase
+{
+ protected $testdir = '';
+
+ public function setUp()
+ {
+ $this->testdir = sys_get_temp_dir() . '/composer_dumpertest_git_repository' . mt_rand();
+ }
+
+ protected function getTestDir()
+ {
+ return $this->testdir;
+ }
+
+ protected function setupGitRepo()
+ {
+ $td = $this->getTestDir();
+ system("rm -rf $td; mkdir $td");
+ system("cd $td; 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://$td");
+ $package->setSourceReference('master');
+ $package->setSourceType('git');
+ return $package;
+ }
+
+ protected function getPackageFileName(MemoryPackage $package)
+ {
+ return preg_replace('#[^a-z0-9_-]#', '-', $package->getUniqueName());
+ }
+}
View
43 tests/Composer/Test/Package/Dumper/TarDumperTest.php
@@ -0,0 +1,43 @@
+<?php
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ * Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Test\Package\Dumper;
+
+use Composer\Package\Dumper\TarDumper;
+
+class TarDumperTest extends DumperTest
+{
+ public function testThis()
+ {
+ $this->setupGitRepo();
+ $package = $this->setupPackage();
+ $name = $this->getPackageFileName($package);
+
+ $temp = sys_get_temp_dir();
+ $tar = new TarDumper($temp);
+ $tar->dump($package);
+
+ $dist = sprintf('%s/%s.tar',
+ $temp, $name
+ );
+ $this->assertFileExists($dist);
+ unlink($dist);
+ $this->removeGitRepo();
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testException()
+ {
+ new TarDumper("/totally-random-" . time());
+ }
+}
View
19 tests/Composer/Test/Package/Dumper/ZipDumperTest.php
@@ -12,32 +12,25 @@
namespace Composer\Test\Package\Dumper;
use Composer\Package\Dumper\ZipDumper;
-use Composer\Package\MemoryPackage;
-class ZipDumperTest extends \PHPUnit_Framework_TestCase
+class ZipDumperTest extends DumperTest
{
- /**
- * @todo Replace with local git repo to run offline.
- */
public function testThis()
{
- $package = new MemoryPackage('lagged/Lagged_Session_SaveHandler_Memcache', '0.5.0', '0.5.0');
- $package->setSourceUrl('git://github.com/lagged/Lagged_Session_SaveHandler_Memcache.git');
- $package->setSourceReference('0.5.0');
- $package->setSourceType('git');
+ $this->setupGitRepo();
+ $package = $this->setupPackage();
+ $name = $this->getPackageFileName($package);
$temp = sys_get_temp_dir();
-
$zip = new ZipDumper($temp);
$zip->dump($package);
- $name = preg_replace('#[^a-z0-9_-]#', '-', $package->getUniqueName());
-
$dist = sprintf('%s/%s.zip',
$temp, $name
);
$this->assertFileExists($dist);
unlink($dist);
+ $this->removeGitRepo();
}
/**
@@ -47,4 +40,4 @@ public function testException()
{
new ZipDumper("/totally-random-" . time());
}
-}
+}
Something went wrong with that request. Please try again.