Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 0e5184c

Browse files
committed
📝 Create tests
1 parent d3c7c59 commit 0e5184c

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
],
5757
"phpstan": "phpstan analyse -c phpstan.neon -l 7 src/",
5858
"phpcs": "phpcs --standard=phpcs.xml --encoding=utf-8 --colors -sp src/ tests/",
59-
"tester": "tester tests/"
59+
"tester": "tester -c tests/php.ini tests/",
60+
"coverage": "tester . -c tests/php.ini --coverage coverage.html --coverage-src src/ --colors 1"
6061
}
6162
}

tests/EETTests/DispatcherTest.phpt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@ require_once __DIR__ . '/../bootstrap.php';
1818

1919
class DispatcherTest extends TestCase
2020
{
21+
public function testService(): void
22+
{
23+
$certificate = new Certificate(__DIR__ . '/../Data/EET_CA1_Playground-CZ00000019.p12', 'eet');
24+
25+
$dispatcher = new Dispatcher($certificate, 'Personal/MySchema/MyService.wsdl');
26+
27+
Assert::contains('Personal/MySchema/MyService.wsdl', $dispatcher->getService());
28+
29+
$schemaPath = 'FilipSedivy/EET/Schema';
30+
31+
$dispatcher->setProductionService();
32+
33+
Assert::contains($schemaPath . '/ProductionService.wsdl', $dispatcher->getService());
34+
35+
$dispatcher->setPlaygroundService();
36+
37+
Assert::contains($schemaPath . '/PlaygroundService.wsdl', $dispatcher->getService());
38+
39+
$dispatcher->setService('Personal/MySchema/MyService.wsdl');
40+
41+
Assert::contains('Personal/MySchema/MyService.wsdl', $dispatcher->getService());
42+
43+
$dispatcher = new Dispatcher($certificate, Dispatcher::PRODUCTION_SERVICE);
44+
45+
Assert::contains($schemaPath . '/ProductionService.wsdl', $dispatcher->getService());
46+
}
47+
2148
public function testSendReceipt(): void
2249
{
2350
$certificate = new Certificate(__DIR__ . '/../Data/EET_CA1_Playground-CZ00000019.p12', 'eet');
@@ -53,6 +80,33 @@ class DispatcherTest extends TestCase
5380
}
5481
}
5582

83+
public function testCheck(): void
84+
{
85+
$certificate = new Certificate(__DIR__ . '/../Data/EET_CA1_Playground-CZ00000019.p12', 'eet');
86+
$dispatcher = new Dispatcher($certificate, Dispatcher::PLAYGROUND_SERVICE);
87+
88+
$receipt = $this->getValidReceipt();
89+
Assert::true($dispatcher->check($receipt));
90+
91+
$receipt->dic_popl = 'CZ00000018';
92+
Assert::false($dispatcher->check($receipt));
93+
}
94+
95+
public function testGetCheckCodes(): void
96+
{
97+
$certificate = new Certificate(__DIR__ . '/../Data/EET_CA1_Playground-CZ00000019.p12', 'eet');
98+
$dispatcher = new Dispatcher($certificate, Dispatcher::PLAYGROUND_SERVICE);
99+
100+
$receipt = $this->getValidReceipt();
101+
102+
Assert::type('array', $dispatcher->getCheckCodes($receipt));
103+
104+
$receipt->bkp = $dispatcher->getBkp();
105+
$receipt->pkp = $dispatcher->getPkp(false);
106+
107+
Assert::type('array', $dispatcher->getCheckCodes($receipt));
108+
}
109+
56110
private function getValidReceipt(): Receipt
57111
{
58112
$receipt = new Receipt();

tests/EETTests/ReceiptTest.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace EETTest;
99

10+
use FilipSedivy\EET\Certificate;
11+
use FilipSedivy\EET\Dispatcher;
12+
use FilipSedivy\EET\Exceptions\Receipt\ConstraintViolationException;
1013
use FilipSedivy\EET\Receipt;
1114
use Tester\Assert;
1215
use Tester\TestCase;
@@ -27,6 +30,17 @@ class ReceiptTest extends TestCase
2730

2831
Assert::same($receipt->buildHeader(), $header);
2932
}
33+
34+
public function testSendEmptyReceipt()
35+
{
36+
$certificate = new Certificate(__DIR__ . '/../Data/EET_CA1_Playground-CZ00000019.p12', 'eet');
37+
$dispatcher = new Dispatcher($certificate, Dispatcher::PLAYGROUND_SERVICE);
38+
39+
Assert::exception(function () use ($dispatcher) {
40+
$receipt = new Receipt();
41+
$dispatcher->send($receipt);
42+
}, ConstraintViolationException::class);
43+
}
3044
}
3145

3246
(new ReceiptTest())->run();

tests/UtilsTests/FormatTest.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class FormatTest extends TestCase
2121
Assert::same(Format::price(123.4), '123.40');
2222
Assert::same(Format::price(123.45), '123.45');
2323
}
24+
25+
public function testBkpFormat(): void
26+
{
27+
$format = Format::BKB('2fdabd7e8978870662e1d0ec2b51670ac6fedb32');
28+
Assert::same($format, '2fdabd7e-89788706-62e1d0ec-2b51670a-c6fedb32');
29+
}
2430
}
2531

2632
(new FormatTest())->run();

tests/php.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[PHP]
2+
zend_extension=xdebug.so
3+
xdebug.remote_enable=on
4+
xdebug.remote_host=127.0.0.1
5+
xdebug.remote_port=9000
6+
xdebug.remote_handler=xdebug

0 commit comments

Comments
 (0)