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 { |
|
|
|
|
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); |
|
|
|
|
46
|
|
|
$component = new Component( |
47
|
|
|
'type_name', [$componentVersion], $badPackageRepository); |
48
|
|
|
$component->getVersion('2015021800'); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.