1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BringYourOwnIdeas\Maintenance\Tests\Tasks; |
4
|
|
|
|
5
|
|
|
use BringYourOwnIdeas\Maintenance\Util\ComposerLoader; |
6
|
|
|
use BringYourOwnIdeas\Maintenance\Util\SupportedAddonsLoader; |
7
|
|
|
use Package; |
8
|
|
|
use PHPUnit_Framework_TestCase; |
9
|
|
|
use RuntimeException; |
10
|
|
|
use SapphireTest; |
11
|
|
|
use UpdatePackageInfoTask; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @mixin PHPUnit_Framework_TestCase |
15
|
|
|
*/ |
16
|
|
|
class UpdatePackageInfoTest extends SapphireTest |
17
|
|
|
{ |
18
|
|
|
protected $usesDatabase = true; |
19
|
|
|
|
20
|
|
|
public function testGetPackageInfo() |
21
|
|
|
{ |
22
|
|
|
$lockOutput = [(object) [ |
23
|
|
|
"name" => "fake/package", |
24
|
|
|
"description" => "A faux package from a mocked composer.lock for testing purposes", |
25
|
|
|
"version" => "1.0.0", |
26
|
|
|
]]; |
27
|
|
|
|
28
|
|
|
$processor = new UpdatePackageInfoTask; |
29
|
|
|
$output = $processor->getPackageInfo($lockOutput); |
30
|
|
|
$this->assertInternalType('array', $output); |
|
|
|
|
31
|
|
|
$this->assertCount(1, $output); |
|
|
|
|
32
|
|
|
$this->assertContains([ |
33
|
|
|
"Name" => "fake/package", |
34
|
|
|
"Description" => "A faux package from a mocked composer.lock for testing purposes", |
35
|
|
|
"Version" => "1.0.0" |
36
|
|
|
], $output); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetSupportedPackagesEchosErrors() |
40
|
|
|
{ |
41
|
|
|
$supportedAddonsLoader = $this->getMockBuilder(SupportedAddonsLoader::class) |
|
|
|
|
42
|
|
|
->setMethods(['getAddonNames']) |
43
|
|
|
->getMock(); |
44
|
|
|
|
45
|
|
|
$supportedAddonsLoader->expects($this->once()) |
|
|
|
|
46
|
|
|
->method('getAddonNames') |
47
|
|
|
->will($this->throwException(new RuntimeException('A test message'))); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$task = new UpdatePackageInfoTask; |
50
|
|
|
$task->setSupportedAddonsLoader($supportedAddonsLoader); |
51
|
|
|
|
52
|
|
|
ob_start(); |
53
|
|
|
$task->getSupportedPackages(); |
54
|
|
|
$output = ob_get_clean(); |
55
|
|
|
|
56
|
|
|
$this->assertContains('A test message', $output); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testPackagesAreAddedCorrectly() |
60
|
|
|
{ |
61
|
|
|
$task = new UpdatePackageInfoTask; |
62
|
|
|
|
63
|
|
|
$composerLoader = $this->getMockBuilder(ComposerLoader::class) |
|
|
|
|
64
|
|
|
->setMethods(['getLock'])->getMock(); |
65
|
|
|
$composerLoader->expects($this->any())->method('getLock')->will($this->returnValue(json_decode(<<<LOCK |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
"packages": [ |
68
|
|
|
{ |
69
|
|
|
"name": "fake/supported-package", |
70
|
|
|
"description": "A faux package from a mocked composer.lock for testing purposes", |
71
|
|
|
"version": "1.0.0" |
72
|
|
|
}, |
73
|
|
|
{ |
74
|
|
|
"name": "fake/unsupported-package", |
75
|
|
|
"description": "A faux package from a mocked composer.lock for testing purposes", |
76
|
|
|
"version": "1.0.0" |
77
|
|
|
} |
78
|
|
|
], |
79
|
|
|
"packages-dev": null |
80
|
|
|
} |
81
|
|
|
LOCK |
82
|
|
|
))); |
83
|
|
|
$task->setComposerLoader($composerLoader); |
84
|
|
|
|
85
|
|
|
$supportedAddonsLoader = $this->getMockBuilder(SupportedAddonsLoader::class) |
|
|
|
|
86
|
|
|
->setMethods(['getAddonNames']) |
87
|
|
|
->getMock(); |
88
|
|
|
$supportedAddonsLoader->expects($this->once()) |
|
|
|
|
89
|
|
|
->method('getAddonNames') |
90
|
|
|
->will($this->returnValue(['fake/supported-package'])); |
|
|
|
|
91
|
|
|
$task->setSupportedAddonsLoader($supportedAddonsLoader); |
92
|
|
|
|
93
|
|
|
$task->run(null); |
94
|
|
|
|
95
|
|
|
$packages = Package::get(); |
96
|
|
|
$this->assertCount(2, $packages); |
|
|
|
|
97
|
|
|
|
98
|
|
|
$package = $packages->find('Name', 'fake/supported-package'); |
99
|
|
|
$this->assertInstanceOf(Package::class, $package); |
|
|
|
|
100
|
|
|
$this->assertEquals(1, $package->Supported); |
|
|
|
|
101
|
|
|
|
102
|
|
|
$package = $packages->find('Name', 'fake/unsupported-package'); |
103
|
|
|
$this->assertInstanceOf(Package::class, $package); |
|
|
|
|
104
|
|
|
$this->assertEquals(0, $package->Supported); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.