Skip to content

Commit

Permalink
Inject the config in the asset repository manager
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Feb 28, 2017
1 parent 2b652ae commit 68fc247
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion FxpAssetPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function activate(Composer $composer, IOInterface $io)
$this->composer = $composer;
$this->io = $io;
$this->packageFilter = new VcsPackageFilter($this->config, $composer->getPackage(), $composer->getInstallationManager(), $installedRepository);
$this->assetRepositoryManager = new AssetRepositoryManager($io, $composer->getRepositoryManager(), $this->packageFilter);
$this->assetRepositoryManager = new AssetRepositoryManager($io, $composer->getRepositoryManager(), $this->config, $this->packageFilter);
$this->assetRepositoryManager->setResolutionManager(new ResolutionManager($this->config->getArray('resolutions')));

AssetPlugin::addRegistryRepositories($this->assetRepositoryManager, $this->packageFilter, $this->config);
Expand Down
20 changes: 19 additions & 1 deletion Repository/AssetRepositoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Composer\IO\IOInterface;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\RepositoryManager;
use Fxp\Composer\AssetPlugin\Config\Config;

/**
* The asset repository manager.
Expand All @@ -33,6 +34,11 @@ class AssetRepositoryManager
*/
protected $rm;

/**
* @var Config
*/
protected $config;

/**
* @var VcsPackageFilter
*/
Expand Down Expand Up @@ -63,12 +69,14 @@ class AssetRepositoryManager
*
* @param IOInterface $io The IO
* @param RepositoryManager $rm The repository manager
* @param Config $config The asset config
* @param VcsPackageFilter $packageFilter The package filter
*/
public function __construct(IOInterface $io, RepositoryManager $rm, VcsPackageFilter $packageFilter)
public function __construct(IOInterface $io, RepositoryManager $rm, Config $config, VcsPackageFilter $packageFilter)
{
$this->io = $io;
$this->rm = $rm;
$this->config = $config;
$this->packageFilter = $packageFilter;
}

Expand All @@ -82,6 +90,16 @@ public function getRepositoryManager()
return $this->rm;
}

/**
* Get the asset config.
*
* @return Config
*/
public function getConfig()
{
return $this->config;
}

/**
* Set the pool.
*
Expand Down
5 changes: 3 additions & 2 deletions Tests/Repository/AbstractAssetsRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Composer\EventDispatcher\EventDispatcher;
use Composer\IO\IOInterface;
use Composer\Repository\RepositoryManager;
use Fxp\Composer\AssetPlugin\Config\Config as AssetConfig;
use Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository;
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager;
use Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository;
Expand Down Expand Up @@ -45,7 +46,7 @@ abstract class AbstractAssetsRepositoryTest extends \PHPUnit_Framework_TestCase
protected $rm;

/**
* @var AssetRepositoryManager|\PHPUnit_Framework_MockObject_MockObject
* @var AssetRepositoryManager
*/
protected $assertRepositoryManager;

Expand Down Expand Up @@ -77,7 +78,7 @@ protected function setUp()
$filter = $this->getMockBuilder(VcsPackageFilter::class)->disableOriginalConstructor()->getMock();
$rm = new RepositoryManager($io, $config);
$rm->setRepositoryClass($this->getType().'-vcs', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\MockAssetRepository');
$this->assertRepositoryManager = new AssetRepositoryManager($io, $rm, $filter);
$this->assertRepositoryManager = new AssetRepositoryManager($io, $rm, new AssetConfig(array()), $filter);
$repoConfig = array_merge(array(
'asset-repository-manager' => $this->assertRepositoryManager,
'asset-options' => array(
Expand Down
14 changes: 13 additions & 1 deletion Tests/Repository/AssetRepositoryManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Composer\IO\IOInterface;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\RepositoryManager;
use Fxp\Composer\AssetPlugin\Config\Config;
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager;
use Fxp\Composer\AssetPlugin\Repository\ResolutionManager;
use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter;
Expand All @@ -36,6 +37,11 @@ class AssetRepositoryManagerTest extends \PHPUnit_Framework_TestCase
*/
protected $io;

/**
* @var Config
*/
protected $config;

/**
* @var VcsPackageFilter|\PHPUnit_Framework_MockObject_MockObject
*/
Expand All @@ -55,10 +61,11 @@ protected function setUp()
{
$this->io = $this->getMockBuilder(IOInterface::class)->getMock();
$this->rm = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->getMock();
$this->config = new Config(array());
$this->filter = $this->getMockBuilder(VcsPackageFilter::class)->disableOriginalConstructor()->getMock();

$this->resolutionManager = $this->getMockBuilder(ResolutionManager::class)->getMock();
$this->assertRepositoryManager = new AssetRepositoryManager($this->io, $this->rm, $this->filter);
$this->assertRepositoryManager = new AssetRepositoryManager($this->io, $this->rm, $this->config, $this->filter);
}

public function getDataForSolveResolutions()
Expand Down Expand Up @@ -128,4 +135,9 @@ public function testAddRepositoryInPool()

$this->assertRepositoryManager->setPool($pool);
}

public function testGetConfig()
{
$this->assertSame($this->config, $this->assertRepositoryManager->getConfig());
}
}

0 comments on commit 68fc247

Please sign in to comment.