Passed
Push — master ( b6f9c0...18138a )
by Robbie
02:20
created

PackageSecurityExtensionTest::testGetBadgesHook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace BringYourOwnIdeas\SecurityChecker\Tests\Extensions;
4
5
use BringYourOwnIdeas\Maintenance\Model\Package;
0 ignored issues
show
Bug introduced by
The type BringYourOwnIdeas\Maintenance\Model\Package was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use SilverStripe\Dev\SapphireTest;
7
use Symbiote\QueuedJobs\Services\QueuedJobService;
8
9
class PackageSecurityExtensionTest extends SapphireTest
10
{
11
    protected static $fixture_file = 'PackageSecurityExtensionTest.yml';
12
13
    protected function setUp()
14
    {
15
        if (!class_exists(Package::class)) {
16
            static::$fixture_file = null;
17
            $this->markTestSkipped('This test class requires the maintenance module to be installed');
18
        }
19
20
        QueuedJobService::config()->set('use_shutdown_function', false);
21
22
        parent::setUp();
23
    }
24
25
    public function testAlertsAreIncludedInDataSchema()
26
    {
27
        /** @var Package $package */
28
        $package = $this->objFromFixture(Package::class, 'package_a');
29
30
        $dataSchema = $package->getDataSchema();
31
        $this->assertArrayHasKey('securityAlerts', $dataSchema);
32
        $this->assertNotEmpty($dataSchema['securityAlerts']);
33
34
        $firstAlert = $dataSchema['securityAlerts'][0];
35
        $this->assertEquals('SS-123-456', $firstAlert['Identifier']);
36
        $this->assertEquals('silverstripe.org', $firstAlert['ExternalLink']);
37
    }
38
39
    public function testListSecurityAlertIdentifiers()
40
    {
41
        /** @var Package $package */
42
        $package = $this->objFromFixture(Package::class, 'otheralerts');
43
44
        $this->assertEquals('ABC-001, SPY-007', $package->listSecurityAlertIdentifiers());
45
    }
46
47
    public function testGetBadgesHook()
48
    {
49
        /** @var Package $package */
50
        $package = $this->objFromFixture(Package::class, 'otheralerts');
51
52
        $badges = $package->getBadges();
53
        $this->assertCount(1, $badges);
54
        $this->assertEquals('warning security-alerts__toggler', $badges->first()->Type);
0 ignored issues
show
Bug introduced by
The method first() does not exist on Countable. It seems like you code against a sub-type of Countable such as SilverStripe\ORM\SS_List. ( Ignorable by Annotation )

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

54
        $this->assertEquals('warning security-alerts__toggler', $badges->/** @scrutinizer ignore-call */ first()->Type);
Loading history...
Bug introduced by
The method first() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as IntlCodePointBreakIterator or IntlRuleBasedBreakIterator or IntlBreakIterator or SilverStripe\ORM\SS_List or SilverStripe\View\ViewableData or SilverStripe\ORM\Connect\Query. ( Ignorable by Annotation )

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

54
        $this->assertEquals('warning security-alerts__toggler', $badges->/** @scrutinizer ignore-call */ first()->Type);
Loading history...
55
    }
56
}
57