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\Version\VersionParser;
10 use Composer\Composer;
13 class CakePHPInstallerTest extends TestCase
23 public function setUp()
25 $this->package = new Package('CamelCased', '1.0', '1.0');
26 $this->io = $this->getMock('Composer\IO\PackageInterface');
27 $this->composer = new Composer();
28 $this->composer->setConfig(new Config(false));
32 * testInflectPackageVars
36 public function testInflectPackageVars()
38 $installer = new CakePHPInstaller($this->package, $this->composer);
39 $result = $installer->inflectPackageVars(array('name' => 'CamelCased'));
40 $this->assertEquals($result, array('name' => 'CamelCased'));
42 $installer = new CakePHPInstaller($this->package, $this->composer);
43 $result = $installer->inflectPackageVars(array('name' => 'with-dash'));
44 $this->assertEquals($result, array('name' => 'WithDash'));
46 $installer = new CakePHPInstaller($this->package, $this->composer);
47 $result = $installer->inflectPackageVars(array('name' => 'with_underscore'));
48 $this->assertEquals($result, array('name' => 'WithUnderscore'));
50 $installer = new CakePHPInstaller($this->package, $this->composer);
51 $result = $installer->inflectPackageVars(array('name' => 'cake/acl'));
52 $this->assertEquals($result, array('name' => 'Cake/Acl'));
54 $installer = new CakePHPInstaller($this->package, $this->composer);
55 $result = $installer->inflectPackageVars(array('name' => 'cake/debug-kit'));
56 $this->assertEquals($result, array('name' => 'Cake/DebugKit'));
60 * Test getLocations returning appropriate values based on CakePHP version
63 public function testGetLocations() {
64 $package = new RootPackage('CamelCased', '1.0', '1.0');
65 $composer = $this->composer;
66 $rm = new RepositoryManager(
67 $this->getMock('Composer\IO\IOInterface'),
68 $this->getMock('Composer\Config')
70 $composer->setRepositoryManager($rm);
71 $installer = new CakePHPInstaller($package, $composer);
73 // 2.0 < cakephp < 3.0
74 $this->setCakephpVersion($rm, '2.0.0');
75 $result = $installer->getLocations();
76 $this->assertContains('Plugin/', $result['plugin']);
78 $this->setCakephpVersion($rm, '2.5.9');
79 $result = $installer->getLocations();
80 $this->assertContains('Plugin/', $result['plugin']);
82 $this->setCakephpVersion($rm, '~2.5');
83 $result = $installer->getLocations();
84 $this->assertContains('Plugin/', $result['plugin']);
86 // special handling for 2.x versions when 3.x is still in development
87 $this->setCakephpVersion($rm, 'dev-master');
88 $result = $installer->getLocations();
89 $this->assertContains('Plugin/', $result['plugin']);
91 $this->setCakephpVersion($rm, '>=2.5');
92 $result = $installer->getLocations();
93 $this->assertContains('Plugin/', $result['plugin']);
96 $this->setCakephpVersion($rm, '3.0.*-dev');
97 $result = $installer->getLocations();
98 $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']);
100 $this->setCakephpVersion($rm, '~8.8');
101 $result = $installer->getLocations();
102 $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']);
105 protected function setCakephpVersion($rm, $version) {
106 $parser = new VersionParser();
107 list(, $version) = explode(' ', $parser->parseConstraints($version));
108 $installed = new InstalledArrayRepository();
109 $package = new Package('cakephp/cakephp', $version, $version);
110 $installed->addPackage($package);
111 $rm->setLocalRepository($installed);