Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Flyingmana committed Mar 8, 2016
2 parents 46e3afe + 4ec7f94 commit 66648d3
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion src/MagentoHackathon/Composer/Magento/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/MagentoHackathon/Composer/Magento/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 18 additions & 0 deletions src/MagentoHackathon/Composer/Magento/ProjectConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
}
}
180 changes: 180 additions & 0 deletions tests/MagentoHackathon/Composer/FullStack/Regression/IssueC065Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php
/**
* Copyright (c) 2008-2015 dotSource GmbH.
* All rights reserved.
* http://www.dotsource.de
*
* Created:
* 26.08.2015
*
* Contributors:
* Felix Glaser - initial contents
*
* @category Dotsource
*/

namespace MagentoHackathon\Composer\FullStack\Regression;

use Composer\Util\Filesystem;
use Cotya\ComposerTestFramework;

class IssueC065Test extends ComposerTestFramework\PHPUnit\FullStackTestCase
{
/** @var ComposerTestFramework\Composer\Wrapper */
protected $composer;

/** @var \SplFileInfo */
protected $projectDirectory;

/** @var \SplFileInfo */
protected $artifactDirectory;

/** @var string */
protected $testFilePath;

protected function setUp()
{
$this->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 = <<<MODMAN
app/code/local/* app/code/local/
MODMAN;

$modman->fwrite($modmanContent);
}

/**
* @group regression
*/
public function testIncludeRootPackageNotSet()
{
$this->prepareProject();

$composerJson = new \SplTempFileObject();
$composerJsonContent = <<<JSON
{
"name": "test/module",
"type": "magento-module",
"repositories": [
{
"type": "composer",
"url": "http://packages.firegento.com"
},
{
"type": "artifact",
"url": "$this->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 = <<<JSON
{
"name": "test/module",
"type": "magento-module",
"repositories": [
{
"type": "composer",
"url": "http://packages.firegento.com"
},
{
"type": "artifact",
"url": "$this->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 = <<<JSON
{
"name": "test/module",
"type": "magento-module",
"repositories": [
{
"type": "composer",
"url": "http://packages.firegento.com"
},
{
"type": "artifact",
"url": "$this->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);
}
}
39 changes: 38 additions & 1 deletion tests/MagentoHackathon/Composer/Magento/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 66648d3

Please sign in to comment.