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