Completed
Push — master ( d4cdf1...85bc2e )
by
unknown
11s
created

testGetSupportedPackagesEchosErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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

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...
31
        $this->assertCount(1, $output);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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

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...
42
            ->setMethods(['getAddonNames'])
43
            ->getMock();
44
45
        $supportedAddonsLoader->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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...
46
            ->method('getAddonNames')
47
            ->will($this->throwException(new RuntimeException('A test message')));
0 ignored issues
show
Bug introduced by
The method throwException() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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

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...
64
            ->setMethods(['getLock'])->getMock();
65
        $composerLoader->expects($this->any())->method('getLock')->will($this->returnValue(json_decode(<<<LOCK
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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 returnValue() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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

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...
86
            ->setMethods(['getAddonNames'])
87
            ->getMock();
88
        $supportedAddonsLoader->expects($this->once())
0 ignored issues
show
Bug introduced by
The method once() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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...
89
            ->method('getAddonNames')
90
            ->will($this->returnValue(['fake/supported-package']));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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...
91
        $task->setSupportedAddonsLoader($supportedAddonsLoader);
92
93
        $task->run(null);
94
95
        $packages = Package::get();
96
        $this->assertCount(2, $packages);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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...
97
98
        $package = $packages->find('Name', 'fake/supported-package');
99
        $this->assertInstanceOf(Package::class, $package);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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...
100
        $this->assertEquals(1, $package->Supported);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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...
101
102
        $package = $packages->find('Name', 'fake/unsupported-package');
103
        $this->assertInstanceOf(Package::class, $package);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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...
104
        $this->assertEquals(0, $package->Supported);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<BringYourOwnIdeas...\UpdatePackageInfoTest>.

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...
105
    }
106
}
107