Permalink
Browse files

Add PimcoreInstaller::inflectPackageVars to respect code normalizatio…

…n of Pimcore plugins. Closes GH-147.
  • Loading branch information...
1 parent 362c970 commit 72fda370a1f045c47915b678db7e4a05f8f2519d @bmarrot bmarrot committed with shama May 4, 2014
View
@@ -1,3 +1,3 @@
vendor/
composer.lock
-.idea/
+.idea/
@@ -6,4 +6,16 @@ class PimcoreInstaller extends BaseInstaller
protected $locations = array(
'plugin' => 'plugins/{$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;
+ }
}
@@ -0,0 +1,44 @@
+<?php
+namespace Composer\Installers\Test;
+
+use Composer\Installers\PimcoreInstaller;
+use Composer\Package\Package;
+use Composer\Composer;
+
+class PimcoreInstallerTest extends TestCase
+{
+ private $composer;
+ private $io;
+
+ /**
+ * setUp
+ *
+ * @return void
+ */
+ public function setUp()
+ {
+ $this->package = new Package('CamelCased', '1.0', '1.0');
+ $this->io = $this->getMock('Composer\IO\PackageInterface');
+ $this->composer = new Composer();
+ }
+
+ /**
+ * testInflectPackageVars
+ *
+ * @return void
+ */
+ public function testInflectPackageVars()
+ {
+ $installer = new PimcoreInstaller($this->package, $this->composer);
+ $result = $installer->inflectPackageVars(array('name' => 'CamelCased'));
+ $this->assertEquals($result, array('name' => 'CamelCased'));
+
+ $installer = new PimcoreInstaller($this->package, $this->composer);
+ $result = $installer->inflectPackageVars(array('name' => 'with-dash'));
+ $this->assertEquals($result, array('name' => 'WithDash'));
+
+ $installer = new PimcoreInstaller($this->package, $this->composer);
+ $result = $installer->inflectPackageVars(array('name' => 'with_underscore'));
+ $this->assertEquals($result, array('name' => 'WithUnderscore'));
+ }
+}

0 comments on commit 72fda37

Please sign in to comment.