CakePHPInstallerTest.php 4.1 KB

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