Passed
Push — unit ( fc9abb...3cd14f )
by Luke
02:42
created

ComponentTest::testGetNameParts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * Moodle component manager.
5
 *
6
 * @author Luke Carrier <[email protected]>
7
 * @copyright 2016 Luke Carrier
8
 * @license GPL-3.0+
9
 */
10
11
namespace ComponentManager\Test;
12
13
use ComponentManager\Component;
14
use ComponentManager\ComponentVersion;
15
use ComponentManager\Exception\UnsatisfiedVersionException;
16
use ComponentManager\PackageRepository\PackageRepository;
17
use PHPUnit\Framework\TestCase;
18
19
/**
20
 * @coversDefaultClass \ComponentManager\Component
21
 */
22
class ComponentTest extends TestCase {
23
   public function testGetNameParts() {
24
       $component = new Component('type_name', []);
25
       $this->assertEquals(['type', 'name'], $component->getNameParts());
26
       $this->assertEquals('type', $component->getPluginType());
27
       $this->assertEquals('name', $component->getPluginName());
28
   }
29
30
   public function testGetVersion() {
31
       $goodPackageRepository = $this->createMock(PackageRepository::class);
32
       $goodPackageRepository->method('satisfiesVersion')
33
           ->willReturn(true);
34
       $badPackageRepository = $this->createMock(PackageRepository::class);
35
       $badPackageRepository->method('satisfiesVersion')
36
           ->willReturn(false);
37
38
       $componentVersion = new ComponentVersion(
39
            '2015021800', 'Genesis', ComponentVersion::MATURITY_STABLE, []);
40
41
       $component = new Component(
42
            'type_name', [$componentVersion], $goodPackageRepository);
43
       $this->assertEquals(
44
            $componentVersion, $component->getVersion('2015021800'));
45
46
       $this->expectException(UnsatisfiedVersionException::class);
47
       $this->expectExceptionCode(UnsatisfiedVersionException::CODE_UNKNOWN_VERSION);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 85 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
48
       $component = new Component(
49
            'type_name', [$componentVersion], $badPackageRepository);
50
       $component->getVersion('2015021800');
51
   }
52
}
53