Completed
Push — master ( da1a6c...6bb072 )
by Marco
02:08
created

testWillReportFailedVerificationWithMultipleChecks()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 15

Duplication

Lines 29
Ratio 100 %

Importance

Changes 0
Metric Value
dl 29
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\ComposerGpgVerify\Package;
6
7
use Composer\Package\PackageInterface;
8
use PHPUnit\Framework\TestCase;
9
use Roave\ComposerGpgVerify\Package\Git\GitSignatureCheck;
10
use Roave\ComposerGpgVerify\Package\GitPackage;
11
12
/**
13
 * @covers \Roave\ComposerGpgVerify\Package\GitPackage
14
 */
15
final class GitPackageTest extends TestCase
16
{
17
    /**
18
     * @var PackageInterface
19
     */
20
    private $package;
21
22
    /**
23
     * @var string
24
     */
25
    private $packageName;
26
27
    protected function setUp() : void
28
    {
29
        parent::setUp();
30
31
        $this->packageName = uniqid('packageName', true);
32
33
        /* @var $package PackageInterface|\PHPUnit_Framework_MockObject_MockObject */
34
        $package = $this->createMock(PackageInterface::class);
35
36
        $package->expects(self::any())->method('getName')->willReturn($this->packageName);
37
38
        $this->package = $package;
0 ignored issues
show
Documentation Bug introduced by
It seems like $package can also be of type object<PHPUnit_Framework_MockObject_MockObject>. However, the property $package is declared as type object<Composer\Package\PackageInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
39
    }
40
41 View Code Duplication
    public function testWillReportSuccessfulVerification() : void
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...
42
    {
43
        $verification = GitPackage::fromPackageAndSignatureChecks(
44
            $this->package,
45
            $this->makeSignatureCheck(true, 'yadda')
46
        );
47
48
        self::assertInstanceOf(GitPackage::class, $verification);
49
        self::assertSame($this->packageName, $verification->packageName());
50
        self::assertTrue($verification->isVerified());
51
        self::assertSame(
52
            <<<REASON
53
The following GIT GPG signature checks passed for package "{$this->packageName}":
54
55
yadda
56
REASON
57
            ,
58
            $verification->printReason()
59
        );
60
    }
61
62 View Code Duplication
    public function testWillReportSuccessfulVerificationWithMultipleChecks() : void
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...
63
    {
64
        $verification = GitPackage::fromPackageAndSignatureChecks(
65
            $this->package,
66
            $this->makeSignatureCheck(true, 'yadda'),
67
            $this->makeSignatureCheck(true, 'dadda'),
68
            $this->makeSignatureCheck(true, 'wadda'),
69
            $this->makeSignatureCheck(false, 'nope')
70
        );
71
72
        self::assertInstanceOf(GitPackage::class, $verification);
73
        self::assertSame($this->packageName, $verification->packageName());
74
        self::assertTrue($verification->isVerified());
75
        self::assertSame(
76
            <<<REASON
77
The following GIT GPG signature checks passed for package "{$this->packageName}":
78
79
yadda
80
81
dadda
82
83
wadda
84
REASON
85
            ,
86
            $verification->printReason()
87
        );
88
    }
89
90 View Code Duplication
    public function testWillReportFailedVerification() : void
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...
91
    {
92
        $verification = GitPackage::fromPackageAndSignatureChecks(
93
            $this->package,
94
            $this->makeSignatureCheck(false, 'yadda')
95
        );
96
97
        self::assertInstanceOf(GitPackage::class, $verification);
98
        self::assertSame($this->packageName, $verification->packageName());
99
        self::assertFalse($verification->isVerified());
100
        self::assertSame(
101
            <<<REASON
102
The following GIT GPG signature checks have failed for package "{$this->packageName}":
103
104
yadda
105
REASON
106
            ,
107
            $verification->printReason()
108
        );
109
    }
110
111 View Code Duplication
    public function testWillReportFailedVerificationWithMultipleChecks() : void
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...
112
    {
113
        $verification = GitPackage::fromPackageAndSignatureChecks(
114
            $this->package,
115
            $this->makeSignatureCheck(false, 'yadda'),
116
            $this->makeSignatureCheck(false, 'dadda'),
117
            $this->makeSignatureCheck(false, 'wadda'),
118
            $this->makeSignatureCheck(false, 'nope')
119
        );
120
121
        self::assertInstanceOf(GitPackage::class, $verification);
122
        self::assertSame($this->packageName, $verification->packageName());
123
        self::assertFalse($verification->isVerified());
124
        self::assertSame(
125
            <<<REASON
126
The following GIT GPG signature checks have failed for package "{$this->packageName}":
127
128
yadda
129
130
dadda
131
132
wadda
133
134
nope
135
REASON
136
            ,
137
            $verification->printReason()
138
        );
139
    }
140
141 View Code Duplication
    public function testWillReportSuccessfulVerificationWithMultipleChecksAndSuccessfulOneNotFirst() : void
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...
142
    {
143
        $verification = GitPackage::fromPackageAndSignatureChecks(
144
            $this->package,
145
            $this->makeSignatureCheck(false, 'yadda'),
146
            $this->makeSignatureCheck(false, 'dadda'),
147
            $this->makeSignatureCheck(false, 'wadda'),
148
            $this->makeSignatureCheck(true, 'yarp')
149
        );
150
151
        self::assertInstanceOf(GitPackage::class, $verification);
152
        self::assertSame($this->packageName, $verification->packageName());
153
        self::assertTrue($verification->isVerified());
154
        self::assertSame(
155
            <<<REASON
156
The following GIT GPG signature checks passed for package "{$this->packageName}":
157
158
yarp
159
REASON
160
            ,
161
            $verification->printReason()
162
        );
163
    }
164
165
    private function makeSignatureCheck(bool $passed, string $reasoning) : GitSignatureCheck
166
    {
167
        /* @var $verification GitSignatureCheck|\PHPUnit_Framework_MockObject_MockObject */
168
        $verification = $this->createMock(GitSignatureCheck::class);
169
170
        $verification->expects(self::any())->method('asHumanReadableString')->willReturn($reasoning);
1 ignored issue
show
Bug introduced by
The method expects() does not seem to exist on object<Roave\ComposerGpg...\Git\GitSignatureCheck>.

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...
171
        $verification->expects(self::any())->method('canBeTrusted')->willReturn($passed);
1 ignored issue
show
Bug introduced by
The method expects() does not seem to exist on object<Roave\ComposerGpg...\Git\GitSignatureCheck>.

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...
172
173
        return $verification;
174
    }
175
}
176