Completed
Pull Request — master (#34)
by
unknown
05:06
created

CVECheckTaskTest::getSecurityCheckerMock()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 8
nc 1
nop 1
1
<?php
2
3
use SensioLabs\Security\SecurityChecker;
4
5
class CVECheckTaskTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    protected $usesDatabase = true;
8
9
    /**
10
     * provide a mock to remove dependency on external service
11
     */
12
    protected function getSecurityCheckerMock($empty = false)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
13
    {
14
        $mockOutput = <<<CVENOTICE
15
{
16
    "symfony\/symfony": {
17
        "version": "2.1.x-dev",
18
        "advisories": {
19
            "symfony\/symfony\/CVE-2013-1397.yaml": {
20
                "title": "Ability to enable\/disable object support in YAML parsing and dumping",
21
                "link": "http:\/\/symfony.com\/blog\/security-release-symfony-2-0-22-and-2-1-7-released",
22
                "cve": "CVE-2013-1397"
23
            }
24
        }
25
    }
26
}
27
CVENOTICE;
28
29
        $securityCheckerMock = $this->getMockBuilder(SecurityChecker::class)->setMethods(['check'])->getMock();
0 ignored issues
show
Bug introduced by
The method getMockBuilder() does not seem to exist on object<CVECheckTaskTest>.

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
        $securityCheckerMock->expects($this->any())->method('check')->will($this->returnValue(
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<CVECheckTaskTest>.

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<CVECheckTaskTest>.

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
            $empty ? [] : json_decode($mockOutput, true)
32
        ));
33
34
        return $securityCheckerMock;
35
    }
36
37
    public function testUpdatesAreSaved()
38
    {
39
        $securityCheckerMock = $this->getSecurityCheckerMock();
40
        $checkTask = new CVECheckTask;
41
        $checkTask->setSecurityChecker($securityCheckerMock);
42
43
        $preCheck = CVE::get();
44
        $this->assertEquals(0, $preCheck->count(), 'database is empty to begin with');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CVECheckTaskTest>.

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...
45
46
        $checkTask->run(null);
47
48
        $postCheck = CVE::get();
49
        $this->assertEquals(1, $postCheck->count(), 'CVE has been stored');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CVECheckTaskTest>.

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...
50
    }
51
52 View Code Duplication
    public function testNoDuplicates()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $securityCheckerMock = $this->getSecurityCheckerMock();
55
        $checkTask = new CVECheckTask;
56
        $checkTask->setSecurityChecker($securityCheckerMock);
57
58
        $preCheck = CVE::get();
59
        $this->assertEquals(0, $preCheck->count(), 'database is empty to begin with');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CVECheckTaskTest>.

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
61
        $checkTask->run(null);
62
63
        $postCheck = CVE::get();
64
        $this->assertEquals(1, $postCheck->count(), 'CVE has been stored');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CVECheckTaskTest>.

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...
65
        
66
        $checkTask->run(null);
67
68
        $postCheck = CVE::get();
69
        $this->assertEquals(1, $postCheck->count(), 'The CVE isn\'t stored twice.');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CVECheckTaskTest>.

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...
70
    }
71
72 View Code Duplication
    public function testCVERemovals()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        $securityCheckerMock = $this->getSecurityCheckerMock();
75
        $checkTask = new CVECheckTask;
76
        $checkTask->setSecurityChecker($securityCheckerMock);
77
78
        $checkTask->run(null);
79
80
        $preCheck = CVE::get();
81
        $this->assertEquals(1, $preCheck->count(), 'database has stored CVEs');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CVECheckTaskTest>.

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
83
        $securityCheckerMock = $this->getSecurityCheckerMock(true);
84
        $checkTask->setSecurityChecker($securityCheckerMock);
85
86
        $checkTask->run(null);
87
88
        $postCheck = CVE::get();
89
        $this->assertEquals(0, $postCheck->count(), 'database is empty to finish with');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CVECheckTaskTest>.

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...
90
    }
91
}
92