annotate vendor/composer/installers/tests/Composer/Installers/Test/CakePHPInstallerTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
rev   line source
Chris@0 1 <?php
Chris@0 2 namespace Composer\Installers\Test;
Chris@0 3
Chris@0 4 use Composer\Installers\CakePHPInstaller;
Chris@0 5 use Composer\Repository\RepositoryManager;
Chris@0 6 use Composer\Repository\InstalledArrayRepository;
Chris@0 7 use Composer\Package\Package;
Chris@0 8 use Composer\Package\RootPackage;
Chris@0 9 use Composer\Package\Version\VersionParser;
Chris@0 10 use Composer\Composer;
Chris@0 11 use Composer\Config;
Chris@0 12
Chris@0 13 class CakePHPInstallerTest extends TestCase
Chris@0 14 {
Chris@0 15 private $composer;
Chris@0 16 private $io;
Chris@0 17
Chris@0 18 /**
Chris@0 19 * setUp
Chris@0 20 *
Chris@0 21 * @return void
Chris@0 22 */
Chris@0 23 public function setUp()
Chris@0 24 {
Chris@0 25 $this->package = new Package('CamelCased', '1.0', '1.0');
Chris@0 26 $this->io = $this->getMock('Composer\IO\PackageInterface');
Chris@0 27 $this->composer = new Composer();
Chris@0 28 $this->composer->setConfig(new Config(false));
Chris@0 29 }
Chris@0 30
Chris@0 31 /**
Chris@0 32 * testInflectPackageVars
Chris@0 33 *
Chris@0 34 * @return void
Chris@0 35 */
Chris@0 36 public function testInflectPackageVars()
Chris@0 37 {
Chris@0 38 $installer = new CakePHPInstaller($this->package, $this->composer);
Chris@0 39 $result = $installer->inflectPackageVars(array('name' => 'CamelCased'));
Chris@0 40 $this->assertEquals($result, array('name' => 'CamelCased'));
Chris@0 41
Chris@0 42 $installer = new CakePHPInstaller($this->package, $this->composer);
Chris@0 43 $result = $installer->inflectPackageVars(array('name' => 'with-dash'));
Chris@0 44 $this->assertEquals($result, array('name' => 'WithDash'));
Chris@0 45
Chris@0 46 $installer = new CakePHPInstaller($this->package, $this->composer);
Chris@0 47 $result = $installer->inflectPackageVars(array('name' => 'with_underscore'));
Chris@0 48 $this->assertEquals($result, array('name' => 'WithUnderscore'));
Chris@0 49
Chris@0 50 $installer = new CakePHPInstaller($this->package, $this->composer);
Chris@0 51 $result = $installer->inflectPackageVars(array('name' => 'cake/acl'));
Chris@0 52 $this->assertEquals($result, array('name' => 'Cake/Acl'));
Chris@0 53
Chris@0 54 $installer = new CakePHPInstaller($this->package, $this->composer);
Chris@0 55 $result = $installer->inflectPackageVars(array('name' => 'cake/debug-kit'));
Chris@0 56 $this->assertEquals($result, array('name' => 'Cake/DebugKit'));
Chris@0 57 }
Chris@0 58
Chris@0 59 /**
Chris@0 60 * Test getLocations returning appropriate values based on CakePHP version
Chris@0 61 *
Chris@0 62 */
Chris@0 63 public function testGetLocations() {
Chris@0 64 $package = new RootPackage('CamelCased', '1.0', '1.0');
Chris@0 65 $composer = $this->composer;
Chris@0 66 $rm = new RepositoryManager(
Chris@0 67 $this->getMock('Composer\IO\IOInterface'),
Chris@0 68 $this->getMock('Composer\Config')
Chris@0 69 );
Chris@0 70 $composer->setRepositoryManager($rm);
Chris@0 71 $installer = new CakePHPInstaller($package, $composer);
Chris@0 72
Chris@0 73 // 2.0 < cakephp < 3.0
Chris@0 74 $this->setCakephpVersion($rm, '2.0.0');
Chris@0 75 $result = $installer->getLocations();
Chris@0 76 $this->assertContains('Plugin/', $result['plugin']);
Chris@0 77
Chris@0 78 $this->setCakephpVersion($rm, '2.5.9');
Chris@0 79 $result = $installer->getLocations();
Chris@0 80 $this->assertContains('Plugin/', $result['plugin']);
Chris@0 81
Chris@0 82 $this->setCakephpVersion($rm, '~2.5');
Chris@0 83 $result = $installer->getLocations();
Chris@0 84 $this->assertContains('Plugin/', $result['plugin']);
Chris@0 85
Chris@0 86 // special handling for 2.x versions when 3.x is still in development
Chris@0 87 $this->setCakephpVersion($rm, 'dev-master');
Chris@0 88 $result = $installer->getLocations();
Chris@0 89 $this->assertContains('Plugin/', $result['plugin']);
Chris@0 90
Chris@0 91 $this->setCakephpVersion($rm, '>=2.5');
Chris@0 92 $result = $installer->getLocations();
Chris@0 93 $this->assertContains('Plugin/', $result['plugin']);
Chris@0 94
Chris@0 95 // cakephp >= 3.0
Chris@0 96 $this->setCakephpVersion($rm, '3.0.*-dev');
Chris@0 97 $result = $installer->getLocations();
Chris@0 98 $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']);
Chris@0 99
Chris@0 100 $this->setCakephpVersion($rm, '~8.8');
Chris@0 101 $result = $installer->getLocations();
Chris@0 102 $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']);
Chris@0 103 }
Chris@0 104
Chris@0 105 protected function setCakephpVersion($rm, $version) {
Chris@0 106 $parser = new VersionParser();
Chris@0 107 list(, $version) = explode(' ', $parser->parseConstraints($version));
Chris@0 108 $installed = new InstalledArrayRepository();
Chris@0 109 $package = new Package('cakephp/cakephp', $version, $version);
Chris@0 110 $installed->addPackage($package);
Chris@0 111 $rm->setLocalRepository($installed);
Chris@0 112 }
Chris@0 113
Chris@0 114 }