2 namespace Composer\Installers\Test;
4 use Composer\Installers\Installer;
5 use Composer\Util\Filesystem;
6 use Composer\Package\Package;
7 use Composer\Package\RootPackage;
11 class InstallerTest extends TestCase
27 public function setUp()
29 $this->fs = new Filesystem;
31 $this->composer = new Composer();
32 $this->config = new Config();
33 $this->composer->setConfig($this->config);
35 $this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'baton-test-vendor';
36 $this->ensureDirectoryExistsAndClear($this->vendorDir);
38 $this->binDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'baton-test-bin';
39 $this->ensureDirectoryExistsAndClear($this->binDir);
41 $this->config->merge(array(
43 'vendor-dir' => $this->vendorDir,
44 'bin-dir' => $this->binDir,
48 $this->dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
49 ->disableOriginalConstructor()
51 $this->composer->setDownloadManager($this->dm);
53 $this->repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
54 $this->io = $this->getMock('Composer\IO\IOInterface');
62 public function tearDown()
64 $this->fs->removeDirectory($this->vendorDir);
65 $this->fs->removeDirectory($this->binDir);
73 * @dataProvider dataForTestSupport
75 public function testSupports($type, $expected)
77 $installer = new Installer($this->io, $this->composer);
78 $this->assertSame($expected, $installer->supports($type), sprintf('Failed to show support for %s', $type));
84 public function dataForTestSupport()
87 array('agl-module', true),
88 array('aimeos-extension', true),
89 array('annotatecms-module', true),
90 array('annotatecms-component', true),
91 array('annotatecms-service', true),
92 array('attogram-module', true),
93 array('bitrix-module', true),
94 array('bitrix-component', true),
95 array('bitrix-theme', true),
96 array('bonefish-package', true),
97 array('cakephp', false),
98 array('cakephp-', false),
99 array('cakephp-app', false),
100 array('cakephp-plugin', true),
101 array('chef-cookbook', true),
102 array('chef-role', true),
103 array('cockpit-module', true),
104 array('codeigniter-app', false),
105 array('codeigniter-library', true),
106 array('codeigniter-third-party', true),
107 array('codeigniter-module', true),
108 array('concrete5-block', true),
109 array('concrete5-package', true),
110 array('concrete5-theme', true),
111 array('concrete5-core', true),
112 array('concrete5-update', true),
113 array('craft-plugin', true),
114 array('croogo-plugin', true),
115 array('croogo-theme', true),
116 array('decibel-app', true),
117 array('dokuwiki-plugin', true),
118 array('dokuwiki-template', true),
119 array('drupal-module', true),
120 array('dolibarr-module', true),
121 array('ee3-theme', true),
122 array('ee3-addon', true),
123 array('ee2-theme', true),
124 array('ee2-addon', true),
125 array('elgg-plugin', true),
126 array('eliasis-module', true),
127 array('fuel-module', true),
128 array('fuel-package', true),
129 array('fuel-theme', true),
130 array('fuelphp-component', true),
131 array('hurad-plugin', true),
132 array('hurad-theme', true),
133 array('imagecms-template', true),
134 array('imagecms-module', true),
135 array('imagecms-library', true),
136 array('itop-extension', true),
137 array('joomla-library', true),
138 array('kanboard-plugin', true),
139 array('kirby-plugin', true),
140 array('kohana-module', true),
141 array('laravel-library', true),
142 array('lavalite-theme', true),
143 array('lavalite-package', true),
144 array('lithium-library', true),
145 array('magento-library', true),
146 array('mako-package', true),
147 array('modxevo-snippet', true),
148 array('modxevo-plugin', true),
149 array('modxevo-module', true),
150 array('modxevo-template', true),
151 array('modxevo-lib', true),
152 array('mediawiki-extension', true),
153 array('mediawiki-skin', true),
154 array('microweber-module', true),
155 array('modulework-module', true),
156 array('moodle-mod', true),
157 array('october-module', true),
158 array('october-plugin', true),
159 array('piwik-plugin', true),
160 array('phpbb-extension', true),
161 array('pimcore-plugin', true),
162 array('plentymarkets-plugin', true),
163 array('ppi-module', true),
164 array('prestashop-module', true),
165 array('prestashop-theme', true),
166 array('puppet-module', true),
167 array('porto-container', true),
168 array('radphp-bundle', true),
169 array('redaxo-addon', true),
170 array('redaxo-bestyle-plugin', true),
171 array('reindex-theme', true),
172 array('reindex-plugin', true),
173 array('roundcube-plugin', true),
174 array('shopware-backend-plugin', true),
175 array('shopware-core-plugin', true),
176 array('shopware-frontend-plugin', true),
177 array('shopware-theme', true),
178 array('shopware-plugin', true),
179 array('shopware-frontend-theme', true),
180 array('silverstripe-module', true),
181 array('silverstripe-theme', true),
182 array('smf-module', true),
183 array('smf-theme', true),
184 array('sydes-module', true),
185 array('sydes-theme', true),
186 array('symfony1-plugin', true),
187 array('thelia-module', true),
188 array('thelia-frontoffice-template', true),
189 array('thelia-backoffice-template', true),
190 array('thelia-email-template', true),
191 array('tusk-task', true),
192 array('tusk-asset', true),
193 array('typo3-flow-plugin', true),
194 array('typo3-cms-extension', true),
195 array('vanilla-plugin', true),
196 array('vanilla-theme', true),
197 array('whmcs-gateway', true),
198 array('wolfcms-plugin', true),
199 array('wordpress-plugin', true),
200 array('wordpress-core', false),
201 array('yawik-module', true),
202 array('zend-library', true),
203 array('zikula-module', true),
204 array('zikula-theme', true),
205 array('kodicms-plugin', true),
206 array('kodicms-media', true),
207 array('phifty-bundle', true),
208 array('phifty-library', true),
209 array('phifty-framework', true),
216 * @dataProvider dataForTestInstallPath
218 public function testInstallPath($type, $path, $name, $version = '1.0.0')
220 $installer = new Installer($this->io, $this->composer);
221 $package = new Package($name, $version, $version);
223 $package->setType($type);
224 $result = $installer->getInstallPath($package);
225 $this->assertEquals($path, $result);
229 * dataFormTestInstallPath
231 public function dataForTestInstallPath()
234 array('agl-module', 'More/MyTestPackage/', 'agl/my_test-package'),
235 array('aimeos-extension', 'ext/ai-test/', 'author/ai-test'),
236 array('annotatecms-module', 'addons/modules/my_module/', 'vysinsky/my_module'),
237 array('annotatecms-component', 'addons/components/my_component/', 'vysinsky/my_component'),
238 array('annotatecms-service', 'addons/services/my_service/', 'vysinsky/my_service'),
239 array('attogram-module', 'modules/my_module/', 'author/my_module'),
240 array('bitrix-module', 'bitrix/modules/my_module/', 'author/my_module'),
241 array('bitrix-component', 'bitrix/components/my_component/', 'author/my_component'),
242 array('bitrix-theme', 'bitrix/templates/my_theme/', 'author/my_theme'),
243 array('bitrix-d7-module', 'bitrix/modules/author.my_module/', 'author/my_module'),
244 array('bitrix-d7-component', 'bitrix/components/author/my_component/', 'author/my_component'),
245 array('bitrix-d7-template', 'bitrix/templates/author_my_template/', 'author/my_template'),
246 array('bonefish-package', 'Packages/bonefish/package/', 'bonefish/package'),
247 array('cakephp-plugin', 'Plugin/Ftp/', 'shama/ftp'),
248 array('chef-cookbook', 'Chef/mre/my_cookbook/', 'mre/my_cookbook'),
249 array('chef-role', 'Chef/roles/my_role/', 'mre/my_role'),
250 array('cockpit-module', 'cockpit/modules/addons/My_module/', 'piotr-cz/cockpit-my_module'),
251 array('codeigniter-library', 'application/libraries/my_package/', 'shama/my_package'),
252 array('codeigniter-module', 'application/modules/my_package/', 'shama/my_package'),
253 array('concrete5-block', 'application/blocks/concrete5_block/', 'remo/concrete5_block'),
254 array('concrete5-package', 'packages/concrete5_package/', 'remo/concrete5_package'),
255 array('concrete5-theme', 'application/themes/concrete5_theme/', 'remo/concrete5_theme'),
256 array('concrete5-core', 'concrete/', 'concrete5/core'),
257 array('concrete5-update', 'updates/concrete5/', 'concrete5/concrete5'),
258 array('craft-plugin', 'craft/plugins/my_plugin/', 'mdcpepper/my_plugin'),
259 array('croogo-plugin', 'Plugin/Sitemaps/', 'fahad19/sitemaps'),
260 array('croogo-theme', 'View/Themed/Readable/', 'rchavik/readable'),
261 array('decibel-app', 'app/someapp/', 'author/someapp'),
262 array('dokuwiki-plugin', 'lib/plugins/someplugin/', 'author/someplugin'),
263 array('dokuwiki-template', 'lib/tpl/sometemplate/', 'author/sometemplate'),
264 array('dolibarr-module', 'htdocs/custom/my_module/', 'shama/my_module'),
265 array('drupal-module', 'modules/my_module/', 'shama/my_module'),
266 array('drupal-theme', 'themes/my_module/', 'shama/my_module'),
267 array('drupal-profile', 'profiles/my_module/', 'shama/my_module'),
268 array('drupal-drush', 'drush/my_module/', 'shama/my_module'),
269 array('elgg-plugin', 'mod/sample_plugin/', 'test/sample_plugin'),
270 array('eliasis-module', 'modules/my_module/', 'shama/my_module'),
271 array('ee3-addon', 'system/user/addons/ee_theme/', 'author/ee_theme'),
272 array('ee3-theme', 'themes/user/ee_package/', 'author/ee_package'),
273 array('ee2-addon', 'system/expressionengine/third_party/ee_theme/', 'author/ee_theme'),
274 array('ee2-theme', 'themes/third_party/ee_package/', 'author/ee_package'),
275 array('fuel-module', 'fuel/app/modules/module/', 'fuel/module'),
276 array('fuel-package', 'fuel/packages/orm/', 'fuel/orm'),
277 array('fuel-theme', 'fuel/app/themes/theme/', 'fuel/theme'),
278 array('fuelphp-component', 'components/demo/', 'fuelphp/demo'),
279 array('hurad-plugin', 'plugins/Akismet/', 'atkrad/akismet'),
280 array('hurad-theme', 'plugins/Hurad2013/', 'atkrad/Hurad2013'),
281 array('imagecms-template', 'templates/my_template/', 'shama/my_template'),
282 array('imagecms-module', 'application/modules/my_module/', 'shama/my_module'),
283 array('imagecms-library', 'application/libraries/my_library/', 'shama/my_library'),
284 array('itop-extension', 'extensions/my_extension/', 'shama/my_extension'),
285 array('joomla-plugin', 'plugins/my_plugin/', 'shama/my_plugin'),
286 array('kanboard-plugin', 'plugins/my_plugin/', 'shama/my_plugin'),
287 array('kirby-plugin', 'site/plugins/my_plugin/', 'shama/my_plugin'),
288 array('kohana-module', 'modules/my_package/', 'shama/my_package'),
289 array('laravel-library', 'libraries/my_package/', 'shama/my_package'),
290 array('lavalite-theme', 'public/themes/my_theme/', 'shama/my_theme'),
291 array('lavalite-package', 'packages/my_package/', 'shama/my_package'),
292 array('lithium-library', 'libraries/li3_test/', 'user/li3_test'),
293 array('magento-library', 'lib/foo/', 'test/foo'),
294 array('modxevo-snippet', 'assets/snippets/my_snippet/', 'shama/my_snippet'),
295 array('modxevo-plugin', 'assets/plugins/my_plugin/', 'shama/my_plugin'),
296 array('modxevo-module', 'assets/modules/my_module/', 'shama/my_module'),
297 array('modxevo-template', 'assets/templates/my_template/', 'shama/my_template'),
298 array('modxevo-lib', 'assets/lib/my_lib/', 'shama/my_lib'),
299 array('mako-package', 'app/packages/my_package/', 'shama/my_package'),
300 array('mediawiki-extension', 'extensions/APC/', 'author/APC'),
301 array('mediawiki-extension', 'extensions/APC/', 'author/APC-extension'),
302 array('mediawiki-extension', 'extensions/UploadWizard/', 'author/upload-wizard'),
303 array('mediawiki-extension', 'extensions/SyntaxHighlight_GeSHi/', 'author/syntax-highlight_GeSHi'),
304 array('mediawiki-skin', 'skins/someskin/', 'author/someskin-skin'),
305 array('mediawiki-skin', 'skins/someskin/', 'author/someskin'),
306 array('microweber-module', 'userfiles/modules/my-thing/', 'author/my-thing-module'),
307 array('modulework-module', 'modules/my_package/', 'shama/my_package'),
308 array('moodle-mod', 'mod/my_package/', 'shama/my_package'),
309 array('october-module', 'modules/my_plugin/', 'shama/my_plugin'),
310 array('october-plugin', 'plugins/shama/my_plugin/', 'shama/my_plugin'),
311 array('october-theme', 'themes/my_theme/', 'shama/my_theme'),
312 array('piwik-plugin', 'plugins/VisitSummary/', 'shama/visit-summary'),
313 array('prestashop-module', 'modules/a-module/', 'vendor/a-module'),
314 array('prestashop-theme', 'themes/a-theme/', 'vendor/a-theme'),
315 array('phpbb-extension', 'ext/test/foo/', 'test/foo'),
316 array('phpbb-style', 'styles/foo/', 'test/foo'),
317 array('phpbb-language', 'language/foo/', 'test/foo'),
318 array('pimcore-plugin', 'plugins/MyPlugin/', 'ubikz/my_plugin'),
319 array('plentymarkets-plugin', 'HelloWorld/', 'plugin-hello-world'),
320 array('ppi-module', 'modules/foo/', 'test/foo'),
321 array('puppet-module', 'modules/puppet-name/', 'puppet/puppet-name'),
322 array('porto-container', 'app/Containers/container-name/', 'test/container-name'),
323 array('radphp-bundle', 'src/Migration/', 'atkrad/migration'),
324 array('redaxo-addon', 'redaxo/include/addons/my_plugin/', 'shama/my_plugin'),
325 array('redaxo-bestyle-plugin', 'redaxo/include/addons/be_style/plugins/my_plugin/', 'shama/my_plugin'),
326 array('reindex-theme', 'themes/my_module/', 'author/my_module'),
327 array('reindex-plugin', 'plugins/my_module/', 'author/my_module'),
328 array('roundcube-plugin', 'plugins/base/', 'test/base'),
329 array('roundcube-plugin', 'plugins/replace_dash/', 'test/replace-dash'),
330 array('shopware-backend-plugin', 'engine/Shopware/Plugins/Local/Backend/ShamaMyBackendPlugin/', 'shama/my-backend-plugin'),
331 array('shopware-core-plugin', 'engine/Shopware/Plugins/Local/Core/ShamaMyCorePlugin/', 'shama/my-core-plugin'),
332 array('shopware-frontend-plugin', 'engine/Shopware/Plugins/Local/Frontend/ShamaMyFrontendPlugin/', 'shama/my-frontend-plugin'),
333 array('shopware-theme', 'templates/my_theme/', 'shama/my-theme'),
334 array('shopware-frontend-theme', 'themes/Frontend/ShamaMyFrontendTheme/', 'shama/my-frontend-theme'),
335 array('shopware-plugin', 'custom/plugins/ShamaMyPlugin/', 'shama/my-plugin'),
336 array('silverstripe-module', 'my_module/', 'shama/my_module'),
337 array('silverstripe-module', 'sapphire/', 'silverstripe/framework', '2.4.0'),
338 array('silverstripe-module', 'framework/', 'silverstripe/framework', '3.0.0'),
339 array('silverstripe-module', 'framework/', 'silverstripe/framework', '3.0.0-rc1'),
340 array('silverstripe-module', 'framework/', 'silverstripe/framework', 'my/branch'),
341 array('silverstripe-theme', 'themes/my_theme/', 'shama/my_theme'),
342 array('smf-module', 'Sources/my_module/', 'shama/my_module'),
343 array('smf-theme', 'Themes/my_theme/', 'shama/my_theme'),
344 array('symfony1-plugin', 'plugins/sfShamaPlugin/', 'shama/sfShamaPlugin'),
345 array('symfony1-plugin', 'plugins/sfShamaPlugin/', 'shama/sf-shama-plugin'),
346 array('thelia-module', 'local/modules/my_module/', 'shama/my_module'),
347 array('thelia-frontoffice-template', 'templates/frontOffice/my_template_fo/', 'shama/my_template_fo'),
348 array('thelia-backoffice-template', 'templates/backOffice/my_template_bo/', 'shama/my_template_bo'),
349 array('thelia-email-template', 'templates/email/my_template_email/', 'shama/my_template_email'),
350 array('tusk-task', '.tusk/tasks/my_task/', 'shama/my_task'),
351 array('typo3-flow-package', 'Packages/Application/my_package/', 'shama/my_package'),
352 array('typo3-flow-build', 'Build/my_package/', 'shama/my_package'),
353 array('typo3-cms-extension', 'typo3conf/ext/my_extension/', 'shama/my_extension'),
354 array('vanilla-plugin', 'plugins/my_plugin/', 'shama/my_plugin'),
355 array('vanilla-theme', 'themes/my_theme/', 'shama/my_theme'),
356 array('whmcs-gateway', 'modules/gateways/gateway_name/', 'vendor/gateway_name'),
357 array('wolfcms-plugin', 'wolf/plugins/my_plugin/', 'shama/my_plugin'),
358 array('wordpress-plugin', 'wp-content/plugins/my_plugin/', 'shama/my_plugin'),
359 array('wordpress-muplugin', 'wp-content/mu-plugins/my_plugin/', 'shama/my_plugin'),
360 array('zend-extra', 'extras/library/zend_test/', 'shama/zend_test'),
361 array('zikula-module', 'modules/my-test_module/', 'my/test_module'),
362 array('zikula-theme', 'themes/my-test_theme/', 'my/test_theme'),
363 array('kodicms-media', 'cms/media/vendor/my_media/', 'shama/my_media'),
364 array('kodicms-plugin', 'cms/plugins/my_plugin/', 'shama/my_plugin'),
365 array('phifty-bundle', 'bundles/core/', 'shama/core'),
366 array('phifty-library', 'libraries/my-lib/', 'shama/my-lib'),
367 array('phifty-framework', 'frameworks/my-framework/', 'shama/my-framework'),
368 array('yawik-module', 'module/MyModule/', 'shama/my_module'),
373 * testGetCakePHPInstallPathException
377 * @expectedException \InvalidArgumentException
379 public function testGetCakePHPInstallPathException()
381 $installer = new Installer($this->io, $this->composer);
382 $package = new Package('shama/ftp', '1.0.0', '1.0.0');
384 $package->setType('cakephp-whoops');
385 $result = $installer->getInstallPath($package);
389 * testCustomInstallPath
391 public function testCustomInstallPath()
393 $installer = new Installer($this->io, $this->composer);
394 $package = new Package('shama/ftp', '1.0.0', '1.0.0');
395 $package->setType('cakephp-plugin');
396 $consumerPackage = new RootPackage('foo/bar', '1.0.0', '1.0.0');
397 $this->composer->setPackage($consumerPackage);
398 $consumerPackage->setExtra(array(
399 'installer-paths' => array(
400 'my/custom/path/{$name}/' => array(
406 $result = $installer->getInstallPath($package);
407 $this->assertEquals('my/custom/path/Ftp/', $result);
411 * testCustomInstallerName
413 public function testCustomInstallerName()
415 $installer = new Installer($this->io, $this->composer);
416 $package = new Package('shama/cakephp-ftp-plugin', '1.0.0', '1.0.0');
417 $package->setType('cakephp-plugin');
418 $package->setExtra(array(
419 'installer-name' => 'FTP',
421 $result = $installer->getInstallPath($package);
422 $this->assertEquals('Plugin/FTP/', $result);
428 public function testCustomTypePath()
430 $installer = new Installer($this->io, $this->composer);
431 $package = new Package('slbmeh/my_plugin', '1.0.0', '1.0.0');
432 $package->setType('wordpress-plugin');
433 $consumerPackage = new RootPackage('foo/bar', '1.0.0', '1.0.0');
434 $this->composer->setPackage($consumerPackage);
435 $consumerPackage->setExtra(array(
436 'installer-paths' => array(
437 'my/custom/path/{$name}/' => array(
438 'type:wordpress-plugin'
442 $result = $installer->getInstallPath($package);
443 $this->assertEquals('my/custom/path/my_plugin/', $result);
449 public function testVendorPath()
451 $installer = new Installer($this->io, $this->composer);
452 $package = new Package('penyaskito/my_module', '1.0.0', '1.0.0');
453 $package->setType('drupal-module');
454 $consumerPackage = new RootPackage('drupal/drupal', '1.0.0', '1.0.0');
455 $this->composer->setPackage($consumerPackage);
456 $consumerPackage->setExtra(array(
457 'installer-paths' => array(
458 'modules/custom/{$name}/' => array(
463 $result = $installer->getInstallPath($package);
464 $this->assertEquals('modules/custom/my_module/', $result);
470 public function testNoVendorName()
472 $installer = new Installer($this->io, $this->composer);
473 $package = new Package('sfPhpunitPlugin', '1.0.0', '1.0.0');
475 $package->setType('symfony1-plugin');
476 $result = $installer->getInstallPath($package);
477 $this->assertEquals('plugins/sfPhpunitPlugin/', $result);
481 * testTypo3Inflection
483 public function testTypo3Inflection()
485 $installer = new Installer($this->io, $this->composer);
486 $package = new Package('typo3/fluid', '1.0.0', '1.0.0');
488 $package->setAutoload(array(
490 'TYPO3\\Fluid' => 'Classes',
494 $package->setType('typo3-flow-package');
495 $result = $installer->getInstallPath($package);
496 $this->assertEquals('Packages/Application/TYPO3.Fluid/', $result);
499 public function testUninstallAndDeletePackageFromLocalRepo()
501 $package = new Package('foo', '1.0.0', '1.0.0');
503 $installer = $this->getMock('Composer\Installers\Installer', array('getInstallPath'), array($this->io, $this->composer));
504 $installer->expects($this->once())->method('getInstallPath')->with($package)->will($this->returnValue(sys_get_temp_dir().'/foo'));
506 $repo = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
507 $repo->expects($this->once())->method('hasPackage')->with($package)->will($this->returnValue(true));
508 $repo->expects($this->once())->method('removePackage')->with($package);
510 $installer->uninstall($repo, $package);