Completed
Pull Request — master (#71)
by
unknown
03:46
created

UpdatePackageInfoTest::testGetPackageInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 14
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
    public function testGetPackageInfo()
19
    {
20
        $lockOutput = [(object) [
21
            "name" => "fake/package",
22
            "description" => "A faux package from a mocked composer.lock for testing purposes",
23
            "version" => "1.0.0",
24
        ]];
25
26
        $processor = new UpdatePackageInfoTask;
27
        $output = $processor->getPackageInfo($lockOutput);
28
        $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...
29
        $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...
30
        $this->assertContains([
31
            "Name" => "fake/package",
32
            "Description" => "A faux package from a mocked composer.lock for testing purposes",
33
            "Version" => "1.0.0"
34
        ], $output);
35
    }
36
37
    public function testGetSupportedPackagesEchosErrors()
38
    {
39
        $supportedAddonsLoader = $this->getMock(SupportedAddonsLoader::class, ['getAddonNames']);
0 ignored issues
show
Bug introduced by
The method getMock() 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...
40
41
        $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...
42
            ->method('getAddonNames')
43
            ->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...
44
45
        $task = new UpdatePackageInfoTask;
46
        $task->setSupportedAddonsLoader($supportedAddonsLoader);
47
48
        ob_start();
49
        $task->getSupportedPackages();
50
        $output = ob_get_clean();
51
52
        $this->assertContains('A test message', $output);
53
    }
54
55
    public function testPackagesAreAddedCorrectly()
56
    {
57
        $task = new UpdatePackageInfoTask;
58
59
        $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...
60
            ->setMethods(['getLock'])->getMock();
61
        $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...
62
{
63
    "packages": [
64
        {
65
            "name": "fake/supported-package",
66
            "description": "A faux package from a mocked composer.lock for testing purposes",
67
            "version": "1.0.0"
68
        },
69
        {
70
            "name": "fake/unsupported-package",
71
            "description": "A faux package from a mocked composer.lock for testing purposes",
72
            "version": "1.0.0"
73
        }
74
    ],
75
    "packages-dev": null
76
}
77
LOCK
78
        )));
79
        $task->setComposerLoader($composerLoader);
80
81
        $supportedAddonsLoader = $this->getMock(SupportedAddonsLoader::class, ['getAddonNames']);
0 ignored issues
show
Bug introduced by
The method getMock() 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...
82
        $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...
83
            ->method('getAddonNames')
84
            ->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...
85
        $task->setSupportedAddonsLoader($supportedAddonsLoader);
86
87
        $task->run(null);
88
89
        $packages = Package::get();
90
        $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...
91
92
        $package = $packages->first();
93
        $this->assertSame('fake/supported-package', $package->Name);
0 ignored issues
show
Bug introduced by
The method assertSame() 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...
94
        $this->assertSame('1', $package->Supported);
0 ignored issues
show
Bug introduced by
The method assertSame() 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...
95
96
        $package = $packages->last();
97
        $this->assertSame('fake/unsupported-package', $package->Name);
0 ignored issues
show
Bug introduced by
The method assertSame() 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...
98
        $this->assertSame('0', $package->Supported);
0 ignored issues
show
Bug introduced by
The method assertSame() 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...
99
    }
100
}
101