Skip to content

Commit

Permalink
Throw an exception if the new config key is in the wrong section (see #3
Browse files Browse the repository at this point in the history
)
  • Loading branch information
leofeyer committed Dec 21, 2018
1 parent 920dd20 commit 0d04932
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
6 changes: 2 additions & 4 deletions README.md
@@ -1,8 +1,6 @@
Contao components installer
===========================

[![](https://img.shields.io/travis/contao-components/installer/master.svg?style=flat-square)](https://travis-ci.org/contao-components/installer/)
[![](https://img.shields.io/coveralls/contao-components/installer/master.svg?style=flat-square)](https://coveralls.io/github/contao-components/installer)
[![](https://img.shields.io/packagist/v/contao-components/installer.svg?style=flat-square)](https://packagist.org/packages/contao-components/installer)
[![](https://img.shields.io/packagist/dt/contao-components/installer.svg?style=flat-square)](https://packagist.org/packages/contao-components/installer)

Expand Down Expand Up @@ -44,8 +42,8 @@ file of your project:

```json
{
"config": {
"component-dir": "assets"
"extra": {
"contao-component-dir": "assets"
}
}
```
Expand Down
14 changes: 10 additions & 4 deletions src/Composer/Plugin.php
Expand Up @@ -41,12 +41,18 @@ private function hasComponentDir(Composer $composer, IOInterface $io)
return true;
}

if ($composer->getConfig()->has('component-dir')) {
$io->write('<warning>Using config.component-dir has been deprecated. Please use extra.contao-component-dir instead.</warning>');
$config = $composer->getConfig();

return true;
if ($config->has('contao-component-dir')) {
throw new \RuntimeException('Found the "contao-component-dir" key in the "config" section. Did you mean to put it into the "extra" section?');
}

if (!$config->has('component-dir')) {
return false;
}

return false;
$io->write('<warning>Using config.component-dir has been deprecated. Please use extra.contao-component-dir instead.</warning>');

return true;
}
}
5 changes: 0 additions & 5 deletions tests/Composer/LibraryInstallerTest.php
Expand Up @@ -30,11 +30,6 @@ protected function setUp()
$this->installer = new LibraryInstaller(new NullIO(), $this->getComposer(), 'contao-component');
}

public function testCanBeInstantiated()
{
$this->assertInstanceOf('Contao\ComponentsInstaller\Composer\LibraryInstaller', $this->installer);
}

public function testSupportsContaoComponents()
{
$this->assertTrue($this->installer->supports('contao-component'));
Expand Down
5 changes: 0 additions & 5 deletions tests/Composer/NoopInstallerTest.php
Expand Up @@ -28,11 +28,6 @@ protected function setUp()
$this->installer = new NoopInstaller();
}

public function testCanBeInstantiated()
{
$this->assertInstanceOf('Contao\ComponentsInstaller\Composer\NoopInstaller', $this->installer);
}

public function testSupportsContaoComponents()
{
$this->assertTrue($this->installer->supports('contao-component'));
Expand Down
37 changes: 29 additions & 8 deletions tests/Composer/PluginTest.php
Expand Up @@ -14,16 +14,13 @@
use Composer\IO\ConsoleIO;
use Composer\IO\NullIO;
use Composer\Package\RootPackage;
use Contao\ComponentsInstaller\Composer\LibraryInstaller;
use Contao\ComponentsInstaller\Composer\NoopInstaller;
use Contao\ComponentsInstaller\Composer\Plugin;
use Contao\ComponentsInstaller\Test\TestCase;

class PluginTest extends TestCase
{
public function testCanBeInstantiated()
{
$this->assertInstanceOf('Contao\ComponentsInstaller\Composer\Plugin', new Plugin());
}

public function testAddsTheInstallerUponActivation()
{
$composer = $this->getComposer();
Expand All @@ -33,7 +30,7 @@ public function testAddsTheInstallerUponActivation()

$installer = $composer->getInstallationManager()->getInstaller('contao-component');

$this->assertInstanceOf('Contao\ComponentsInstaller\Composer\LibraryInstaller', $installer);
$this->assertInstanceOf(LibraryInstaller::class, $installer);
}

public function testAddsTheNoopInstallerIfThereIsNoComponentDir()
Expand All @@ -46,7 +43,7 @@ public function testAddsTheNoopInstallerIfThereIsNoComponentDir()

$installer = $composer->getInstallationManager()->getInstaller('contao-component');

$this->assertInstanceOf('Contao\ComponentsInstaller\Composer\NoopInstaller', $installer);
$this->assertInstanceOf(NoopInstaller::class, $installer);
}

public function testShowsAWarningIfTheOldConfigurationIsUsed()
Expand Down Expand Up @@ -77,6 +74,30 @@ public function testShowsAWarningIfTheOldConfigurationIsUsed()

$installer = $composer->getInstallationManager()->getInstaller('contao-component');

$this->assertInstanceOf('Contao\ComponentsInstaller\Composer\LibraryInstaller', $installer);
$this->assertInstanceOf(LibraryInstaller::class, $installer);
}

public function testFailsIfTheNewConfigurationIsUsedInTheWrongSection()
{
$config = new Config();
$config->merge(
[
'config' => [
'contao-component-dir' => 'assets',
'vendor-dir' => 'vendor',
],
]
);

$composer = $this->getComposer();
$composer->setConfig($config);
$composer->getPackage()->setExtra([]);

$plugin = new Plugin();

$this->expectException('RuntimeException');
$this->expectExceptionMessage('Found the "contao-component-dir" key in the "config" section. Did you mean to put it into the "extra" section?');

$plugin->activate($composer, $this->createMock(ConsoleIO::class));
}
}

0 comments on commit 0d04932

Please sign in to comment.