Skip to content

Commit 4a597d7

Browse files
committed
Added check for messages in exceptions
1 parent 5ef5c1a commit 4a597d7

File tree

11 files changed

+37
-3
lines changed

11 files changed

+37
-3
lines changed

tests/BalanceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Bavix\Wallet\Test\Models\Buyer;
1111
use Bavix\Wallet\Test\Models\UserMulti;
1212
use Illuminate\Support\Facades\DB;
13-
use PHPUnit\Framework\MockObject\MockObject;
1413
use PDOException;
14+
use PHPUnit\Framework\MockObject\MockObject;
1515
use function app;
1616

1717
class BalanceTest extends TestCase
@@ -111,8 +111,8 @@ public function testSimple(): void
111111

112112
/**
113113
* @return void
114-
* @deprecated
115114
* @throws
115+
* @deprecated
116116
*/
117117
public function testGetBalance(): void
118118
{

tests/ConfirmTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function testForce(): void
8282
public function testConfirmedInvalid(): void
8383
{
8484
$this->expectException(ConfirmedInvalid::class);
85+
$this->expectExceptionMessageStrict(trans('wallet::errors.confirmed_invalid'));
8586

8687
/**
8788
* @var Buyer $buyer
@@ -104,6 +105,7 @@ public function testConfirmedInvalid(): void
104105
public function testWalletOwnerInvalid(): void
105106
{
106107
$this->expectException(WalletOwnerInvalid::class);
108+
$this->expectExceptionMessageStrict(trans('wallet::errors.owner_invalid'));
107109

108110
/**
109111
* @var Buyer $first

tests/DiscountTaxTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public function testForceRefund(): void
201201
public function testOutOfStock(): void
202202
{
203203
$this->expectException(ProductEnded::class);
204+
$this->expectExceptionMessageStrict(trans('wallet::errors.product_stock'));
204205

205206
/**
206207
* @var Buyer $buyer
@@ -311,6 +312,7 @@ public function testFreePay(): void
311312
public function testPayFreeOutOfStock(): void
312313
{
313314
$this->expectException(ProductEnded::class);
315+
$this->expectExceptionMessageStrict(trans('wallet::errors.product_stock'));
314316

315317
/**
316318
* @var Buyer $buyer

tests/DiscountTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public function testForceRefund(): void
180180
public function testOutOfStock(): void
181181
{
182182
$this->expectException(ProductEnded::class);
183+
$this->expectExceptionMessageStrict(trans('wallet::errors.product_stock'));
183184

184185
/**
185186
* @var Buyer $buyer
@@ -280,6 +281,7 @@ public function testFreePay(): void
280281
public function testPayFreeOutOfStock(): void
281282
{
282283
$this->expectException(ProductEnded::class);
284+
$this->expectExceptionMessageStrict(trans('wallet::errors.product_stock'));
283285

284286
/**
285287
* @var Buyer $buyer

tests/MultiWalletTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function testDeposit(): void
7878
public function testInvalidDeposit(): void
7979
{
8080
$this->expectException(AmountInvalid::class);
81+
$this->expectExceptionMessageStrict(trans('wallet::errors.price_positive'));
8182

8283
/**
8384
* @var UserMulti $user
@@ -96,6 +97,7 @@ public function testInvalidDeposit(): void
9697
public function testWithdraw(): void
9798
{
9899
$this->expectException(BalanceIsEmpty::class);
100+
$this->expectExceptionMessageStrict(trans('wallet::errors.wallet_empty'));
99101

100102
/**
101103
* @var UserMulti $user
@@ -128,6 +130,7 @@ public function testWithdraw(): void
128130
public function testInvalidWithdraw(): void
129131
{
130132
$this->expectException(BalanceIsEmpty::class);
133+
$this->expectExceptionMessageStrict(trans('wallet::errors.wallet_empty'));
131134

132135
/**
133136
* @var UserMulti $user
@@ -235,6 +238,7 @@ public function testTransferYourself(): void
235238
public function testBalanceIsEmpty(): void
236239
{
237240
$this->expectException(BalanceIsEmpty::class);
241+
$this->expectExceptionMessageStrict(trans('wallet::errors.wallet_empty'));
238242

239243
/**
240244
* @var UserMulti $user

tests/ProductTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function testForceRefund(): void
153153
public function testOutOfStock(): void
154154
{
155155
$this->expectException(ProductEnded::class);
156+
$this->expectExceptionMessageStrict(trans('wallet::errors.product_stock'));
156157

157158
/**
158159
* @var Buyer $buyer
@@ -251,6 +252,7 @@ public function testFreePay(): void
251252
public function testPayFreeOutOfStock(): void
252253
{
253254
$this->expectException(ProductEnded::class);
255+
$this->expectExceptionMessageStrict(trans('wallet::errors.product_stock'));
254256

255257
/**
256258
* @var Buyer $buyer

tests/TaxTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function testGift(): void
109109
public function testGiftFail(): void
110110
{
111111
$this->expectException(InsufficientFunds::class);
112+
$this->expectExceptionMessageStrict(trans('wallet::errors.insufficient_funds'));
112113

113114
/**
114115
* @var Buyer $santa

tests/TestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,12 @@ protected function getEnvironmentSetUp($app): void
104104
]);
105105
}
106106

107+
/**
108+
* @param string $message
109+
*/
110+
public function expectExceptionMessageStrict(string $message): void
111+
{
112+
$this->expectExceptionMessageRegExp("~^{$message}$~");
113+
}
114+
107115
}

tests/WalletExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Bavix\Wallet\Test;
44

5-
use Bavix\Wallet\Test\Objects;
65
use Bavix\Wallet\Objects\Operation;
76
use Bavix\Wallet\Test\Common\Models\Transaction;
87
use Bavix\Wallet\Test\Models\Buyer;
8+
use Bavix\Wallet\Test\Objects;
99

1010
class WalletExtensionTest extends TestCase
1111
{

tests/WalletFloatTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function testDeposit(): void
4444
public function testInvalidDeposit(): void
4545
{
4646
$this->expectException(AmountInvalid::class);
47+
$this->expectExceptionMessageStrict(trans('wallet::errors.price_positive'));
4748
$user = factory(User::class)->create();
4849
$user->depositFloat(-1);
4950
}
@@ -54,6 +55,7 @@ public function testInvalidDeposit(): void
5455
public function testWithdraw(): void
5556
{
5657
$this->expectException(BalanceIsEmpty::class);
58+
$this->expectExceptionMessageStrict(trans('wallet::errors.wallet_empty'));
5759

5860
$user = factory(User::class)->create();
5961
$this->assertEquals($user->balance, 0);
@@ -79,6 +81,7 @@ public function testWithdraw(): void
7981
public function testInvalidWithdraw(): void
8082
{
8183
$this->expectException(BalanceIsEmpty::class);
84+
$this->expectExceptionMessageStrict(trans('wallet::errors.wallet_empty'));
8285
$user = factory(User::class)->create();
8386
$user->withdrawFloat(-1);
8487
}
@@ -156,6 +159,7 @@ public function testTransferYourself(): void
156159
public function testBalanceIsEmpty(): void
157160
{
158161
$this->expectException(BalanceIsEmpty::class);
162+
$this->expectExceptionMessageStrict(trans('wallet::errors.wallet_empty'));
159163

160164
/**
161165
* @var User $user

0 commit comments

Comments
 (0)