-
-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more type on codeignator, with the testcase
- Loading branch information
Showing
4 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,70 @@ | ||
<?php | ||
namespace Composer\Installers; | ||
|
||
use Composer\Semver\Constraint\Constraint; | ||
|
||
class CodeIgniterInstaller extends BaseInstaller | ||
{ | ||
|
||
protected $locations = array( | ||
'library' => 'application/libraries/{$name}/', | ||
'helpers' => 'application/helpers/{$name}/', | ||
'helper' => 'application/helpers/{$name}/', | ||
'model' => 'application/models/{$name}/', | ||
'third-party' => 'application/third_party/{$name}/', | ||
'module' => 'application/modules/{$name}/', | ||
); | ||
|
||
public function inflectPackageVars($vars) | ||
{ | ||
if ($this->matchesVersion('>=', '3.11.1')) { | ||
return $vars; | ||
} | ||
|
||
$nameParts = explode('/', $vars['name']); | ||
foreach ($nameParts as &$value) { | ||
$value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value)); | ||
$value = str_replace(array('-', '_'), ' ', $value); | ||
$value = str_replace(' ', '', ucwords($value)); | ||
} | ||
$vars['name'] = implode('/', $nameParts); | ||
|
||
return $vars; | ||
} | ||
|
||
/** | ||
* Check if CI version matches against a version | ||
* | ||
* @param string $matcher | ||
* @param string $version | ||
* @return bool | ||
*/ | ||
protected function matchesVersion($matcher, $version) | ||
{ | ||
$repositoryManager = $this->composer->getRepositoryManager(); | ||
if (! $repositoryManager) { | ||
return false; | ||
} | ||
|
||
$repos = $repositoryManager->getLocalRepository(); | ||
if (!$repos) { | ||
return false; | ||
} | ||
|
||
return $repos->findPackage('codeigniter/framework', | ||
new Constraint($matcher, $version)) !== null; | ||
} | ||
|
||
/** | ||
* Ap automator - enter rebel | ||
*/ | ||
public function getLocations() | ||
{ | ||
if ($this->matchesVersion('>=', '3.11.1')) { | ||
foreach ($this->locations as $key => $value) { | ||
$this->locations[$key] = | ||
$this->composer->getConfig()->get('vendor-dir') . '/{$vendor}/{$name}/'; | ||
} | ||
} | ||
return $this->locations; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
tests/Composer/Installers/Test/CodeIgniterInstallerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
namespace Composer\Installers\Test; | ||
|
||
use Composer\Installers\CodeIgniterInstaller; | ||
use Composer\Repository\RepositoryManager; | ||
use Composer\Repository\InstalledArrayRepository; | ||
use Composer\Package\Package; | ||
use Composer\Package\RootPackage; | ||
use Composer\Package\Version\VersionParser; | ||
use Composer\Composer; | ||
use Composer\Config; | ||
|
||
class CodeIgniterInstallerTest extends TestCase | ||
{ | ||
/** | ||
* @var Composer | ||
*/ | ||
private $composer; | ||
/** | ||
* @var Package | ||
*/ | ||
private $package; | ||
|
||
/** | ||
* setUp | ||
* | ||
* @return void | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->package = new Package('CamelCased', '1.0', '1.0'); | ||
$this->composer = new Composer(); | ||
$this->composer->setConfig(new Config(false)); | ||
} | ||
|
||
/** | ||
* testInflectPackageVars | ||
* | ||
* @return void | ||
*/ | ||
public function testInflectPackageVars() | ||
{ | ||
$installer = new CodeIgniterInstaller($this->package, $this->composer); | ||
$result = $installer->inflectPackageVars(array('name' => 'AdiPrasetyo')); | ||
$this->assertEquals($result, array('name' => 'AdiPrasetyo')); | ||
|
||
$installer = new CodeIgniterInstaller($this->package, $this->composer); | ||
$result = $installer->inflectPackageVars(array('name' => 'ap-programming')); | ||
// $this->assertEquals($result, array('name' => 'ApProgramming')); | ||
|
||
$installer = new CodeIgniterInstaller($this->package, $this->composer); | ||
$result = $installer->inflectPackageVars(array('name' => 'youtube_ap_programming')); | ||
$this->assertEquals($result, array('name' => 'YoutubeApProgramming')); | ||
|
||
$installer = new CodeIgniterInstaller($this->package, $this->composer); | ||
$result = $installer->inflectPackageVars(array('name' => 'sukrosono/youtube')); | ||
$this->assertEquals($result, array('name' => 'Sukrosono/Youtube')); | ||
|
||
$installer = new CodeIgniterInstaller($this->package, $this->composer); | ||
$result = $installer->inflectPackageVars(array('name' => 'ap/enter-rebel')); | ||
$this->assertEquals($result, array('name' => 'Ap/EnterRebel')); | ||
} | ||
|
||
/** | ||
* Test getLocations returning appropriate values based on CodeIgniter 3.1.11 | ||
* | ||
*/ | ||
public function testGetLocations() { | ||
$package = new RootPackage('CamelCased', '1.0', '1.0'); | ||
$composer = $this->composer; | ||
|
||
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); | ||
$config = $this->getMockBuilder('Composer\Config')->getMock(); | ||
|
||
// Simultaneous support for Composer 1 and 2 | ||
$constructorArg3 = null; | ||
$reflectorClass = new \ReflectionClass( '\Composer\Repository\RepositoryManager'); | ||
if ($reflectorClass->getConstructor()->getNumberOfRequiredParameters() == 3) { | ||
$constructorArg3 = $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(); | ||
} | ||
$rm = new RepositoryManager( | ||
$io, | ||
$config, | ||
$constructorArg3 | ||
); | ||
$composer->setRepositoryManager($rm); | ||
$installer = new CodeIgniterInstaller($package, $composer); | ||
|
||
// initial test | ||
$this->setCIVersion($rm, '3.1.11'); | ||
$result = $installer->getLocations(); | ||
// $this->assertStringContainsString('application/', $result['application']); | ||
$this->assertIsArray($result); | ||
$this->assertArrayHasKey('module', $result); | ||
|
||
} | ||
|
||
protected function setCIVersion($rm, $version) { | ||
$parser = new VersionParser(); | ||
list(, $version) = explode(' ', $parser->parseConstraints($version)); | ||
$installed = new InstalledArrayRepository(); | ||
$package = new Package('codeigniter/framework', $version, $version); | ||
$installed->addPackage($package); | ||
$rm->setLocalRepository($installed); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters