Completed
Push — master ( d8776d...afe412 )
by Robbie
46s queued 25s
created

testGetModulesFromComposerLock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 27
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Core\Tests\Manifest;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Core\Manifest\VersionProvider;
7
use SilverStripe\Dev\SapphireTest;
8
9
class VersionProviderTest extends SapphireTest
10
{
11
    /**
12
     * @var VersionProvider
13
     */
14
    protected $provider;
15
16
    protected function setUp() : void
17
    {
18
        parent::setUp();
19
        $this->provider = new VersionProvider;
20
    }
21
22
    public function testGetModules()
23
    {
24
        Config::modify()->set(VersionProvider::class, 'modules', [
25
            'silverstripe/somepackage' => 'Some Package',
26
            'silverstripe/hidden' => '',
27
            'silverstripe/another' => 'Another'
28
        ]);
29
30
        $result = $this->provider->getModules();
31
        $this->assertArrayHasKey('silverstripe/somepackage', $result);
32
        $this->assertSame('Some Package', $result['silverstripe/somepackage']);
33
        $this->assertArrayHasKey('silverstripe/another', $result);
34
        $this->assertArrayNotHasKey('silverstripe/hidden', $result);
35
    }
36
37
    public function testGetModuleVersionFromComposer()
38
    {
39
        Config::modify()->set(VersionProvider::class, 'modules', [
40
            'silverstripe/framework' => 'Framework',
41
            'silverstripe/siteconfig' => 'SiteConfig'
42
        ]);
43
44
        $result = $this->provider->getModules(['silverstripe/framework']);
0 ignored issues
show
Unused Code introduced by
The call to SilverStripe\Core\Manife...nProvider::getModules() has too many arguments starting with array('silverstripe/framework'). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        /** @scrutinizer ignore-call */ 
45
        $result = $this->provider->getModules(['silverstripe/framework']);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
45
        $this->assertArrayHasKey('silverstripe/framework', $result);
46
        $this->assertNotEmpty($result['silverstripe/framework']);
47
    }
48
49
    public function testGetVersion()
50
    {
51
        Config::modify()->set(VersionProvider::class, 'modules', [
52
            'silverstripe/framework' => 'Framework',
53
            'silverstripe/siteconfig' => 'SiteConfig'
54
        ]);
55
56
        $result = $this->provider->getVersion();
57
        $this->assertStringContainsString('SiteConfig: ', $result);
58
        $this->assertStringContainsString('Framework: ', $result);
59
        $this->assertStringContainsString(', ', $result);
60
    }
61
62
    public function testGetModulesFromComposerLock()
63
    {
64
        $mock = $this->getMockBuilder(VersionProvider::class)
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

64
        $mock = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(VersionProvider::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
65
            ->setMethods(['getComposerLock'])
66
            ->getMock();
67
68
        $mock->expects($this->once())
69
            ->method('getComposerLock')
70
            ->will($this->returnValue([
71
                'packages' => [
72
                    [
73
                        'name' => 'silverstripe/somepackage',
74
                        'version' => '1.2.3'
75
                    ],
76
                    [
77
                        'name' => 'silverstripe/another',
78
                        'version' => '2.3.4'
79
                    ]
80
                ]
81
            ]));
82
83
        Config::modify()->set(VersionProvider::class, 'modules', [
84
            'silverstripe/somepackage' => 'Some Package'
85
        ]);
86
87
        $result = $mock->getVersion();
88
        $this->assertStringContainsString('Some Package: 1.2.3', $result);
89
    }
90
}
91