Completed
Pull Request — master (#28)
by Robbie
12:24
created

CheckComposerUpdatesTaskTest::runTask()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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();
0 ignored issues
show
Bug introduced by
The method getMockBuilder() does not seem to exist on object<BringYourOwnIdeas...omposerUpdatesTaskTest>.

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.

Loading history...
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())
0 ignored issues
show
Bug introduced by
The method atLeastOnce() does not seem to exist on object<BringYourOwnIdeas...omposerUpdatesTaskTest>.

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.

Loading history...
Bug introduced by
The method expects() does not seem to exist on object<BringYourOwnIdeas...eChecker\UpdateChecker>.

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.

Loading history...
43
            ->method('checkForUpdates')
44
            ->with($this->isInstanceOf(PackageInterface::class), $this->isType('string'));
0 ignored issues
show
Bug introduced by
The method isInstanceOf() does not seem to exist on object<BringYourOwnIdeas...omposerUpdatesTaskTest>.

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.

Loading history...
Bug introduced by
The method isType() does not seem to exist on object<BringYourOwnIdeas...omposerUpdatesTaskTest>.

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.

Loading history...
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())
0 ignored issues
show
Bug introduced by
The method atLeastOnce() does not seem to exist on object<BringYourOwnIdeas...omposerUpdatesTaskTest>.

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.

Loading history...
Bug introduced by
The method expects() does not seem to exist on object<BringYourOwnIdeas...eChecker\UpdateChecker>.

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.

Loading history...
53
            ->method('checkForUpdates')
54
            ->with($this->callback(function ($argument) {
0 ignored issues
show
Bug introduced by
The method callback() does not seem to exist on object<BringYourOwnIdeas...omposerUpdatesTaskTest>.

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.

Loading history...
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);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<SS_HTTPRequest>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
        return ob_get_clean();
71
    }
72
}
73