1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BringYourOwnIdeas\UpdateChecker\Tests\Extensions; |
4
|
|
|
|
5
|
|
|
use BringYourOwnIdeas\Maintenance\Tasks\UpdatePackageInfoTask; |
6
|
|
|
use BringYourOwnIdeas\UpdateChecker\Extensions\CheckComposerUpdatesExtension; |
7
|
|
|
use BringYourOwnIdeas\UpdateChecker\Extensions\ComposerLoaderExtension; |
8
|
|
|
use BringYourOwnIdeas\UpdateChecker\Tests\Stubs\ComposerLoaderExtensionStub; |
9
|
|
|
use BringYourOwnIdeas\UpdateChecker\UpdateChecker; |
10
|
|
|
use Composer\Package\PackageInterface; |
11
|
|
|
use PHPUnit_Framework_TestCase; |
|
|
|
|
12
|
|
|
use SilverStripe\Core\Config\Config; |
13
|
|
|
use SilverStripe\Core\Injector\Injector; |
14
|
|
|
use SilverStripe\Dev\SapphireTest; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @mixin PHPUnit_Framework_TestCase |
18
|
|
|
*/ |
19
|
|
|
class CheckComposerUpdatesExtensionTest extends SapphireTest |
20
|
|
|
{ |
21
|
|
|
protected $usesDatabase = true; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var UpdatePackageInfoTask|CheckComposerUpdatesExtension |
25
|
|
|
*/ |
26
|
|
|
protected $task; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string[] |
30
|
|
|
*/ |
31
|
|
|
protected $allowedTypes; |
32
|
|
|
|
33
|
|
|
protected function setUp(): void |
34
|
|
|
{ |
35
|
|
|
parent::setUp(); |
36
|
|
|
|
37
|
|
|
// Register the extension stub for unit testing to avoid loading Composer |
38
|
|
|
Config::modify()->merge(Injector::class, ComposerLoaderExtension::class, [ |
39
|
|
|
'class' => ComposerLoaderExtensionStub::class, |
40
|
|
|
]); |
41
|
|
|
|
42
|
|
|
// Create the task for testing |
43
|
|
|
$this->task = UpdatePackageInfoTask::create(); |
44
|
|
|
|
45
|
|
|
// Create a partial mock of the update checker |
46
|
|
|
$updateCheckerMock = $this->getMockBuilder(UpdateChecker::class)->setMethods(['checkForUpdates'])->getMock(); |
47
|
|
|
$this->task->setUpdateChecker($updateCheckerMock); |
48
|
|
|
|
49
|
|
|
$this->allowedTypes = ['silverstripe-module', 'silverstripe-vendormodule', 'silverstripe-theme']; |
50
|
|
|
Config::modify()->set(UpdatePackageInfoTask::class, 'allowed_types', $this->allowedTypes); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testRunPassesPackagesToUpdateChecker() |
54
|
|
|
{ |
55
|
|
|
$this->task->getUpdateChecker()->expects($this->atLeastOnce()) |
|
|
|
|
56
|
|
|
->method('checkForUpdates') |
57
|
|
|
->with($this->isInstanceOf(PackageInterface::class), $this->isType('string')) |
58
|
|
|
->will($this->returnValue([])); |
59
|
|
|
|
60
|
|
|
$this->runTask(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testOnlyAllowedPackageTypesAreProcessed() |
64
|
|
|
{ |
65
|
|
|
$this->task->getUpdateChecker()->expects($this->atLeastOnce()) |
66
|
|
|
->method('checkForUpdates') |
67
|
|
|
->with($this->callback(function ($argument) { |
68
|
|
|
return in_array($argument->getType(), $this->allowedTypes); |
69
|
|
|
})) |
70
|
|
|
->will($this->returnValue([])); |
71
|
|
|
|
72
|
|
|
$this->runTask(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Runs the task and buffers the output (tasks output directly) |
77
|
|
|
* |
78
|
|
|
* @return string Task output |
79
|
|
|
*/ |
80
|
|
|
protected function runTask() |
81
|
|
|
{ |
82
|
|
|
ob_start(); |
83
|
|
|
$this->task->run(null); |
|
|
|
|
84
|
|
|
return ob_get_clean(); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths