EvidenceRequestTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 82
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
B testRequestFormatting() 0 69 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatEET;
4
5
use DateTimeImmutable;
6
use DateTimeZone;
7
use PHPUnit\Framework\TestCase;
8
use SlevomatEET\Cryptography\CryptographyService;
9
10
class EvidenceRequestTest extends TestCase
11
{
12
13
	/** @var Configuration */
14
	private $configuration;
15
16
	public function setUp(): void
17
	{
18
		$this->configuration = new Configuration('CZ00000019', '273', '/5546/RO24', EvidenceEnvironment::get(EvidenceEnvironment::PLAYGROUND), true);
19
	}
20
21
	public function testRequestFormatting(): void
22
	{
23
		$receipt = new Receipt(
24
			true,
25
			'CZ683555118',
26
			'0/6460/ZQ42',
27
			new DateTimeImmutable('2016-11-01 00:30:12', new DateTimeZone('Europe/Prague')),
28
			3411300
29
		);
30
31
		$crypto = $this->createMock(CryptographyService::class);
32
		$crypto->method('getPkpCode')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
33
			->willReturn('123');
34
35
		$crypto->method('getBkpCode')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
36
			->willReturn('456');
37
38
		$request = new EvidenceRequest($receipt, $this->configuration, $crypto);
0 ignored issues
show
Documentation introduced by
$crypto is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<SlevomatEET\Crypt...hy\CryptographyService>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
40
		$requestData = $request->getRequestData();
41
42
		$this->assertArrayHasKey('Hlavicka', $requestData);
43
		$this->assertArrayHasKey('Data', $requestData);
44
		$this->assertArrayHasKey('KontrolniKody', $requestData);
45
		$headerData = $requestData['Hlavicka'];
46
		$this->assertArrayHasKey('uuid_zpravy', $headerData);
47
		$this->assertArrayHasKey('dat_odesl', $headerData);
48
49
		$this->assertSame($headerData, $request->getHeader());
50
		unset($headerData['uuid_zpravy']);
51
		unset($headerData['dat_odesl']);
52
53
		$this->assertSame([
54
			'prvni_zaslani' => true,
55
			'overeni' => true,
56
		], $headerData);
57
58
		$this->assertSame([
59
			'dic_popl' => 'CZ00000019',
60
			'dic_poverujiciho' => 'CZ683555118',
61
			'id_provoz' => '273',
62
			'id_pokl' => '/5546/RO24',
63
			'porad_cis' => '0/6460/ZQ42',
64
			'dat_trzby' => '2016-11-01T00:30:12+01:00',
65
			'celk_trzba' => '34113.00',
66
			'rezim' => 0,
67
		], $requestData['Data']);
68
69
		$this->assertSame($requestData['Data'], $request->getBody());
70
71
		$this->assertSame([
72
			'pkp' => [
73
				'_' => '123',
74
				'digest' => 'SHA256',
75
				'cipher' => 'RSA2048',
76
				'encoding' => 'base64',
77
			],
78
			'bkp' => [
79
				'_' => '456',
80
				'digest' => 'SHA1',
81
				'encoding' => 'base16',
82
			],
83
		], $requestData['KontrolniKody']);
84
85
		$this->assertSame('123', $request->getPkpCode());
86
		$this->assertSame('456', $request->getBkpCode());
87
88
		$this->assertInstanceOf(DateTimeImmutable::class, $request->getSendDate());
89
	}
90
91
}
92