CompletePackageTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Package;
  12. use Composer\Package\Package;
  13. use Composer\Semver\VersionParser;
  14. use Composer\Test\TestCase;
  15. class CompletePackageTest extends TestCase
  16. {
  17. /**
  18. * Memory package naming, versioning, and marshalling semantics provider
  19. *
  20. * demonstrates several versioning schemes
  21. */
  22. public function providerVersioningSchemes()
  23. {
  24. $provider[] = array('foo', '1-beta');
  25. $provider[] = array('node', '0.5.6');
  26. $provider[] = array('li3', '0.10');
  27. $provider[] = array('mongodb_odm', '1.0.0BETA3');
  28. $provider[] = array('DoctrineCommon', '2.2.0-DEV');
  29. return $provider;
  30. }
  31. /**
  32. * Tests memory package naming semantics
  33. * @dataProvider providerVersioningSchemes
  34. */
  35. public function testPackageHasExpectedNamingSemantics($name, $version)
  36. {
  37. $versionParser = new VersionParser();
  38. $normVersion = $versionParser->normalize($version);
  39. $package = new Package($name, $normVersion, $version);
  40. $this->assertEquals(strtolower($name), $package->getName());
  41. }
  42. /**
  43. * Tests memory package versioning semantics
  44. * @dataProvider providerVersioningSchemes
  45. */
  46. public function testPackageHasExpectedVersioningSemantics($name, $version)
  47. {
  48. $versionParser = new VersionParser();
  49. $normVersion = $versionParser->normalize($version);
  50. $package = new Package($name, $normVersion, $version);
  51. $this->assertEquals($version, $package->getPrettyVersion());
  52. $this->assertEquals($normVersion, $package->getVersion());
  53. }
  54. /**
  55. * Tests memory package marshalling/serialization semantics
  56. * @dataProvider providerVersioningSchemes
  57. */
  58. public function testPackageHasExpectedMarshallingSemantics($name, $version)
  59. {
  60. $versionParser = new VersionParser();
  61. $normVersion = $versionParser->normalize($version);
  62. $package = new Package($name, $normVersion, $version);
  63. $this->assertEquals(strtolower($name).'-'.$normVersion, (string) $package);
  64. }
  65. public function testGetTargetDir()
  66. {
  67. $package = new Package('a', '1.0.0.0', '1.0');
  68. $this->assertNull($package->getTargetDir());
  69. $package->setTargetDir('./../foo/');
  70. $this->assertEquals('foo/', $package->getTargetDir());
  71. $package->setTargetDir('foo/../../../bar/');
  72. $this->assertEquals('foo/bar/', $package->getTargetDir());
  73. $package->setTargetDir('../..');
  74. $this->assertEquals('', $package->getTargetDir());
  75. $package->setTargetDir('..');
  76. $this->assertEquals('', $package->getTargetDir());
  77. $package->setTargetDir('/..');
  78. $this->assertEquals('', $package->getTargetDir());
  79. $package->setTargetDir('/foo/..');
  80. $this->assertEquals('foo/', $package->getTargetDir());
  81. $package->setTargetDir('/foo/..//bar');
  82. $this->assertEquals('foo/bar', $package->getTargetDir());
  83. }
  84. }