Completed
Pull Request — master (#71)
by
unknown
01:38
created

UpdatePackageInfoTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 87
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetPackageInfo() 0 18 1
A testGetSupportedPackagesEchosErrors() 0 17 1
B testPackagesAreAddedCorrectly() 0 45 1
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->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...
42
43
        $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...
44
            ->method('getAddonNames')
45
            ->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...
46
47
        $task = new UpdatePackageInfoTask;
48
        $task->setSupportedAddonsLoader($supportedAddonsLoader);
49
50
        ob_start();
51
        $task->getSupportedPackages();
52
        $output = ob_get_clean();
53
54
        $this->assertContains('A test message', $output);
55
    }
56
57
    public function testPackagesAreAddedCorrectly()
58
    {
59
        $task = new UpdatePackageInfoTask;
60
61
        $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...
62
            ->setMethods(['getLock'])->getMock();
63
        $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...
64
{
65
    "packages": [
66
        {
67
            "name": "fake/supported-package",
68
            "description": "A faux package from a mocked composer.lock for testing purposes",
69
            "version": "1.0.0"
70
        },
71
        {
72
            "name": "fake/unsupported-package",
73
            "description": "A faux package from a mocked composer.lock for testing purposes",
74
            "version": "1.0.0"
75
        }
76
    ],
77
    "packages-dev": null
78
}
79
LOCK
80
        )));
81
        $task->setComposerLoader($composerLoader);
82
83
        $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...
84
        $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...
85
            ->method('getAddonNames')
86
            ->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...
87
        $task->setSupportedAddonsLoader($supportedAddonsLoader);
88
89
        $task->run(null);
90
91
        $packages = Package::get();
92
        $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...
93
94
        $package = $packages->first();
95
        $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...
96
        $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...
97
98
        $package = $packages->last();
99
        $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...
100
        $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...
101
    }
102
}
103