diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d0959c5..402b2558 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fix problems with magento connect packages referencing non existent files - Fix PHP TestSetup for windows with PR [#69](https://github.com/Cotya/magento-composer-installer/pull/69) - Added PR [#73](https://github.com/Cotya/magento-composer-installer/pull/73): add workaround for paths with containing whitespace +- Added functionality to include root package when deploying modules ## [3.0.5] - 2015-08-05 - Fixed Issue [#20](https://github.com/Cotya/magento-composer-installer/issues/20): 'mklink""' is not recognized as an internal or external command, operable program or batch file. diff --git a/README.md b/README.md index c116028d..4722aae5 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,25 @@ Multiple deploys will not add additional lines to your `.gitignore`, they will o Documentation available [here](doc/Autoloading.md). +### Include your project in deployment + +When the magento-composer-installer is run, it only looks for magento-modules among your project's dependencies. Thus, if +your project is a magento-module and you want to test it, you will need a second `composer.json` for deployment, +where your project is configured as a required package. + +If you wish to deploy your project's files (a.k.a. root package), too, you need to setup your `composer.json` as follows: + +``` +{ + "type": "magento-module", + ... + "extra": { + "magento-root-dir": "htdocs/", + "include-root-package": true + } +} +``` + ### Testing First clone the magento-composer-installer, then install the dev-stuff (installed by default): diff --git a/src/MagentoHackathon/Composer/Magento/ModuleManager.php b/src/MagentoHackathon/Composer/Magento/ModuleManager.php index 08799127..fefa2428 100644 --- a/src/MagentoHackathon/Composer/Magento/ModuleManager.php +++ b/src/MagentoHackathon/Composer/Magento/ModuleManager.php @@ -3,6 +3,7 @@ namespace MagentoHackathon\Composer\Magento; use Composer\Package\PackageInterface; +use Composer\Package\RootPackage; use MagentoHackathon\Composer\Magento\Deploy\Manager\Entry; use MagentoHackathon\Composer\Magento\Event\EventManager; use MagentoHackathon\Composer\Magento\Event\PackageDeployEvent; @@ -195,7 +196,12 @@ public function getInstalls(array $currentComposerInstalledPackages) */ private function getPackageSourceDirectory(PackageInterface $package) { - $path = sprintf("%s/%s", $this->config->getVendorDir(), $package->getPrettyName()); + if ($package instanceof RootPackage) { + $path = sprintf("%s/..", $this->config->getVendorDir()); + } else { + $path = sprintf("%s/%s", $this->config->getVendorDir(), $package->getPrettyName()); + } + $targetDir = $package->getTargetDir(); if ($targetDir) { diff --git a/src/MagentoHackathon/Composer/Magento/Plugin.php b/src/MagentoHackathon/Composer/Magento/Plugin.php index 0c5720c8..3b1d468f 100644 --- a/src/MagentoHackathon/Composer/Magento/Plugin.php +++ b/src/MagentoHackathon/Composer/Magento/Plugin.php @@ -215,6 +215,12 @@ function (PackageInterface $package) use ($packageTypeToMatch) { } ); + if ($this->composer->getPackage()->getType() === static::PACKAGE_TYPE + && $this->config->getIncludeRootPackage() === true + ) { + $magentoModules[] = $this->composer->getPackage(); + } + $vendorDir = rtrim($this->composer->getConfig()->get(self::VENDOR_DIR_KEY), '/'); Helper::initMagentoRootDir( diff --git a/src/MagentoHackathon/Composer/Magento/ProjectConfig.php b/src/MagentoHackathon/Composer/Magento/ProjectConfig.php index 8aa74e93..44165319 100644 --- a/src/MagentoHackathon/Composer/Magento/ProjectConfig.php +++ b/src/MagentoHackathon/Composer/Magento/ProjectConfig.php @@ -35,6 +35,8 @@ class ProjectConfig const PATH_MAPPINGS_TRANSLATIONS_KEY = 'path-mapping-translations'; + const INCLUDE_ROOT_PACKAGE_KEY = 'include-root-package'; + // Default Values const DEFAULT_MAGENTO_ROOT_DIR = 'root'; @@ -461,4 +463,20 @@ public function skipSuggestComposerRepositories() { return (bool) $this->fetchVarFromExtraConfig(self::EXTRA_WITH_SKIP_SUGGEST_KEY, false); } + + /** + * @param $includeRootPackage + */ + public function setIncludeRootPackage($includeRootPackage) + { + $this->updateExtraConfig(self::INCLUDE_ROOT_PACKAGE_KEY, trim($includeRootPackage)); + } + + /** + * @return bool + */ + public function getIncludeRootPackage() + { + return (bool)$this->fetchVarFromExtraConfig(self::INCLUDE_ROOT_PACKAGE_KEY); + } } diff --git a/tests/MagentoHackathon/Composer/FullStack/Regression/IssueC065Test.php b/tests/MagentoHackathon/Composer/FullStack/Regression/IssueC065Test.php new file mode 100644 index 00000000..9dd1a473 --- /dev/null +++ b/tests/MagentoHackathon/Composer/FullStack/Regression/IssueC065Test.php @@ -0,0 +1,180 @@ +composer = new ComposerTestFramework\Composer\Wrapper(); + $this->projectDirectory = new \SplFileInfo(self::getTempComposerProjectPath()); + $this->artifactDirectory = new \SplFileInfo(__DIR__.'/../../../../../tests/FullStackTest/artifact'); + $this->testFilePath = $this->projectDirectory->getPathname()."/mage/app/code/local/Test/Module"; + } + + private function prepareProject() + { + $fs = new Filesystem(); + $fs->remove($this->projectDirectory->getPathname()."/mage/app"); + $fs->ensureDirectoryExists($this->projectDirectory->getPathname()."/app/code/local/Test/Module"); + + $modman = new \SplFileObject($this->projectDirectory->getPathname()."/modman", "w"); + $modmanContent = <<fwrite($modmanContent); + } + + /** + * @group regression + */ + public function testIncludeRootPackageNotSet() + { + $this->prepareProject(); + + $composerJson = new \SplTempFileObject(); + $composerJsonContent = <<artifactDirectory/" + } + ], + "require": { + "magento-hackathon/magento-composer-installer": "999.0.0" + }, + "extra": { + "magento-deploy-strategy": "symlink", + "magento-root-dir": "./mage" + } + +} +JSON; + + $composerJson->fwrite($composerJsonContent); + + $this->composer->install($this->projectDirectory, $composerJson); + + $this->assertFileNotExists($this->testFilePath); + } + + /** + * @group regression + */ + public function testIncludeRootPackageIsFalse() + { + $this->prepareProject(); + + + $composerJson = new \SplTempFileObject(); + $composerJsonContent = <<artifactDirectory/" + } + ], + "require": { + "magento-hackathon/magento-composer-installer": "999.0.0" + }, + "extra": { + "magento-deploy-strategy": "symlink", + "magento-root-dir": "./mage", + "include-root-package": false + } + +} +JSON; + + $composerJson->fwrite($composerJsonContent); + + $this->composer->install($this->projectDirectory, $composerJson); + + $this->assertFileNotExists($this->testFilePath); + } + + /** + * @group regression + */ + public function testIncludeRootPackageIsTrue() + { + $this->prepareProject(); + + + $composerJson = new \SplTempFileObject(); + $composerJsonContent = <<artifactDirectory/" + } + ], + "require": { + "magento-hackathon/magento-composer-installer": "999.0.0" + }, + "extra": { + "magento-deploy-strategy": "symlink", + "magento-root-dir": "./mage", + "include-root-package": true + } + +} +JSON; + + $composerJson->fwrite($composerJsonContent); + + $this->composer->install($this->projectDirectory, $composerJson); + + $this->assertFileExists($this->testFilePath); + } +} diff --git a/tests/MagentoHackathon/Composer/Magento/PluginTest.php b/tests/MagentoHackathon/Composer/Magento/PluginTest.php index 9ade6149..4f08e0df 100644 --- a/tests/MagentoHackathon/Composer/Magento/PluginTest.php +++ b/tests/MagentoHackathon/Composer/Magento/PluginTest.php @@ -145,6 +145,37 @@ public function testOnlyMagentoModulePackagesArePassedToModuleManager() $this->plugin->onNewCodeEvent(new \Composer\Script\Event('event', $this->composer, $this->io)); } + public function testRootPackageIsIncludedIfConfigPermits() + { + $rootPackage = $this->createRootPackage(array("include-root-package" => true), "magento-module"); + $this->composer->setPackage($rootPackage); + $this->plugin->activate($this->composer, $this->io); + $moduleManagerMock = $this->getMockBuilder('\MagentoHackathon\Composer\Magento\ModuleManager') + ->disableOriginalConstructor() + ->setMethods(['updateInstalledPackages']) + ->getMock(); + + $this->plugin + ->expects($this->any()) + ->method('getModuleManager') + ->will($this->returnValue($moduleManagerMock)); + + $mPackage1 = $this->createPackage('magento/module1', 'magento-module'); + $mPackage2 = $this->createPackage('magento/module2', 'magento-module'); + $normalPackage = $this->createPackage('normal/module', 'other-module'); + $lRepository = $this->composer->getRepositoryManager()->getLocalRepository(); + $lRepository->addPackage($mPackage1); + $lRepository->addPackage($mPackage2); + $lRepository->addPackage($normalPackage); + + $moduleManagerMock + ->expects($this->once()) + ->method('updateInstalledPackages') + ->with([$mPackage1, $mPackage2, $rootPackage]); + + $this->plugin->onNewCodeEvent(new \Composer\Script\Event('event', $this->composer, $this->io)); + } + /** * Given Magento Composer Installer is configured to skip repository suggestions * When the plugin object is activated @@ -193,11 +224,17 @@ public function testAliasPackagesAreFilteredOut() /** * @param array $extra + * @param string $type * @return RootPackage */ - private function createRootPackage(array $extra = array()) + private function createRootPackage(array $extra = array(), $type = null) { $package = new RootPackage("root/package", "1.0.0", "root/package"); + + if ($type) { + $package->setType($type); + } + $extra['magento-root-dir'] = vfsStream::url('root/htdocs'); $package->setExtra($extra); return $package;