Blame view

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