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

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