12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace Composer\Test\Package\Archiver;
- use Composer\Package\Archiver\ZipArchiver;
- class ZipArchiverTest extends ArchiverTest
- {
- public function testZipArchive()
- {
- if (!class_exists('ZipArchive')) {
- $this->markTestSkipped('Cannot run ZipArchiverTest, missing class "ZipArchive".');
- }
-
- $this->setupDummyRepo();
- $package = $this->setupPackage();
- $target = sys_get_temp_dir().'/composer_archiver_test.zip';
-
- $archiver = new ZipArchiver();
- $archiver->archive($package->getSourceUrl(), $target, 'zip');
- $this->assertFileExists($target);
- unlink($target);
- }
-
- protected function setupDummyRepo()
- {
- $currentWorkDir = getcwd();
- chdir($this->testDir);
- $this->writeFile('file.txt', 'content', $currentWorkDir);
- $this->writeFile('foo/bar/baz', 'content', $currentWorkDir);
- $this->writeFile('foo/bar/ignoreme', 'content', $currentWorkDir);
- $this->writeFile('x/baz', 'content', $currentWorkDir);
- $this->writeFile('x/includeme', 'content', $currentWorkDir);
- chdir($currentWorkDir);
- }
- protected function writeFile($path, $content, $currentWorkDir)
- {
- if (!file_exists(dirname($path))) {
- mkdir(dirname($path), 0777, true);
- }
- $result = file_put_contents($path, 'a');
- if (false === $result) {
- chdir($currentWorkDir);
- throw new \RuntimeException('Could not save file.');
- }
- }
- }
|