1 | <?php |
||
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 |
||
40 | |||
41 | public function testWillReportSuccessfulVerification() : void |
||
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 | public function testWillReportSuccessfulVerificationWithMultipleChecks() : void |
||
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 | public function testWillReportFailedVerification() : void |
||
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 | public function testWillReportFailedVerificationWithMultipleChecks() : void |
||
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 | public function testWillReportSuccessfulVerificationWithMultipleChecksAndSuccessfulOneNotFirst() : void |
||
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 |
||
175 | } |
||
176 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: