Completed
Push — master ( fa5ac7...eb2a5f )
by Jan
06:08
created

CryptographyServiceTest::getReceiptData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatEET\Cryptography;
4
5
use SlevomatEET\Formatter;
6
7
class CryptographyServiceTest extends \PHPUnit\Framework\TestCase
8
{
9
10
	const EXPECTED_PKP = 'a0asEiJhFCBlVtptSspKvEZhcrvnzF7SQ55C4DhnStnSu1b37GUI2+Dlme9P94UCPZ1oCUPJdsYOBZ3IX6aEgEe0FJKXYX0kXraYCJKIo3g64wRchE7iblIOBCK1uHh8qqHA66Isnhb6hqBOOdlt2aWO/0jCzlfeQr0axpPF1mohMnP3h3ICaxZh0dnMdju5OmMrq+91PL5T9KkR7bfGHqAoWJ0kmxY/mZumtRfGil2/xf7I5pdVeYXPgDO/Tojzm6J95n68fPDOXTDrTzKYmqDjpg3kmWepLNQKFXRmkQrkBLToJWG1LDUDm3UTTmPWzq4c0XnGcXJDZglxfolGpA==';
11
	const EXPECTED_BKP = '9356D566-A3E48838-FB403790-D201244E-95DCBD92';
12
13
	public function testGetCodes()
14
	{
15
		$data = $this->getReceiptData();
16
		$crypto = new CryptographyService(__DIR__ . '/../../../cert/EET_CA1_Playground-CZ00000019.key', __DIR__ . '/../../../cert/EET_CA1_Playground-CZ00000019.pub');
17
18
		$expectedPkp = base64_decode(self::EXPECTED_PKP);
19
		$pkpCode = $crypto->getPkpCode($data);
20
		self::assertSame($expectedPkp, $pkpCode);
21
		self::assertSame(self::EXPECTED_BKP, $crypto->getBkpCode($pkpCode));
22
	}
23
24 View Code Duplication
	public function testExceptions()
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...
25
	{
26
		$cryptoService = new CryptographyService(
27
			__DIR__ . '/invalid-certificate.pem',
28
			__DIR__ . '/invalid-certificate.pem'
29
		);
30
31
		try {
32
			$cryptoService->getPkpCode($this->getReceiptData());
33
			$this->fail();
34
35
		} catch (PrivateKeyFileException $e) {
36
			$this->assertSame(__DIR__ . '/invalid-certificate.pem', $e->getPrivateKeyFile());
37
		}
38
	}
39
40
	/**
41
	 * @runInSeparateProcess
42
	 */
43 View Code Duplication
	public function testExceptions2()
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...
44
	{
45
		include __DIR__ . '/OpenSslFunctionsMock.php';
46
47
		$cryptoService = new CryptographyService(
48
			__DIR__ . '/../../../cert/EET_CA1_Playground-CZ00000019.key',
49
			__DIR__ . '/../../../cert/EET_CA1_Playground-CZ00000019.pub'
50
		);
51
52
		try {
53
			$cryptoService->getPkpCode($this->getReceiptData());
54
			$this->fail();
55
56
		} catch (SigningFailedException $e) {
57
			$this->assertSame(array_values($this->getReceiptData()), $e->getData());
58
		}
59
	}
60
61
	private function getReceiptData():array
62
	{
63
		return [
64
			'dic_popl' => 'CZ00000019',
65
			'id_provoz' => '273',
66
			'id_pokl' => '/5546/RO24',
67
			'porad_cis' => '0/6460/ZQ42',
68
			'dat_trzby' => Formatter::formatDateTime(new \DateTimeImmutable('2016-08-05 00:30:12', new \DateTimeZone('Europe/Prague'))),
69
			'celk_trzba' => Formatter::formatAmount(3411300),
70
		];
71
	}
72
73
}
74