Passed
Push — master ( 95d224...68f44f )
by Luke
02:40
created

ComponentTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetNameParts() 0 6 1
A testGetVersion() 0 22 1
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
use ComponentManager\Component;
12
use ComponentManager\ComponentVersion;
13
use ComponentManager\Exception\UnsatisfiedVersionException;
14
use ComponentManager\PackageRepository\PackageRepository;
15
use PHPUnit\Framework\TestCase;
16
17
/**
18
 * @coversDefaultClass \ComponentManager\Component
19
 */
20
class ComponentTest extends TestCase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
21
   public function testGetNameParts() {
22
       $component = new Component('type_name', []);
23
       $this->assertEquals(['type', 'name'], $component->getNameParts());
24
       $this->assertEquals('type', $component->getPluginType());
25
       $this->assertEquals('name', $component->getPluginName());
26
   }
27
28
   public function testGetVersion() {
29
       $goodPackageRepository = $this->createMock(PackageRepository::class);
30
       $goodPackageRepository->method('satisfiesVersion')
31
           ->willReturn(true);
32
       $badPackageRepository = $this->createMock(PackageRepository::class);
33
       $badPackageRepository->method('satisfiesVersion')
34
           ->willReturn(false);
35
36
       $componentVersion = new ComponentVersion(
37
            '2015021800', 'Genesis', ComponentVersion::MATURITY_STABLE, []);
38
39
       $component = new Component(
40
            'type_name', [$componentVersion], $goodPackageRepository);
41
       $this->assertEquals(
42
            $componentVersion, $component->getVersion('2015021800'));
43
44
       $this->expectException(UnsatisfiedVersionException::class);
45
       $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...
46
       $component = new Component(
47
            'type_name', [$componentVersion], $badPackageRepository);
48
       $component->getVersion('2015021800');
49
   }
50
}
51