Completed
Push — master ( 55accb...6b95b9 )
by
unknown
17:55
created

testOnlyAllowedPackageTypesAreProcessed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace BringYourOwnIdeas\UpdateChecker\Tests\Extensions;
4
5
use BringYourOwnIdeas\Maintenance\Util\ComposerLoader;
6
use BringYourOwnIdeas\UpdateChecker\Extensions\CheckComposerUpdatesExtension;
7
use BringYourOwnIdeas\UpdateChecker\UpdateChecker;
8
use Composer\Composer;
9
use Composer\Package\PackageInterface;
10
use Composer\Package\RootPackage;
11
use Config;
12
use Injector;
13
use Package;
14
use PHPUnit_Framework_TestCase;
15
use SapphireTest;
16
use UpdatePackageInfoTask;
17
18
/**
19
 * @mixin PHPUnit_Framework_TestCase
20
 */
21
class CheckComposerUpdatesExtensionTest extends SapphireTest
22
{
23
    protected $usesDatabase = true;
24
25
    /**
26
     * @var UpdatePackageInfoTask|CheckComposerUpdatesExtension
27
     */
28
    protected $task;
29
30
    /**
31
     * @var string[]
32
     */
33
    protected $allowedTypes;
34
35
    public function setUp()
36
    {
37
        parent::setUp();
38
39
        $this->task = UpdatePackageInfoTask::create();
40
41
        // Create a partial mock of the update checker
42
        $updateCheckerMock = $this->getMockBuilder(UpdateChecker::class)->setMethods(['checkForUpdates'])->getMock();
43
        $this->task->setUpdateChecker($updateCheckerMock);
44
45
        $this->allowedTypes = ['silverstripe-module', 'silverstripe-vendormodule', 'silverstripe-theme'];
46
        Config::inst()->update(UpdatePackageInfoTask::class, 'allowed_types', $this->allowedTypes);
47
    }
48
49
    public function testRunPassesPackagesToUpdateChecker()
50
    {
51
        $this->task->getUpdateChecker()->expects($this->atLeastOnce())
52
            ->method('checkForUpdates')
53
            ->with($this->isInstanceOf(PackageInterface::class), $this->isType('string'))
54
            ->will($this->returnValue([]));
55
56
        $this->runTask();
57
    }
58
59
    public function testOnlyAllowedPackageTypesAreProcessed()
60
    {
61
        $this->task->getUpdateChecker()->expects($this->atLeastOnce())
62
            ->method('checkForUpdates')
63
            ->with($this->callback(function ($argument) {
64
                return in_array($argument->getType(), $this->allowedTypes);
65
            }))
66
            ->will($this->returnValue([]));
67
68
        $this->runTask();
69
    }
70
71
    /**
72
     * Runs the task and buffers the output (tasks output directly)
73
     *
74
     * @return string Task output
75
     */
76
    protected function runTask()
77
    {
78
        ob_start();
79
        $this->task->run(null);
80
        return ob_get_clean();
81
    }
82
}
83