Skip to content

Commit

Permalink
Add installer for Processwire module (#472)
Browse files Browse the repository at this point in the history
* Add ProcessWire installer

* Inflect package names to CamelCase

* Add tests

* Add readme
  • Loading branch information
daun committed Jan 12, 2021
1 parent 02652f4 commit 9d4e028
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ is not needed to install packages with these frameworks:
| PPI | **`ppi-module`**
| Puppet | `puppet-module`
| Porto | `porto-container`
| ProcessWire | `processwire-module`
| RadPHP | `radphp-bundle`
| REDAXO | `redaxo-addon`
| REDAXO bestyle-plugin | `redaxo-bestyle-plugin`
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"PPI",
"Puppet",
"Porto",
"ProcessWire",
"RadPHP",
"ReIndex",
"Roundcube",
Expand Down
1 change: 1 addition & 0 deletions src/Composer/Installers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Installer extends LibraryInstaller
'radphp' => 'RadPHPInstaller',
'phifty' => 'PhiftyInstaller',
'porto' => 'PortoInstaller',
'processwire' => 'ProcessWireInstaller',
'redaxo' => 'RedaxoInstaller',
'redaxo5' => 'Redaxo5Installer',
'reindex' => 'ReIndexInstaller',
Expand Down
22 changes: 22 additions & 0 deletions src/Composer/Installers/ProcessWireInstaller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Composer\Installers;

class ProcessWireInstaller extends BaseInstaller
{
protected $locations = array(
'module' => 'site/modules/{$name}/',
);

/**
* Format package name to CamelCase
*/
public function inflectPackageVars($vars)
{
$vars['name'] = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $vars['name']));
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']);
$vars['name'] = str_replace(' ', '', ucwords($vars['name']));

return $vars;
}
}
2 changes: 2 additions & 0 deletions tests/Composer/Installers/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public function dataForTestSupport()
array('prestashop-theme', true),
array('puppet-module', true),
array('porto-container', true),
array('processwire-module', true),
array('radphp-bundle', true),
array('redaxo-addon', true),
array('redaxo-bestyle-plugin', true),
Expand Down Expand Up @@ -404,6 +405,7 @@ public function dataForTestInstallPath()
array('puppet-module', 'modules/puppet-name/', 'puppet/puppet-name'),
array('porto-container', 'app/Containers/container-name/', 'test/container-name'),
array('radphp-bundle', 'src/Migration/', 'atkrad/migration'),
array('processwire-module', 'site/modules/HelloWorld/', 'test/hello-world'),
array('redaxo-addon', 'redaxo/include/addons/my_plugin/', 'shama/my_plugin'),
array('redaxo-bestyle-plugin', 'redaxo/include/addons/be_style/plugins/my_plugin/', 'shama/my_plugin'),
array('redaxo5-addon', 'redaxo/src/addons/my_plugin/', 'shama/my_plugin'),
Expand Down
44 changes: 44 additions & 0 deletions tests/Composer/Installers/Test/ProcessWireInstallerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace Composer\Installers\Test;

use Composer\Installers\ProcessWireInstaller;
use Composer\Package\Package;
use Composer\Composer;

class ProcessWireInstallerTest extends TestCase
{
private $composer;
private $io;
private $package;

/**
* setUp
*
* @return void
*/
public function setUp()
{
$this->package = new Package('CamelCased', '1.0', '1.0');
$this->composer = new Composer();
}

/**
* testInflectPackageVars
*
* @return void
*/
public function testInflectPackageVars()
{
$installer = new ProcessWireInstaller($this->package, $this->composer);
$result = $installer->inflectPackageVars(array('name' => 'CamelCased'));
$this->assertEquals($result, array('name' => 'CamelCased'));

$installer = new ProcessWireInstaller($this->package, $this->composer);
$result = $installer->inflectPackageVars(array('name' => 'with-dash'));
$this->assertEquals($result, array('name' => 'WithDash'));

$installer = new ProcessWireInstaller($this->package, $this->composer);
$result = $installer->inflectPackageVars(array('name' => 'with_underscore'));
$this->assertEquals($result, array('name' => 'WithUnderscore'));
}
}

0 comments on commit 9d4e028

Please sign in to comment.