Merge branch 'master' of https://github.com/composer/composer into pull-4431
commit
80bf5b75fc
@ -0,0 +1,65 @@
|
||||
<?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\Archiver;
|
||||
|
||||
use ZipArchive;
|
||||
|
||||
/**
|
||||
* @author Jan Prieser <jan@prieser.net>
|
||||
*/
|
||||
class ZipArchiver implements ArchiverInterface
|
||||
{
|
||||
protected static $formats = array(
|
||||
'zip' => 1
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function archive($sources, $target, $format, array $excludes = array())
|
||||
{
|
||||
$sources = realpath($sources);
|
||||
$zip = new ZipArchive();
|
||||
$res = $zip->open($target, ZipArchive::CREATE);
|
||||
if ($res === true) {
|
||||
$files = new ArchivableFilesFinder($sources, $excludes);
|
||||
foreach($files as $file) {
|
||||
/** @var $file \SplFileInfo */
|
||||
$filepath = $file->getPath()."/".$file->getFilename();
|
||||
$localname = str_replace($sources."/", '', $filepath);
|
||||
$zip->addFile($filepath, $localname);
|
||||
}
|
||||
if ($zip->close()) {
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
$message = sprintf("Could not create archive '%s' from '%s': %s",
|
||||
$target,
|
||||
$sources,
|
||||
$zip->getStatusString()
|
||||
);
|
||||
throw new \RuntimeException($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($format, $sourceType)
|
||||
{
|
||||
return isset(static::$formats[$format]) && $this->compressionAvailable();
|
||||
}
|
||||
|
||||
private function compressionAvailable() {
|
||||
return class_exists('ZipArchive');
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?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\Util;
|
||||
|
||||
/**
|
||||
* Platform helper for uniform platform-specific tests.
|
||||
*
|
||||
* @author Niels Keurentjes <niels.keurentjes@omines.com>
|
||||
*/
|
||||
class Platform
|
||||
{
|
||||
/**
|
||||
* @return bool Whether the host machine is running a Windows OS
|
||||
*/
|
||||
public static function isWindows()
|
||||
{
|
||||
return defined('PHP_WINDOWS_VERSION_BUILD');
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
|
||||
See Github issue #4319 ( github.com/composer/composer/issues/4319 ).
|
||||
|
||||
Present a clear error message when config.platform.php version results in a conflict rule.
|
||||
|
||||
--CONDITION--
|
||||
!defined('HHVM_VERSION')
|
||||
|
||||
--COMPOSER--
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "package",
|
||||
"package": [
|
||||
{ "name": "a", "version": "1.0.0", "require": { "php": "5.5" } }
|
||||
]
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"a": "~1.0"
|
||||
},
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "5.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--RUN--
|
||||
install
|
||||
|
||||
--EXPECT-OUTPUT--
|
||||
Loading composer repositories with package information
|
||||
Installing dependencies (including require-dev)
|
||||
Your requirements could not be resolved to an installable set of packages.
|
||||
|
||||
Problem 1
|
||||
- Installation request for a ~1.0 -> satisfiable by a[1.0.0].
|
||||
- a 1.0.0 requires php 5.5 -> your PHP version (%s) overriden by "config.platform.php" version (5.3) does not satisfy that requirement.
|
||||
|
||||
--EXPECT--
|
||||
|
||||
--EXPECT-EXIT-CODE--
|
||||
2
|
@ -0,0 +1,47 @@
|
||||
--TEST--
|
||||
|
||||
See Github issue #4795 ( github.com/composer/composer/issues/4795 ).
|
||||
|
||||
Composer\Installer::whitelistUpdateDependencies intentionally ignores root requirements even if said package is also a
|
||||
dependency of one the requirements that is whitelisted for update.
|
||||
|
||||
--COMPOSER--
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "package",
|
||||
"package": [
|
||||
{ "name": "a", "version": "1.0.0" },
|
||||
{ "name": "a", "version": "1.1.0" },
|
||||
{ "name": "b", "version": "1.0.0", "require": { "a": "~1.0" } },
|
||||
{ "name": "b", "version": "1.1.0", "require": { "a": "~1.1" } },
|
||||
{ "name": "c", "version": "1.0.0", "require": { "a": "~1.0" } }
|
||||
]
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"a": "~1.0",
|
||||
"b": "~1.0",
|
||||
"c": "~1.0"
|
||||
}
|
||||
}
|
||||
|
||||
--INSTALLED--
|
||||
[
|
||||
{ "name": "a", "version": "1.0.0" },
|
||||
{ "name": "b", "version": "1.0.0", "require": { "a": "~1.0" } },
|
||||
{ "name": "c", "version": "1.0.0", "require": { "a": "~1.0" } }
|
||||
]
|
||||
|
||||
--RUN--
|
||||
update B --with-dependencies
|
||||
|
||||
--EXPECT-OUTPUT--
|
||||
<warning>Dependency "a" is also a root requirement, but is not explicitly whitelisted. Ignoring.</warning>
|
||||
Loading composer repositories with package information
|
||||
Updating dependencies (including require-dev)
|
||||
Nothing to install or update
|
||||
Writing lock file
|
||||
Generating autoload files
|
||||
|
||||
--EXPECT--
|
@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Tries to require a package with the same name as the root package
|
||||
--COMPOSER--
|
||||
{
|
||||
"name": "foo/bar",
|
||||
"require": {
|
||||
"foo/bar": "@dev"
|
||||
}
|
||||
}
|
||||
--RUN--
|
||||
install
|
||||
--EXPECT-EXCEPTION--
|
||||
InvalidArgumentException
|
||||
--EXPECT--
|
||||
Root package 'foo/bar' cannot require itself in its composer.json
|
||||
Did you accidentally name your root package after an external package?
|
@ -0,0 +1,64 @@
|
||||
<?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\Archiver;
|
||||
|
||||
use Composer\Package\Archiver\ZipArchiver;
|
||||
|
||||
class ZipArchiverTest extends ArchiverTest
|
||||
{
|
||||
|
||||
public function testZipArchive()
|
||||
{
|
||||
// Set up repository
|
||||
$this->setupDummyRepo();
|
||||
$package = $this->setupPackage();
|
||||
$target = sys_get_temp_dir().'/composer_archiver_test.zip';
|
||||
|
||||
// Test archive
|
||||
$archiver = new ZipArchiver();
|
||||
$archiver->archive($package->getSourceUrl(), $target, 'zip');
|
||||
$this->assertFileExists($target);
|
||||
|
||||
unlink($target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a local dummy repository to run tests against!
|
||||
*/
|
||||
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.');
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?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\Util;
|
||||
|
||||
use Composer\Util\Platform;
|
||||
|
||||
/**
|
||||
* PlatformTest
|
||||
*
|
||||
* @author Niels Keurentjes <niels.keurentjes@omines.com>
|
||||
*/
|
||||
class PlatformTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testWindows()
|
||||
{
|
||||
// Compare 2 common tests for Windows to the built-in Windows test
|
||||
$this->assertEquals(('\\' === DIRECTORY_SEPARATOR), Platform::isWindows());
|
||||
$this->assertEquals(defined('PHP_WINDOWS_VERSION_MAJOR'), Platform::isWindows());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue