Skip to content

Commit 5de7bff

Browse files
committed
Tests: refactor
1 parent dc0f5e4 commit 5de7bff

11 files changed

Lines changed: 107 additions & 143 deletions

File tree

‎src/Entity/AbstractPayment.php‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,88 @@
33
namespace Contributte\Comgate\Entity;
44

55
use Contributte\Comgate\Entity\Codes\CountryCode;
6+
use Contributte\Comgate\Exceptions\LogicException;
67

78
class AbstractPayment extends AbstractEntity
89
{
910

10-
protected int $price;
11+
protected ?int $price = null;
1112

1213
/** @var string ISO 4217 */
13-
protected string $curr;
14+
protected ?string $curr = null;
1415

15-
protected string $label;
16+
protected ?string $label = null;
1617

17-
protected string $refId;
18+
protected ?string $refId = null;
1819

19-
protected string $email;
20+
protected ?string $email = null;
2021

21-
protected string $country = CountryCode::ALL;
22+
protected ?string $country = CountryCode::ALL;
2223

23-
protected string $account;
24+
protected ?string $account = null;
2425

25-
protected string $name;
26+
protected ?string $name = null;
2627

2728
public function getPrice(): int
2829
{
30+
if ($this->price === null) {
31+
throw new LogicException('Price is required');
32+
}
33+
2934
return $this->price;
3035
}
3136

3237
public function getCurr(): string
3338
{
39+
if ($this->curr === null) {
40+
throw new LogicException('Curr is required');
41+
}
42+
3443
return $this->curr;
3544
}
3645

3746
public function getLabel(): string
3847
{
48+
if ($this->label === null) {
49+
throw new LogicException('Label is required');
50+
}
51+
3952
return $this->label;
4053
}
4154

4255
public function getRefId(): string
4356
{
57+
if ($this->refId === null) {
58+
throw new LogicException('RefId is required');
59+
}
60+
4461
return $this->refId;
4562
}
4663

4764
public function getEmail(): string
4865
{
66+
if ($this->email === null) {
67+
throw new LogicException('Email is required');
68+
}
69+
4970
return $this->email;
5071
}
5172

5273
public function getCountry(): string
5374
{
75+
if ($this->country === null) {
76+
throw new LogicException('Country is required');
77+
}
78+
5479
return $this->country;
5580
}
5681

5782
public function getAccount(): string
5883
{
84+
if ($this->account === null) {
85+
throw new LogicException('Account is required');
86+
}
87+
5988
return $this->account;
6089
}
6190

@@ -66,6 +95,10 @@ public function setAccount(string $account): void
6695

6796
public function getName(): string
6897
{
98+
if ($this->name === null) {
99+
throw new LogicException('Name is required');
100+
}
101+
69102
return $this->name;
70103
}
71104

‎tests/.coveralls.yml‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎tests/.gitignore‎

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Tests\Cases\Unit\DI;
4+
5+
use Contributte\Comgate\DI\ComgateExtension;
6+
use Contributte\Comgate\Http\HttpClient;
7+
use Contributte\Tester\Toolkit;
8+
use Contributte\Tester\Utils\ContainerBuilder;
9+
use Nette\DI\Compiler;
10+
use Tester\Assert;
11+
12+
require_once __DIR__ . '/../../bootstrap.php';
13+
14+
Toolkit::test(function (): void {
15+
$container = ContainerBuilder::of()
16+
->withCompiler(function (Compiler $compiler): void {
17+
$compiler->addExtension('comgate', new ComgateExtension())
18+
->addConfig([
19+
'comgate' => [
20+
'merchant' => '123456',
21+
'secret' => 'top',
22+
'test' => true,
23+
],
24+
]);
25+
})->build();
26+
27+
Assert::type(HttpClient::class, $container->getService('comgate.http.client'));
28+
});
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,25 @@
66
use Contributte\Comgate\Entity\Payment;
77
use Contributte\Comgate\Entity\PaymentStatus;
88
use Contributte\Comgate\Gateway\PaymentService;
9+
use Contributte\Tester\Utils\ContainerBuilder;
910
use Nette\DI\Compiler;
1011
use Nette\DI\Container;
11-
use Nette\DI\ContainerLoader;
1212

1313
require __DIR__ . '/../../../vendor/autoload.php';
1414

1515
function createContainer(): Container
1616
{
17-
$loader = new ContainerLoader(__DIR__ . '/../../tmp/cache', false);
18-
$class = $loader->load(function (Compiler $compiler): void {
19-
$compiler->addExtension('comgate', new ComgateExtension())
20-
->addConfig([
21-
'comgate' => [
22-
'merchant' => '***',
23-
'secret' => '***',
24-
'test' => true,
25-
],
26-
]);
27-
}, __FILE__);
28-
29-
/** @var Container $container */
30-
$container = new $class();
31-
32-
return $container;
17+
return ContainerBuilder::of()
18+
->withCompiler(function (Compiler $compiler): void {
19+
$compiler->addExtension('comgate', new ComgateExtension())
20+
->addConfig([
21+
'comgate' => [
22+
'merchant' => '***',
23+
'secret' => '***',
24+
'test' => true,
25+
],
26+
]);
27+
})->build();
3328
}
3429

3530
function createPayment(): void
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ use Contributte\Comgate\Entity\Codes\CountryCode;
77
use Contributte\Comgate\Entity\Codes\LangCode;
88
use Contributte\Comgate\Entity\Codes\PaymentMethodCode;
99
use Contributte\Comgate\Entity\Payment;
10+
use Contributte\Tester\Toolkit;
1011
use Tester\Assert;
1112

12-
require_once __DIR__ . '/../../../bootstrap.php';
13+
require_once __DIR__ . '/../../bootstrap.php';
1314

14-
test(function (): void {
15+
Toolkit::test(function (): void {
1516
$payment = Payment::of(
1617
Money::of(50, 'CZK'),
1718
'Test item',
@@ -40,7 +41,7 @@ test(function (): void {
4041
], $payment->toArray());
4142
});
4243

43-
test(function (): void {
44+
Toolkit::test(function (): void {
4445
$payment = Payment::of(
4546
Money::of(50, 'CZK'),
4647
'Test item',
@@ -51,7 +52,7 @@ test(function (): void {
5152
Assert::equal('true', $payment->toArray()['embedded']);
5253
});
5354

54-
test(function (): void {
55+
Toolkit::test(function (): void {
5556
$payment = Payment::of(
5657
Money::of(50, 'CZK'),
5758
'Test item',
@@ -62,7 +63,7 @@ test(function (): void {
6263
Assert::equal('true', $payment->toArray()['initRecurring']);
6364
});
6465

65-
test(function (): void {
66+
Toolkit::test(function (): void {
6667
$payment = Payment::of(
6768
Money::of(50, 'CZK'),
6869
'Test item',
@@ -73,7 +74,7 @@ test(function (): void {
7374
Assert::equal('true', $payment->toArray()['preauth']);
7475
});
7576

76-
test(function (): void {
77+
Toolkit::test(function (): void {
7778
$payment = Payment::of(
7879
Money::of(50, 'CZK'),
7980
'Test item',
@@ -84,7 +85,7 @@ test(function (): void {
8485
Assert::equal('false', $payment->toArray()['prepareOnly']);
8586
});
8687

87-
test(function (): void {
88+
Toolkit::test(function (): void {
8889
$payment = Payment::of(
8990
Money::of(50, 'CZK'),
9091
'Test item',
@@ -95,7 +96,7 @@ test(function (): void {
9596
Assert::equal('true', $payment->toArray()['verification']);
9697
});
9798

98-
test(function (): void {
99+
Toolkit::test(function (): void {
99100
$payment = Payment::of(
100101
Money::of(50, 'CZK'),
101102
'Test item',
@@ -106,7 +107,7 @@ test(function (): void {
106107
Assert::equal('item101', $payment->toArray()['name']);
107108
});
108109

109-
test(function (): void {
110+
Toolkit::test(function (): void {
110111
$payment = Payment::of(
111112
Money::of(50, 'CZK'),
112113
'Test item',
@@ -117,7 +118,7 @@ test(function (): void {
117118
Assert::equal('acc1', $payment->toArray()['account']);
118119
});
119120

120-
test(function (): void {
121+
Toolkit::test(function (): void {
121122
$payment = Payment::of(
122123
Money::of(50, 'CZK'),
123124
'Test item',

tests/cases/Unit/Entity/RecurringPayment.phpt renamed to tests/Cases/Entity/RecurringPayment.phpt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ use Brick\Money\Money;
66
use Contributte\Comgate\Entity\Codes\CountryCode;
77
use Contributte\Comgate\Entity\Payment;
88
use Contributte\Comgate\Entity\RecurringPayment;
9+
use Contributte\Tester\Toolkit;
910
use Tester\Assert;
1011

11-
require_once __DIR__ . '/../../../bootstrap.php';
12+
require_once __DIR__ . '/../../bootstrap.php';
1213

13-
test(function (): void {
14+
Toolkit::test(function (): void {
1415
$payment = RecurringPayment::of(
1516
'123-ABC-123',
1617
Money::of(50, 'CZK'),
@@ -33,7 +34,7 @@ test(function (): void {
3334
], $payment->toArray());
3435
});
3536

36-
test(function (): void {
37+
Toolkit::test(function (): void {
3738
$payment = Payment::of(
3839
Money::of(50, 'CZK'),
3940
'Test item',
@@ -44,7 +45,7 @@ test(function (): void {
4445
Assert::equal('item101', $payment->toArray()['name']);
4546
});
4647

47-
test(function (): void {
48+
Toolkit::test(function (): void {
4849
$payment = RecurringPayment::of(
4950
'123-ABC-123',
5051
Money::of(50, 'CZK'),

tests/cases/Unit/Gateway/PaymentService.phpt renamed to tests/Cases/Gateway/PaymentService.phpt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ use Contributte\Comgate\Entity\Response\StornoResponse;
1616
use Contributte\Comgate\Entity\Storno;
1717
use Contributte\Comgate\Gateway\PaymentService;
1818
use Contributte\Comgate\Http\HttpClient;
19+
use Contributte\Tester\Toolkit;
1920
use GuzzleHttp\Client;
2021
use GuzzleHttp\Handler\MockHandler;
2122
use GuzzleHttp\HandlerStack;
2223
use GuzzleHttp\Middleware;
2324
use GuzzleHttp\Psr7\Response;
2425
use Tester\Assert;
2526

26-
require_once __DIR__ . '/../../../bootstrap.php';
27+
require_once __DIR__ . '/../../bootstrap.php';
2728

28-
test(function (): void {
29+
Toolkit::test(function (): void {
2930
$transactions = [];
3031
$mockHandler = new MockHandler();
3132
$handlerStack = HandlerStack::create(HandlerStack::create($mockHandler));
@@ -48,7 +49,7 @@ test(function (): void {
4849
Assert::equal('create', (string) $transactions[0]['request']->getUri()->getPath());
4950
});
5051

51-
test(function (): void {
52+
Toolkit::test(function (): void {
5253
$transactions = [];
5354
$mockHandler = new MockHandler();
5455
$handlerStack = HandlerStack::create(HandlerStack::create($mockHandler));
@@ -72,7 +73,7 @@ test(function (): void {
7273
Assert::equal('recurring', (string) $transactions[0]['request']->getUri()->getPath());
7374
});
7475

75-
test(function (): void {
76+
Toolkit::test(function (): void {
7677
$transactions = [];
7778
$mockHandler = new MockHandler();
7879
$handlerStack = HandlerStack::create(HandlerStack::create($mockHandler));
@@ -90,7 +91,7 @@ test(function (): void {
9091
Assert::equal('status', (string) $transactions[0]['request']->getUri()->getPath());
9192
});
9293

93-
test(function (): void {
94+
Toolkit::test(function (): void {
9495
$transactions = [];
9596
$mockHandler = new MockHandler();
9697
$handlerStack = HandlerStack::create(HandlerStack::create($mockHandler));
@@ -111,7 +112,7 @@ test(function (): void {
111112
Assert::equal('refund', (string) $transactions[0]['request']->getUri()->getPath());
112113
});
113114

114-
test(function (): void {
115+
Toolkit::test(function (): void {
115116
$transactions = [];
116117
$mockHandler = new MockHandler();
117118
$handlerStack = HandlerStack::create(HandlerStack::create($mockHandler));
@@ -129,7 +130,7 @@ test(function (): void {
129130
Assert::equal('cancel', (string) $transactions[0]['request']->getUri()->getPath());
130131
});
131132

132-
test(function (): void {
133+
Toolkit::test(function (): void {
133134
$transactions = [];
134135
$mockHandler = new MockHandler();
135136
$handlerStack = HandlerStack::create(HandlerStack::create($mockHandler));

‎tests/bootstrap.php‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?php declare(strict_types = 1);
22

3-
use Ninjify\Nunjuck\Environment;
3+
use Contributte\Tester\Environment;
44

55
if (@!include __DIR__ . '/../vendor/autoload.php') {
66
echo 'Install Nette Tester using `composer update --dev`';
77
exit(1);
88
}
99

10-
// Configure environment
11-
Environment::setupTester();
12-
Environment::setupTimezone();
13-
Environment::setupVariables(__DIR__);
10+
Environment::setup(__DIR__);

0 commit comments

Comments
 (0)