]> git.mxchange.org Git - friendica-addons.git/blob
ffe3642557eb3e06d71d720e77039701474f2be4
[friendica-addons.git] /
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\DependencyResolver\Pool;
15 use Composer\IO\IOInterface;
16 use Composer\Repository\RepositoryInterface;
17 use Composer\Repository\RepositoryManager;
18 use Fxp\Composer\AssetPlugin\Config\Config;
19 use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager;
20 use Fxp\Composer\AssetPlugin\Repository\ResolutionManager;
21 use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter;
22
23 /**
24  * Tests of Asset Repository Manager.
25  *
26  * @author François Pluchino <francois.pluchino@gmail.com>
27  */
28 class AssetRepositoryManagerTest extends \PHPUnit_Framework_TestCase
29 {
30     /**
31      * @var RepositoryManager|\PHPUnit_Framework_MockObject_MockObject
32      */
33     protected $rm;
34
35     /**
36      * @var IOInterface|\PHPUnit_Framework_MockObject_MockObject
37      */
38     protected $io;
39
40     /**
41      * @var Config
42      */
43     protected $config;
44
45     /**
46      * @var VcsPackageFilter|\PHPUnit_Framework_MockObject_MockObject
47      */
48     protected $filter;
49
50     /**
51      * @var ResolutionManager|\PHPUnit_Framework_MockObject_MockObject
52      */
53     protected $resolutionManager;
54
55     /**
56      * @var AssetRepositoryManager
57      */
58     protected $assetRepositoryManager;
59
60     protected function setUp()
61     {
62         $this->io = $this->getMockBuilder(IOInterface::class)->getMock();
63         $this->rm = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->getMock();
64         $this->config = new Config(array());
65         $this->filter = $this->getMockBuilder(VcsPackageFilter::class)->disableOriginalConstructor()->getMock();
66
67         $this->resolutionManager = $this->getMockBuilder(ResolutionManager::class)->getMock();
68         $this->assetRepositoryManager = new AssetRepositoryManager($this->io, $this->rm, $this->config, $this->filter);
69     }
70
71     public function getDataForSolveResolutions()
72     {
73         return array(
74             array(true),
75             array(false),
76         );
77     }
78
79     /**
80      * @dataProvider getDataForSolveResolutions
81      *
82      * @param bool $withResolutionManager
83      */
84     public function testSolveResolutions($withResolutionManager)
85     {
86         $expected = array(
87             'name' => 'foo/bar',
88         );
89
90         if ($withResolutionManager) {
91             $this->assetRepositoryManager->setResolutionManager($this->resolutionManager);
92             $this->resolutionManager->expects($this->once())
93                 ->method('solveResolutions')
94                 ->with($expected)
95                 ->willReturn($expected);
96         } else {
97             $this->resolutionManager->expects($this->never())
98                 ->method('solveResolutions');
99         }
100
101         $data = $this->assetRepositoryManager->solveResolutions($expected);
102
103         $this->assertSame($expected, $data);
104     }
105
106     public function testAddRepositoryInPool()
107     {
108         $repos = array(
109             array(
110                 'name' => 'foo/bar',
111                 'type' => 'asset-vcs',
112                 'url' => 'https://github.com/helloguest/helloguest-ui-app.git',
113             ),
114         );
115
116         $repoConfigExpected = array_merge($repos[0], array(
117             'asset-repository-manager' => $this->assetRepositoryManager,
118             'vcs-package-filter' => $this->filter,
119         ));
120
121         $repo = $this->getMockBuilder(RepositoryInterface::class)->getMock();
122
123         $this->rm->expects($this->once())
124             ->method('createRepository')
125             ->with('asset-vcs', $repoConfigExpected)
126             ->willReturn($repo);
127
128         $this->assetRepositoryManager->addRepositories($repos);
129
130         /* @var Pool|\PHPUnit_Framework_MockObject_MockObject $pool */
131         $pool = $this->getMockBuilder(Pool::class)->disableOriginalConstructor()->getMock();
132         $pool->expects($this->once())
133             ->method('addRepository')
134             ->with($repo);
135
136         $this->assetRepositoryManager->setPool($pool);
137     }
138
139     public function testGetConfig()
140     {
141         $this->assertSame($this->config, $this->assetRepositoryManager->getConfig());
142     }
143 }