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