|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BringYourOwnIdeas\UpdateChecker\Tests\Tasks; |
|
4
|
|
|
|
|
5
|
|
|
use BringYourOwnIdeas\UpdateChecker\UpdateChecker; |
|
6
|
|
|
use CheckComposerUpdatesTask; |
|
7
|
|
|
use Composer\Package\PackageInterface; |
|
8
|
|
|
use Config; |
|
9
|
|
|
use PHPUnit_Framework_TestCase; |
|
10
|
|
|
use SapphireTest; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @mixin PHPUnit_Framework_TestCase |
|
14
|
|
|
*/ |
|
15
|
|
|
class CheckComposerUpdatesTaskTest extends SapphireTest |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var CheckComposerUpdatesTask |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $task; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string[] |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $allowedTypes; |
|
26
|
|
|
|
|
27
|
|
|
public function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
parent::setUp(); |
|
30
|
|
|
|
|
31
|
|
|
$this->task = CheckComposerUpdatesTask::create(); |
|
32
|
|
|
|
|
33
|
|
|
$updateCheckerMock = $this->getMockBuilder(UpdateChecker::class)->setMethods(['checkForUpdates'])->getMock(); |
|
|
|
|
|
|
34
|
|
|
$this->task->setUpdateChecker($updateCheckerMock); |
|
35
|
|
|
|
|
36
|
|
|
$this->allowedTypes = ['silverstripe-module', 'silverstripe-vendormodule', 'silverstripe-theme']; |
|
37
|
|
|
Config::inst()->update(CheckComposerUpdatesTask::class, 'allowed_types', $this->allowedTypes); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testRunPassesPackagesToUpdateChecker() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->task->getUpdateChecker()->expects($this->atLeastOnce()) |
|
|
|
|
|
|
43
|
|
|
->method('checkForUpdates') |
|
44
|
|
|
->with($this->isInstanceOf(PackageInterface::class), $this->isType('string')); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$output = $this->runTask(); |
|
47
|
|
|
$this->assertContains('The task finished running', $output); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testOnlyAllowedPackageTypesAreProcessed() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->task->getUpdateChecker()->expects($this->atLeastOnce()) |
|
|
|
|
|
|
53
|
|
|
->method('checkForUpdates') |
|
54
|
|
|
->with($this->callback(function ($argument) { |
|
|
|
|
|
|
55
|
|
|
return in_array($argument->getType(), $this->allowedTypes); |
|
56
|
|
|
})); |
|
57
|
|
|
|
|
58
|
|
|
$this->runTask(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Runs the task and buffers the output (tasks output directly) |
|
63
|
|
|
* |
|
64
|
|
|
* @return string Task output |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function runTask() |
|
67
|
|
|
{ |
|
68
|
|
|
ob_start(); |
|
69
|
|
|
$this->task->run(null); |
|
|
|
|
|
|
70
|
|
|
return ob_get_clean(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
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.