Skip to content

Commit ab7804e

Browse files
committed
first unit-tests
1 parent 762883e commit ab7804e

21 files changed

+482
-17
lines changed

composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@
1414
"php": "^7.1",
1515
"laravel/framework": "~5.5.0|~5.6.0|~5.7.0"
1616
},
17+
"require-dev": {
18+
"doctrine/dbal": "^2.8",
19+
"mockery/mockery": "^1.2",
20+
"orchestra/testbench": "^3.7",
21+
"phpunit/phpunit": "^7.4"
22+
},
1723
"autoload": {
1824
"psr-4": {
1925
"Bavix\\Wallet\\": "src/"
2026
}
2127
},
28+
"autoload-dev": {
29+
"psr-4": {
30+
"Bavix\\Wallet\\Test\\": "tests/"
31+
}
32+
},
2233
"extra": {
2334
"laravel": {
2435
"providers": [

database/migrations/2018_11_07_202152_update_transfers_table.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3+
use Illuminate\Support\Facades\DB;
34
use Illuminate\Support\Facades\Schema;
45
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Database\SQLiteConnection;
57
use Illuminate\Database\Migrations\Migration;
68
use Bavix\Wallet\Models\Transfer;
79

@@ -38,9 +40,12 @@ public function up(): void
3840
public function down(): void
3941
{
4042
Schema::table($this->table(), function(Blueprint $table) {
41-
$table->dropIndex('from_to_refund_ind');
42-
$table->dropIndex('from_refund_ind');
43-
$table->dropIndex('to_refund_ind');
43+
if (!(DB::connection() instanceof SQLiteConnection)) {
44+
$table->dropIndex('from_to_refund_ind');
45+
$table->dropIndex('from_refund_ind');
46+
$table->dropIndex('to_refund_ind');
47+
}
48+
4449
$table->dropColumn('refund');
4550
});
4651
}

phpunit.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Wallet Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

src/Exceptions/AmountInvalid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class AmountInvalid extends \InvalidArgumentException
66
{
7-
7+
88
}

src/Exceptions/BalanceIsEmpty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class BalanceIsEmpty extends \LogicException
66
{
7-
7+
88
}

src/Exceptions/ProductEnded.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class ProductEnded extends \LogicException
66
{
7-
7+
88
}

src/Interfaces/Customer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ interface Customer extends Wallet
1010
/**
1111
* @param Product $product
1212
* @return Transfer
13-
* @throws
13+
* @throws
1414
*/
1515
public function pay(Product $product): Transfer;
1616

1717
/**
1818
* @param Product $product
1919
* @return null|Transfer
20-
* @throws
20+
* @throws
2121
*/
2222
public function safePay(Product $product): ?Transfer;
2323

@@ -30,7 +30,7 @@ public function paid(Product $product): ?Transfer;
3030
/**
3131
* @param Product $product
3232
* @return bool
33-
* @throws
33+
* @throws
3434
*/
3535
public function refund(Product $product): bool;
3636

src/Interfaces/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ public function getAmountProduct(): int;
2121
* @return array
2222
*/
2323
public function getMetaProduct(): ?array;
24-
24+
2525
}

src/Interfaces/Wallet.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Bavix\Wallet\Models\Transfer;
77
use Illuminate\Database\Eloquent\Relations\MorphMany;
88

9-
interface Wallet
9+
interface Wallet
1010
{
1111
/**
1212
* @param int $amount
@@ -55,7 +55,7 @@ public function safeTransfer(self $wallet, int $amount, ?array $meta = null): ?T
5555
* @return Transfer
5656
*/
5757
public function forceTransfer(Wallet $wallet, int $amount, ?array $meta = null): Transfer;
58-
58+
5959
/**
6060
* @param int $amount
6161
* @return bool

src/Traits/CanBePaid.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ trait CanBePaid
1717
/**
1818
* @param Product $product
1919
* @return Transfer
20-
* @throws
20+
* @throws
2121
*/
2222
public function pay(Product $product): Transfer
2323
{
@@ -72,7 +72,7 @@ public function refund(Product $product): bool
7272
->setModel($this->transfers()->getMorphClass());
7373
}
7474

75-
return DB::transaction(function() use ($product, $transfer) {
75+
return DB::transaction(function () use ($product, $transfer) {
7676
$product->transfer($this, $product->getAmountProduct(), $product->getMetaProduct());
7777
return $transfer->update(['refund' => 1]);
7878
});

0 commit comments

Comments
 (0)