-
-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add more type on codeigniter custom install #487
Open
sukrosono
wants to merge
5
commits into
composer:main
Choose a base branch
from
sukrosono:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
806077e
add new type
sukrosono 1e41178
add more type on codeignator, with the testcase
sukrosono 49325fb
drop the z on version x.y.z
sukrosono 515a8ba
using 2 space, retrigger personal travis build
sukrosono 47514c9
trigger travis
sukrosono File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,11 +1,70 @@ | ||
<?php | ||
namespace Composer\Installers; | ||
|
||
use Composer\Semver\Constraint\Constraint; | ||
|
||
class CodeIgniterInstaller extends BaseInstaller | ||
{ | ||
|
||
protected $locations = array( | ||
'library' => 'application/libraries/{$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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... Why used non-existed version? I don't see this version on releases page: https://github.com/bcit-ci/CodeIgniter/releases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current version is 3.1.11, but you comparing with 3.11 version. It's error?