Yaffs site version 1.1
[yaffs-website] / vendor / composer / installers / tests / Composer / Installers / Test / CakePHPInstallerTest.php
1 <?php
2 namespace Composer\Installers\Test;
3
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;
12 use Composer\Config;
13
14 class CakePHPInstallerTest extends TestCase
15 {
16     private $composer;
17     private $io;
18
19     /**
20      * setUp
21      *
22      * @return void
23      */
24     public function setUp()
25     {
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));
30     }
31
32     /**
33      * testInflectPackageVars
34      *
35      * @return void
36      */
37     public function testInflectPackageVars()
38     {
39         $installer = new CakePHPInstaller($this->package, $this->composer);
40         $result = $installer->inflectPackageVars(array('name' => 'CamelCased'));
41         $this->assertEquals($result, array('name' => 'CamelCased'));
42
43         $installer = new CakePHPInstaller($this->package, $this->composer);
44         $result = $installer->inflectPackageVars(array('name' => 'with-dash'));
45         $this->assertEquals($result, array('name' => 'WithDash'));
46
47         $installer = new CakePHPInstaller($this->package, $this->composer);
48         $result = $installer->inflectPackageVars(array('name' => 'with_underscore'));
49         $this->assertEquals($result, array('name' => 'WithUnderscore'));
50
51         $installer = new CakePHPInstaller($this->package, $this->composer);
52         $result = $installer->inflectPackageVars(array('name' => 'cake/acl'));
53         $this->assertEquals($result, array('name' => 'Cake/Acl'));
54
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'));
58     }
59
60     /**
61      * Test getLocations returning appropriate values based on CakePHP version
62      *
63      */
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')
70         );
71         $composer->setRepositoryManager($rm);
72         $installer = new CakePHPInstaller($package, $composer);
73
74         // 2.0 < cakephp < 3.0
75         $this->setCakephpVersion($rm, '2.0.0');
76         $result = $installer->getLocations();
77         $this->assertContains('Plugin/', $result['plugin']);
78
79         $this->setCakephpVersion($rm, '2.5.9');
80         $result = $installer->getLocations();
81         $this->assertContains('Plugin/', $result['plugin']);
82
83         $this->setCakephpVersion($rm, '~2.5');
84         $result = $installer->getLocations();
85         $this->assertContains('Plugin/', $result['plugin']);
86
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']);
91
92         $this->setCakephpVersion($rm, '>=2.5');
93         $result = $installer->getLocations();
94         $this->assertContains('Plugin/', $result['plugin']);
95
96         // cakephp >= 3.0
97         $this->setCakephpVersion($rm, '3.0.*-dev');
98         $result = $installer->getLocations();
99         $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']);
100
101         $this->setCakephpVersion($rm, '~8.8');
102         $result = $installer->getLocations();
103         $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']);
104     }
105
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);
113     }
114
115 }