2 namespace Composer\Installers\Test;
4 use Composer\Installers\CakePHPInstaller;
5 use Composer\Repository\RepositoryManager;
6 use Composer\Repository\InstalledArrayRepository;
7 use Composer\Package\Package;
8 use Composer\Package\RootPackage;
9 use Composer\Package\Link;
10 use Composer\Package\Version\VersionParser;
11 use Composer\Composer;
14 class CakePHPInstallerTest extends TestCase
24 public function setUp()
26 $this->package = new Package('CamelCased', '1.0', '1.0');
27 $this->io = $this->getMock('Composer\IO\PackageInterface');
28 $this->composer = new Composer();
29 $this->composer->setConfig(new Config(false));
33 * testInflectPackageVars
37 public function testInflectPackageVars()
39 $installer = new CakePHPInstaller($this->package, $this->composer);
40 $result = $installer->inflectPackageVars(array('name' => 'CamelCased'));
41 $this->assertEquals($result, array('name' => 'CamelCased'));
43 $installer = new CakePHPInstaller($this->package, $this->composer);
44 $result = $installer->inflectPackageVars(array('name' => 'with-dash'));
45 $this->assertEquals($result, array('name' => 'WithDash'));
47 $installer = new CakePHPInstaller($this->package, $this->composer);
48 $result = $installer->inflectPackageVars(array('name' => 'with_underscore'));
49 $this->assertEquals($result, array('name' => 'WithUnderscore'));
51 $installer = new CakePHPInstaller($this->package, $this->composer);
52 $result = $installer->inflectPackageVars(array('name' => 'cake/acl'));
53 $this->assertEquals($result, array('name' => 'Cake/Acl'));
55 $installer = new CakePHPInstaller($this->package, $this->composer);
56 $result = $installer->inflectPackageVars(array('name' => 'cake/debug-kit'));
57 $this->assertEquals($result, array('name' => 'Cake/DebugKit'));
61 * Test getLocations returning appropriate values based on CakePHP version
64 public function testGetLocations() {
65 $package = new RootPackage('CamelCased', '1.0', '1.0');
66 $composer = $this->composer;
67 $rm = new RepositoryManager(
68 $this->getMock('Composer\IO\IOInterface'),
69 $this->getMock('Composer\Config')
71 $composer->setRepositoryManager($rm);
72 $installer = new CakePHPInstaller($package, $composer);
74 // 2.0 < cakephp < 3.0
75 $this->setCakephpVersion($rm, '2.0.0');
76 $result = $installer->getLocations();
77 $this->assertContains('Plugin/', $result['plugin']);
79 $this->setCakephpVersion($rm, '2.5.9');
80 $result = $installer->getLocations();
81 $this->assertContains('Plugin/', $result['plugin']);
83 $this->setCakephpVersion($rm, '~2.5');
84 $result = $installer->getLocations();
85 $this->assertContains('Plugin/', $result['plugin']);
87 // special handling for 2.x versions when 3.x is still in development
88 $this->setCakephpVersion($rm, 'dev-master');
89 $result = $installer->getLocations();
90 $this->assertContains('Plugin/', $result['plugin']);
92 $this->setCakephpVersion($rm, '>=2.5');
93 $result = $installer->getLocations();
94 $this->assertContains('Plugin/', $result['plugin']);
97 $this->setCakephpVersion($rm, '3.0.*-dev');
98 $result = $installer->getLocations();
99 $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']);
101 $this->setCakephpVersion($rm, '~8.8');
102 $result = $installer->getLocations();
103 $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']);
106 protected function setCakephpVersion($rm, $version) {
107 $parser = new VersionParser();
108 list(, $version) = explode(' ', $parser->parseConstraints($version));
109 $installed = new InstalledArrayRepository();
110 $package = new Package('cakephp/cakephp', $version, $version);
111 $installed->addPackage($package);
112 $rm->setLocalRepository($installed);