-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of dependencies resolution to solve the conflicts
- Loading branch information
1 parent
1baac76
commit d65dabd
Showing
11 changed files
with
303 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fxp Composer Asset Plugin package. | ||
* | ||
* (c) François Pluchino <francois.pluchino@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fxp\Composer\AssetPlugin\Repository; | ||
|
||
/** | ||
* Solve the conflicts of dependencies by the resolutions. | ||
* | ||
* @author François Pluchino <francois.pluchino@gmail.com> | ||
*/ | ||
class ResolutionManager | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $resolutions; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param array $resolutions The dependency resolutions | ||
*/ | ||
public function __construct(array $resolutions = array()) | ||
{ | ||
$this->resolutions = $resolutions; | ||
} | ||
|
||
/** | ||
* Solve the dependency resolutions. | ||
* | ||
* @param array $data The data of asset composer package | ||
* | ||
* @return array | ||
*/ | ||
public function solveResolutions(array $data) | ||
{ | ||
$data = $this->doSolveResolutions($data, 'require'); | ||
$data = $this->doSolveResolutions($data, 'require-dev'); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* Solve the dependency resolutions. | ||
* | ||
* @param array $data The data of asset composer package | ||
* @param string $section The dependency section in package | ||
* | ||
* @return array | ||
*/ | ||
protected function doSolveResolutions(array $data, $section) | ||
{ | ||
if (array_key_exists($section, $data) && is_array($data[$section])) { | ||
foreach ($data[$section] as $dependency => &$range) { | ||
foreach ($this->resolutions as $resolutionDependency => $resolutionRange) { | ||
if ($dependency === $resolutionDependency) { | ||
$range = $resolutionRange; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fxp Composer Asset Plugin package. | ||
* | ||
* (c) François Pluchino <francois.pluchino@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fxp\Composer\AssetPlugin\Tests\Repository; | ||
|
||
use Composer\IO\IOInterface; | ||
use Composer\Repository\RepositoryManager; | ||
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager; | ||
use Fxp\Composer\AssetPlugin\Repository\ResolutionManager; | ||
use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter; | ||
|
||
/** | ||
* Tests of Asset Repository Manager. | ||
* | ||
* @author François Pluchino <francois.pluchino@gmail.com> | ||
*/ | ||
class AssetRepositoryManagerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ResolutionManager|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $resolutionManager; | ||
|
||
/** | ||
* @var AssetRepositoryManager | ||
*/ | ||
protected $assertRepositoryManager; | ||
|
||
protected function setUp() | ||
{ | ||
/* @var IOInterface|\PHPUnit_Framework_MockObject_MockObject $io */ | ||
$io = $this->getMockBuilder(IOInterface::class)->getMock(); | ||
/* @var RepositoryManager|\PHPUnit_Framework_MockObject_MockObject $rm */ | ||
$rm = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->getMock(); | ||
/* @var VcsPackageFilter|\PHPUnit_Framework_MockObject_MockObject $filter */ | ||
$filter = $this->getMockBuilder(VcsPackageFilter::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$this->resolutionManager = $this->getMockBuilder(ResolutionManager::class)->getMock(); | ||
$this->assertRepositoryManager = new AssetRepositoryManager($io, $rm, $filter); | ||
} | ||
|
||
public function getDataForSolveResolutions() | ||
{ | ||
return array( | ||
array(true), | ||
array(false), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider getDataForSolveResolutions | ||
* | ||
* @param bool $withResolutionManager | ||
*/ | ||
public function testSolveResolutions($withResolutionManager) | ||
{ | ||
$expected = array( | ||
'name' => 'foo/bar', | ||
); | ||
|
||
if ($withResolutionManager) { | ||
$this->assertRepositoryManager->setResolutionManager($this->resolutionManager); | ||
$this->resolutionManager->expects($this->once()) | ||
->method('solveResolutions') | ||
->with($expected) | ||
->willReturn($expected); | ||
} else { | ||
$this->resolutionManager->expects($this->never()) | ||
->method('solveResolutions'); | ||
} | ||
|
||
$data = $this->assertRepositoryManager->solveResolutions($expected); | ||
|
||
$this->assertSame($expected, $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fxp Composer Asset Plugin package. | ||
* | ||
* (c) François Pluchino <francois.pluchino@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fxp\Composer\AssetPlugin\Tests\Repository; | ||
|
||
use Fxp\Composer\AssetPlugin\Repository\ResolutionManager; | ||
|
||
/** | ||
* Tests of Resolution Manager. | ||
* | ||
* @author François Pluchino <francois.pluchino@gmail.com> | ||
*/ | ||
class ResolutionManagerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testSolveResolutions() | ||
{ | ||
$rm = new ResolutionManager(array( | ||
'foo/bar' => '^2.2.0', | ||
'bar/foo' => '^0.2.0', | ||
)); | ||
|
||
$data = $rm->solveResolutions(array( | ||
'require' => array( | ||
'foo/bar' => '2.0.*', | ||
'foo/baz' => '~1.0', | ||
), | ||
'require-dev' => array( | ||
'bar/foo' => '^0.1.0', | ||
'test/dev' => '~1.0@dev', | ||
), | ||
)); | ||
|
||
$expected = array( | ||
'require' => array( | ||
'foo/bar' => '^2.2.0', | ||
'foo/baz' => '~1.0', | ||
), | ||
'require-dev' => array( | ||
'bar/foo' => '^0.2.0', | ||
'test/dev' => '~1.0@dev', | ||
), | ||
); | ||
|
||
$this->assertSame($expected, $data); | ||
} | ||
} |