No Description

ManifestTest.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /*
  3. * This file is part of PharIo\Manifest.
  4. *
  5. * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace PharIo\Manifest;
  11. use PharIo\Version\Version;
  12. use PharIo\Version\AnyVersionConstraint;
  13. use PHPUnit\Framework\TestCase;
  14. /**
  15. * @covers \PharIo\Manifest\Manifest
  16. *
  17. * @uses \PharIo\Manifest\ApplicationName
  18. * @uses \PharIo\Manifest\Author
  19. * @uses \PharIo\Manifest\AuthorCollection
  20. * @uses \PharIo\Manifest\BundledComponent
  21. * @uses \PharIo\Manifest\BundledComponentCollection
  22. * @uses \PharIo\Manifest\CopyrightInformation
  23. * @uses \PharIo\Manifest\Email
  24. * @uses \PharIo\Manifest\License
  25. * @uses \PharIo\Manifest\RequirementCollection
  26. * @uses \PharIo\Manifest\PhpVersionRequirement
  27. * @uses \PharIo\Manifest\Type
  28. * @uses \PharIo\Manifest\Application
  29. * @uses \PharIo\Manifest\Url
  30. * @uses \PharIo\Version\Version
  31. * @uses \PharIo\Version\VersionConstraint
  32. */
  33. class ManifestTest extends TestCase {
  34. /**
  35. * @var ApplicationName
  36. */
  37. private $name;
  38. /**
  39. * @var Version
  40. */
  41. private $version;
  42. /**
  43. * @var Type
  44. */
  45. private $type;
  46. /**
  47. * @var CopyrightInformation
  48. */
  49. private $copyrightInformation;
  50. /**
  51. * @var RequirementCollection
  52. */
  53. private $requirements;
  54. /**
  55. * @var BundledComponentCollection
  56. */
  57. private $bundledComponents;
  58. /**
  59. * @var Manifest
  60. */
  61. private $manifest;
  62. protected function setUp() {
  63. $this->version = new Version('5.6.5');
  64. $this->type = Type::application();
  65. $author = new Author('Joe Developer', new Email('user@example.com'));
  66. $license = new License('BSD-3-Clause', new Url('https://github.com/sebastianbergmann/phpunit/blob/master/LICENSE'));
  67. $authors = new AuthorCollection;
  68. $authors->add($author);
  69. $this->copyrightInformation = new CopyrightInformation($authors, $license);
  70. $this->requirements = new RequirementCollection;
  71. $this->requirements->add(new PhpVersionRequirement(new AnyVersionConstraint));
  72. $this->bundledComponents = new BundledComponentCollection;
  73. $this->bundledComponents->add(new BundledComponent('phpunit/php-code-coverage', new Version('4.0.2')));
  74. $this->name = new ApplicationName('phpunit/phpunit');
  75. $this->manifest = new Manifest(
  76. $this->name,
  77. $this->version,
  78. $this->type,
  79. $this->copyrightInformation,
  80. $this->requirements,
  81. $this->bundledComponents
  82. );
  83. }
  84. public function testCanBeCreated() {
  85. $this->assertInstanceOf(Manifest::class, $this->manifest);
  86. }
  87. public function testNameCanBeRetrieved() {
  88. $this->assertEquals($this->name, $this->manifest->getName());
  89. }
  90. public function testVersionCanBeRetrieved() {
  91. $this->assertEquals($this->version, $this->manifest->getVersion());
  92. }
  93. public function testTypeCanBeRetrieved() {
  94. $this->assertEquals($this->type, $this->manifest->getType());
  95. }
  96. public function testTypeCanBeQueried() {
  97. $this->assertTrue($this->manifest->isApplication());
  98. $this->assertFalse($this->manifest->isLibrary());
  99. $this->assertFalse($this->manifest->isExtension());
  100. }
  101. public function testCopyrightInformationCanBeRetrieved() {
  102. $this->assertEquals($this->copyrightInformation, $this->manifest->getCopyrightInformation());
  103. }
  104. public function testRequirementsCanBeRetrieved() {
  105. $this->assertEquals($this->requirements, $this->manifest->getRequirements());
  106. }
  107. public function testBundledComponentsCanBeRetrieved() {
  108. $this->assertEquals($this->bundledComponents, $this->manifest->getBundledComponents());
  109. }
  110. /**
  111. * @uses \PharIo\Manifest\Extension
  112. */
  113. public function testExtendedApplicationCanBeQueriedForExtension()
  114. {
  115. $appName = new ApplicationName('foo/bar');
  116. $manifest = new Manifest(
  117. new ApplicationName('foo/foo'),
  118. new Version('1.0.0'),
  119. Type::extension($appName, new AnyVersionConstraint),
  120. $this->copyrightInformation,
  121. new RequirementCollection,
  122. new BundledComponentCollection
  123. );
  124. $this->assertTrue($manifest->isExtensionFor($appName));
  125. }
  126. public function testNonExtensionReturnsFalseWhenQueriesForExtension() {
  127. $appName = new ApplicationName('foo/bar');
  128. $manifest = new Manifest(
  129. new ApplicationName('foo/foo'),
  130. new Version('1.0.0'),
  131. Type::library(),
  132. $this->copyrightInformation,
  133. new RequirementCollection,
  134. new BundledComponentCollection
  135. );
  136. $this->assertFalse($manifest->isExtensionFor($appName));
  137. }
  138. /**
  139. * @uses \PharIo\Manifest\Extension
  140. */
  141. public function testExtendedApplicationCanBeQueriedForExtensionWithVersion()
  142. {
  143. $appName = new ApplicationName('foo/bar');
  144. $manifest = new Manifest(
  145. new ApplicationName('foo/foo'),
  146. new Version('1.0.0'),
  147. Type::extension($appName, new AnyVersionConstraint),
  148. $this->copyrightInformation,
  149. new RequirementCollection,
  150. new BundledComponentCollection
  151. );
  152. $this->assertTrue($manifest->isExtensionFor($appName, new Version('1.2.3')));
  153. }
  154. }