/
GnupgSignatureVerifierTest.php
62 lines (50 loc) · 2.23 KB
/
GnupgSignatureVerifierTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php declare(strict_types=1);
/*
* This file is part of Phive.
*
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Phive;
use Exception;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
/**
* @covers \PharIo\Phive\GnupgSignatureVerifier
*/
class GnupgSignatureVerifierTest extends TestCase {
/** @var GnuPG|ObjectProphecy */
private $gnupg;
/** @var KeyService|ObjectProphecy */
private $keyservice;
protected function setUp(): void {
$this->gnupg = $this->prophesize(GnuPG::class);
$this->keyservice = $this->prophesize(KeyService::class);
}
public function testThrowsVerificationFailedExceptionIfGnuPgThrowsException(): void {
$this->gnupg->verify('foo', 'bar')->willThrow(new Exception());
$verifier = new GnupgSignatureVerifier($this->gnupg->reveal(), $this->keyservice->reveal());
$this->expectException(VerificationFailedException::class);
$verifier->verify('foo', 'bar', []);
}
public function testReturnsExpectedVerificationResult(): void {
$verificationData = ['summary' => 1, 'fingerprint' => 'foo'];
$this->gnupg->verify('foo', 'bar')->willReturn([$verificationData]);
$verifier = new GnupgSignatureVerifier($this->gnupg->reveal(), $this->keyservice->reveal());
$actual = $verifier->verify('foo', 'bar', []);
$expected = new GnupgVerificationResult($verificationData);
$this->assertEquals($expected, $actual);
}
public function testTriesToImportMissingKey(): void {
$verificationData = ['summary' => 128, 'fingerprint' => 'foo'];
$this->gnupg->verify('foo', 'bar')->willReturn([$verificationData]);
$result = $this->prophesize(KeyImportResult::class);
$result->isSuccess()->willReturn(true);
$this->keyservice->importKey('foo', [])->shouldBeCalled()->willReturn($result->reveal());
$verifier = new GnupgSignatureVerifier($this->gnupg->reveal(), $this->keyservice->reveal());
$verifier->verify('foo', 'bar', []);
}
}