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\AnyVersionConstraint;
|
Chris@14
|
14 use PharIo\Version\Version;
|
Chris@14
|
15 use PharIo\Version\VersionConstraint;
|
Chris@14
|
16 use PharIo\Version\VersionConstraintParser;
|
Chris@14
|
17 use PHPUnit\Framework\TestCase;
|
Chris@14
|
18
|
Chris@14
|
19 /**
|
Chris@14
|
20 * @covers \PharIo\Manifest\Extension
|
Chris@14
|
21 * @covers \PharIo\Manifest\Type
|
Chris@14
|
22 *
|
Chris@14
|
23 * @uses \PharIo\Version\VersionConstraint
|
Chris@14
|
24 * @uses \PharIo\Manifest\ApplicationName
|
Chris@14
|
25 */
|
Chris@14
|
26 class ExtensionTest extends TestCase {
|
Chris@14
|
27 /**
|
Chris@14
|
28 * @var Extension
|
Chris@14
|
29 */
|
Chris@14
|
30 private $type;
|
Chris@14
|
31
|
Chris@14
|
32 /**
|
Chris@14
|
33 * @var ApplicationName|\PHPUnit_Framework_MockObject_MockObject
|
Chris@14
|
34 */
|
Chris@14
|
35 private $name;
|
Chris@14
|
36
|
Chris@14
|
37 protected function setUp() {
|
Chris@14
|
38 $this->name = $this->createMock(ApplicationName::class);
|
Chris@14
|
39 $this->type = Type::extension($this->name, new AnyVersionConstraint);
|
Chris@14
|
40 }
|
Chris@14
|
41
|
Chris@14
|
42 public function testCanBeCreated() {
|
Chris@14
|
43 $this->assertInstanceOf(Extension::class, $this->type);
|
Chris@14
|
44 }
|
Chris@14
|
45
|
Chris@14
|
46 public function testIsNotApplication() {
|
Chris@14
|
47 $this->assertFalse($this->type->isApplication());
|
Chris@14
|
48 }
|
Chris@14
|
49
|
Chris@14
|
50 public function testIsNotLibrary() {
|
Chris@14
|
51 $this->assertFalse($this->type->isLibrary());
|
Chris@14
|
52 }
|
Chris@14
|
53
|
Chris@14
|
54 public function testIsExtension() {
|
Chris@14
|
55 $this->assertTrue($this->type->isExtension());
|
Chris@14
|
56 }
|
Chris@14
|
57
|
Chris@14
|
58 public function testApplicationCanBeRetrieved()
|
Chris@14
|
59 {
|
Chris@14
|
60 $this->assertInstanceOf(ApplicationName::class, $this->type->getApplicationName());
|
Chris@14
|
61 }
|
Chris@14
|
62
|
Chris@14
|
63 public function testVersionConstraintCanBeRetrieved() {
|
Chris@14
|
64 $this->assertInstanceOf(
|
Chris@14
|
65 VersionConstraint::class,
|
Chris@14
|
66 $this->type->getVersionConstraint()
|
Chris@14
|
67 );
|
Chris@14
|
68 }
|
Chris@14
|
69
|
Chris@14
|
70 public function testApplicationCanBeQueried()
|
Chris@14
|
71 {
|
Chris@14
|
72 $this->name->method('isEqual')->willReturn(true);
|
Chris@14
|
73 $this->assertTrue(
|
Chris@14
|
74 $this->type->isExtensionFor($this->createMock(ApplicationName::class))
|
Chris@14
|
75 );
|
Chris@14
|
76 }
|
Chris@14
|
77
|
Chris@14
|
78 public function testCompatibleWithReturnsTrueForMatchingVersionConstraintAndApplicaiton() {
|
Chris@14
|
79 $app = new ApplicationName('foo/bar');
|
Chris@14
|
80 $extension = Type::extension($app, (new VersionConstraintParser)->parse('^1.0'));
|
Chris@14
|
81 $version = new Version('1.0.0');
|
Chris@14
|
82
|
Chris@14
|
83 $this->assertTrue(
|
Chris@14
|
84 $extension->isCompatibleWith($app, $version)
|
Chris@14
|
85 );
|
Chris@14
|
86 }
|
Chris@14
|
87
|
Chris@14
|
88 public function testCompatibleWithReturnsFalseForNotMatchingVersionConstraint() {
|
Chris@14
|
89 $app = new ApplicationName('foo/bar');
|
Chris@14
|
90 $extension = Type::extension($app, (new VersionConstraintParser)->parse('^1.0'));
|
Chris@14
|
91 $version = new Version('2.0.0');
|
Chris@14
|
92
|
Chris@14
|
93 $this->assertFalse(
|
Chris@14
|
94 $extension->isCompatibleWith($app, $version)
|
Chris@14
|
95 );
|
Chris@14
|
96 }
|
Chris@14
|
97
|
Chris@14
|
98 public function testCompatibleWithReturnsFalseForNotMatchingApplication() {
|
Chris@14
|
99 $app1 = new ApplicationName('foo/bar');
|
Chris@14
|
100 $app2 = new ApplicationName('foo/foo');
|
Chris@14
|
101 $extension = Type::extension($app1, (new VersionConstraintParser)->parse('^1.0'));
|
Chris@14
|
102 $version = new Version('1.0.0');
|
Chris@14
|
103
|
Chris@14
|
104 $this->assertFalse(
|
Chris@14
|
105 $extension->isCompatibleWith($app2, $version)
|
Chris@14
|
106 );
|
Chris@14
|
107 }
|
Chris@14
|
108
|
Chris@14
|
109 }
|