|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Fxp Composer Asset Plugin package. |
| 5 | + * |
| 6 | + * (c) François Pluchino <francois.pluchino@gmail.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Fxp\Composer\AssetPlugin\Tests\Repository; |
| 13 | + |
| 14 | +use Composer\IO\IOInterface; |
| 15 | +use Composer\Repository\RepositoryManager; |
| 16 | +use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager; |
| 17 | +use Fxp\Composer\AssetPlugin\Repository\ResolutionManager; |
| 18 | +use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter; |
| 19 | + |
| 20 | +/** |
| 21 | + * Tests of Asset Repository Manager. |
| 22 | + * |
| 23 | + * @author François Pluchino <francois.pluchino@gmail.com> |
| 24 | + */ |
| 25 | +class AssetRepositoryManagerTest extends \PHPUnit_Framework_TestCase |
| 26 | +{ |
| 27 | + /** |
| 28 | + * @var ResolutionManager|\PHPUnit_Framework_MockObject_MockObject |
| 29 | + */ |
| 30 | + protected $resolutionManager; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var AssetRepositoryManager |
| 34 | + */ |
| 35 | + protected $assertRepositoryManager; |
| 36 | + |
| 37 | + protected function setUp() |
| 38 | + { |
| 39 | + /* @var IOInterface|\PHPUnit_Framework_MockObject_MockObject $io */ |
| 40 | + $io = $this->getMockBuilder(IOInterface::class)->getMock(); |
| 41 | + /* @var RepositoryManager|\PHPUnit_Framework_MockObject_MockObject $rm */ |
| 42 | + $rm = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->getMock(); |
| 43 | + /* @var VcsPackageFilter|\PHPUnit_Framework_MockObject_MockObject $filter */ |
| 44 | + $filter = $this->getMockBuilder(VcsPackageFilter::class)->disableOriginalConstructor()->getMock(); |
| 45 | + |
| 46 | + $this->resolutionManager = $this->getMockBuilder(ResolutionManager::class)->getMock(); |
| 47 | + $this->assertRepositoryManager = new AssetRepositoryManager($io, $rm, $filter); |
| 48 | + } |
| 49 | + |
| 50 | + public function getDataForSolveResolutions() |
| 51 | + { |
| 52 | + return array( |
| 53 | + array(true), |
| 54 | + array(false), |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @dataProvider getDataForSolveResolutions |
| 60 | + * |
| 61 | + * @param bool $withResolutionManager |
| 62 | + */ |
| 63 | + public function testSolveResolutions($withResolutionManager) |
| 64 | + { |
| 65 | + $expected = array( |
| 66 | + 'name' => 'foo/bar', |
| 67 | + ); |
| 68 | + |
| 69 | + if ($withResolutionManager) { |
| 70 | + $this->assertRepositoryManager->setResolutionManager($this->resolutionManager); |
| 71 | + $this->resolutionManager->expects($this->once()) |
| 72 | + ->method('solveResolutions') |
| 73 | + ->with($expected) |
| 74 | + ->willReturn($expected); |
| 75 | + } else { |
| 76 | + $this->resolutionManager->expects($this->never()) |
| 77 | + ->method('solveResolutions'); |
| 78 | + } |
| 79 | + |
| 80 | + $data = $this->assertRepositoryManager->solveResolutions($expected); |
| 81 | + |
| 82 | + $this->assertSame($expected, $data); |
| 83 | + } |
| 84 | +} |
0 commit comments