GravInstallerTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Composer\Installers\Test;
  3. use Composer\Composer;
  4. use Composer\Installers\GravInstaller;
  5. class GravInstallerTest extends TestCase
  6. {
  7. /* @var \Composer\Composer */
  8. protected $composer;
  9. public function setUp()
  10. {
  11. $this->composer = new Composer();
  12. }
  13. public function testInflectPackageVars()
  14. {
  15. $package = $this->getPackage('vendor/name', '0.0.0');
  16. $installer = new GravInstaller($package, $this->composer);
  17. $packageVars = $this->getPackageVars($package);
  18. $result = $installer->inflectPackageVars(array_merge($packageVars, array('name' => 'test')));
  19. $this->assertEquals('test', $result['name']);
  20. foreach ($installer->getLocations() as $name => $location) {
  21. $result = $installer->inflectPackageVars(array_merge($packageVars, array('name' => "$name-test")));
  22. $this->assertEquals('test', $result['name']);
  23. $result = $installer->inflectPackageVars(array_merge($packageVars, array('name' => "test-$name")));
  24. $this->assertEquals('test', $result['name']);
  25. $result = $installer->inflectPackageVars(array_merge($packageVars, array('name' => "$name-test-test")));
  26. $this->assertEquals('test-test', $result['name']);
  27. $result = $installer->inflectPackageVars(array_merge($packageVars, array('name' => "test-test-$name")));
  28. $this->assertEquals('test-test', $result['name']);
  29. $result = $installer->inflectPackageVars(array_merge($packageVars, array('name' => "grav-$name-test")));
  30. $this->assertEquals('test', $result['name']);
  31. $result = $installer->inflectPackageVars(array_merge($packageVars, array('name' => "grav-test-$name")));
  32. $this->assertEquals('test', $result['name']);
  33. $result = $installer->inflectPackageVars(array_merge($packageVars, array('name' => "grav-$name-test-test")));
  34. $this->assertEquals('test-test', $result['name']);
  35. $result = $installer->inflectPackageVars(array_merge($packageVars, array('name' => "grav-test-test-$name")));
  36. $this->assertEquals('test-test', $result['name']);
  37. }
  38. }
  39. /**
  40. * @param $package \Composer\Package\PackageInterface
  41. */
  42. public function getPackageVars($package)
  43. {
  44. $type = $package->getType();
  45. $prettyName = $package->getPrettyName();
  46. if (strpos($prettyName, '/') !== false) {
  47. list($vendor, $name) = explode('/', $prettyName);
  48. } else {
  49. $vendor = '';
  50. $name = $prettyName;
  51. }
  52. return compact('name', 'vendor', 'type');
  53. }
  54. }