Skip to content

Commit

Permalink
Basic Composer 2 support.
Browse files Browse the repository at this point in the history
More reivew/tests are probably needed.
  • Loading branch information
mbaynton committed Feb 3, 2020
1 parent 71a969f commit c839b37
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ php:
- 7.3
- nightly

matrix:
env:
- DEPS=latest
- DEPS=lowest

jobs:
include:
- dist: precise
php: 5.3
Expand All @@ -27,7 +31,7 @@ matrix:

before_script:
- composer self-update
- composer install
- composer update --prefer-$DEPS

script:
- composer test
- vendor/bin/composer test
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@
"roundcube/plugin-installer": "*"
},
"require": {
"composer-plugin-api": "^1.0"
"composer-plugin-api": "^1.0|^2.0"
},
"require-dev": {
"composer/composer": "1.0.*@dev",
"phpunit/phpunit": "^4.8.36"
"composer/composer": "1.0.0|2.0.*@dev",
"phpunit/phpunit": "^4.8.36",
"sebastian/comparator": ">= 1.2.4",
"symfony/process": ">= 2.3"
},
"scripts": {
"test": "phpunit"
Expand Down
28 changes: 9 additions & 19 deletions src/Composer/Installers/CakePHPInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,15 @@ protected function matchesCakeVersion($matcher, $version)
}

$repositoryManager = $this->composer->getRepositoryManager();
if ($repositoryManager) {
$repos = $repositoryManager->getLocalRepository();
if (!$repos) {
return false;
}
$cake3 = new $multiClass(array(
new $constraintClass($matcher, $version),
new $constraintClass('!=', '9999999-dev'),
));
$pool = new Pool('dev');
$pool->addRepository($repos);
$packages = $pool->whatProvides('cakephp/cakephp');
foreach ($packages as $package) {
$installed = new $constraintClass('=', $package->getVersion());
if ($cake3->matches($installed)) {
return true;
}
}
if (! $repositoryManager) {
return false;
}
return false;

$repos = $repositoryManager->getLocalRepository();
if (!$repos) {
return false;
}

return $repos->findPackage('cakephp/cakephp', new $constraintClass($matcher, $version)) !== null;
}
}
19 changes: 12 additions & 7 deletions tests/Composer/Installers/Test/CakePHPInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,19 @@ public function testInflectPackageVars()
public function testGetLocations() {
$package = new RootPackage('CamelCased', '1.0', '1.0');
$composer = $this->composer;

$io = $this->getMock('Composer\IO\IOInterface');
$config = $this->getMock('Composer\Config');

// Simultaneous support for Composer 1 and 2
$constructorArg3 = null;
if ((new \ReflectionClass( '\Composer\Repository\RepositoryManager'))->getConstructor()->getNumberOfRequiredParameters() == 3) {
$constructorArg3 = $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock();
}
$rm = new RepositoryManager(
$this->getMock('Composer\IO\IOInterface'),
$this->getMock('Composer\Config')
$io,
$config,
$constructorArg3
);
$composer->setRepositoryManager($rm);
$installer = new CakePHPInstaller($package, $composer);
Expand All @@ -83,11 +93,6 @@ public function testGetLocations() {
$result = $installer->getLocations();
$this->assertContains('Plugin/', $result['plugin']);

// special handling for 2.x versions when 3.x is still in development
$this->setCakephpVersion($rm, 'dev-master');
$result = $installer->getLocations();
$this->assertContains('Plugin/', $result['plugin']);

$this->setCakephpVersion($rm, '>=2.5');
$result = $installer->getLocations();
$this->assertContains('Plugin/', $result['plugin']);
Expand Down

0 comments on commit c839b37

Please sign in to comment.