Chris@0: package = new Package('CamelCased', '1.0', '1.0'); Chris@0: $this->io = $this->getMock('Composer\IO\PackageInterface'); Chris@0: $this->composer = new Composer(); Chris@0: $this->composer->setConfig(new Config(false)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * testInflectPackageVars Chris@0: * Chris@0: * @return void Chris@0: */ Chris@0: public function testInflectPackageVars() Chris@0: { Chris@0: $installer = new CakePHPInstaller($this->package, $this->composer); Chris@0: $result = $installer->inflectPackageVars(array('name' => 'CamelCased')); Chris@0: $this->assertEquals($result, array('name' => 'CamelCased')); Chris@0: Chris@0: $installer = new CakePHPInstaller($this->package, $this->composer); Chris@0: $result = $installer->inflectPackageVars(array('name' => 'with-dash')); Chris@0: $this->assertEquals($result, array('name' => 'WithDash')); Chris@0: Chris@0: $installer = new CakePHPInstaller($this->package, $this->composer); Chris@0: $result = $installer->inflectPackageVars(array('name' => 'with_underscore')); Chris@0: $this->assertEquals($result, array('name' => 'WithUnderscore')); Chris@0: Chris@0: $installer = new CakePHPInstaller($this->package, $this->composer); Chris@0: $result = $installer->inflectPackageVars(array('name' => 'cake/acl')); Chris@0: $this->assertEquals($result, array('name' => 'Cake/Acl')); Chris@0: Chris@0: $installer = new CakePHPInstaller($this->package, $this->composer); Chris@0: $result = $installer->inflectPackageVars(array('name' => 'cake/debug-kit')); Chris@0: $this->assertEquals($result, array('name' => 'Cake/DebugKit')); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test getLocations returning appropriate values based on CakePHP version Chris@0: * Chris@0: */ Chris@0: public function testGetLocations() { Chris@0: $package = new RootPackage('CamelCased', '1.0', '1.0'); Chris@0: $composer = $this->composer; Chris@0: $rm = new RepositoryManager( Chris@0: $this->getMock('Composer\IO\IOInterface'), Chris@0: $this->getMock('Composer\Config') Chris@0: ); Chris@0: $composer->setRepositoryManager($rm); Chris@0: $installer = new CakePHPInstaller($package, $composer); Chris@0: Chris@0: // 2.0 < cakephp < 3.0 Chris@0: $this->setCakephpVersion($rm, '2.0.0'); Chris@0: $result = $installer->getLocations(); Chris@0: $this->assertContains('Plugin/', $result['plugin']); Chris@0: Chris@0: $this->setCakephpVersion($rm, '2.5.9'); Chris@0: $result = $installer->getLocations(); Chris@0: $this->assertContains('Plugin/', $result['plugin']); Chris@0: Chris@0: $this->setCakephpVersion($rm, '~2.5'); Chris@0: $result = $installer->getLocations(); Chris@0: $this->assertContains('Plugin/', $result['plugin']); Chris@0: Chris@0: // special handling for 2.x versions when 3.x is still in development Chris@0: $this->setCakephpVersion($rm, 'dev-master'); Chris@0: $result = $installer->getLocations(); Chris@0: $this->assertContains('Plugin/', $result['plugin']); Chris@0: Chris@0: $this->setCakephpVersion($rm, '>=2.5'); Chris@0: $result = $installer->getLocations(); Chris@0: $this->assertContains('Plugin/', $result['plugin']); Chris@0: Chris@0: // cakephp >= 3.0 Chris@0: $this->setCakephpVersion($rm, '3.0.*-dev'); Chris@0: $result = $installer->getLocations(); Chris@0: $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']); Chris@0: Chris@0: $this->setCakephpVersion($rm, '~8.8'); Chris@0: $result = $installer->getLocations(); Chris@0: $this->assertContains('vendor/{$vendor}/{$name}/', $result['plugin']); Chris@0: } Chris@0: Chris@0: protected function setCakephpVersion($rm, $version) { Chris@0: $parser = new VersionParser(); Chris@0: list(, $version) = explode(' ', $parser->parseConstraints($version)); Chris@0: $installed = new InstalledArrayRepository(); Chris@0: $package = new Package('cakephp/cakephp', $version, $version); Chris@0: $installed->addPackage($package); Chris@0: $rm->setLocalRepository($installed); Chris@0: } Chris@0: Chris@0: }