Skip to content

Commit 16f2ad8

Browse files
authored
Merge pull request #144 from bavix/l7
add support laravel 7.x
2 parents e6d4b8a + 00afdd9 commit 16f2ad8

File tree

10 files changed

+68
-22
lines changed

10 files changed

+68
-22
lines changed

.scrutinizer.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
build:
2+
dependencies:
3+
override:
4+
- composer install
5+
26
environment:
37
php:
48
version: 7.2
@@ -13,12 +17,12 @@ build:
1317
tests:
1418
override:
1519
- php-scrutinizer-run
16-
- command: 'vendor/bin/phpunit --dump-xdebug-filter xdebug-filter.php'
20+
- command: vendor/bin/phpunit --dump-xdebug-filter xdebug-filter.php
1721
-
18-
command: 'vendor/bin/phpunit --prepend xdebug-filter.php --coverage-clover=some-file'
22+
command: vendor/bin/phpunit --prepend xdebug-filter.php --coverage-clover=clover.xml
1923
coverage:
20-
file: 'some-file'
21-
format: 'clover'
24+
file: clover.xml
25+
format: php-clover
2226

2327
filter:
2428
excluded_paths: [docs/*, resources/*, tests/*, database/*, config/*]

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ language: php
22
php:
33
- '7.2'
44
- '7.3'
5-
- '7.4snapshot'
5+
- '7.4'
66
- 'nightly'
77

88
services:
99
- memcached
1010

1111
matrix:
1212
allow_failures:
13-
- php: '7.4snapshot'
1413
- php: 'nightly'
1514

1615
before_script:
@@ -19,13 +18,13 @@ before_script:
1918
- bash <(curl -s https://raw.githubusercontent.com/php-cache/cache/master/build/php/7.2/Memcached.sh)
2019
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
2120
- chmod +x ./cc-test-reporter
22-
- if [ $(phpenv version-name) = "7.3" ]; then ./cc-test-reporter before-build; fi
21+
- if [ $(phpenv version-name) = "7.4" ]; then ./cc-test-reporter before-build; fi
2322
- composer install
2423

2524
script:
2625
- ./vendor/bin/phpunit --coverage-xml=build/coverage-xml --log-junit=build/junit.xml
2726
- ./vendor/bin/infection --coverage=build --min-msi=60 -j$(nproc)
2827

2928
after_success:
30-
- if [ $(phpenv version-name) = "7.3" ]; then ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT; fi
29+
- if [ $(phpenv version-name) = "7.4" ]; then ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT; fi
3130
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ laravel-wallet - Easy work with virtual wallet.
2424
* **Package**: laravel-wallet
2525
* **Version**: [![Latest Stable Version](https://poser.pugx.org/bavix/laravel-wallet/v/stable)](https://packagist.org/packages/bavix/laravel-wallet)
2626
* **PHP Version**: 7.2+
27-
* **Laravel Version**: `5.5`, `5.6`, `5.7`, `5.8`, `6.x`
27+
* **Laravel Version**: `5.5`, `5.6`, `5.7`, `5.8`, `6.x`, `7.x`
2828
* **[Composer](https://getcomposer.org/):** `composer require bavix/laravel-wallet`
2929

3030
### Upgrade Guide

changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [4.2.0] - 2020-03-08
10+
11+
### Added
12+
- Add laravel 7 support
13+
914
## [4.1.2] - 2020-01-20
1015
### Added
1116
- add `$amountFloat` to Transaction model
@@ -448,7 +453,8 @@ The operation is now executed in the transaction and updates the new `refund` fi
448453
- Exceptions: AmountInvalid, BalanceIsEmpty.
449454
- Models: Transfer, Transaction.
450455

451-
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/4.1.2...HEAD
456+
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/4.2.0...HEAD
457+
[4.2.0]: https://github.com/bavix/laravel-wallet/compare/4.1.2...4.2.0
452458
[4.1.2]: https://github.com/bavix/laravel-wallet/compare/4.1.1...4.1.2
453459
[4.1.1]: https://github.com/bavix/laravel-wallet/compare/4.1.0...4.1.1
454460
[4.1.0]: https://github.com/bavix/laravel-wallet/compare/4.0.1...4.1.0

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"description": "Easy work with virtual wallet.",
44
"keywords": [
55
"laravel",
6-
"laravel5",
76
"laravel6",
7+
"laravel7",
88
"credits",
99
"bavix",
1010
"currency",
11-
"laravel5-package",
1211
"laravel6-package",
12+
"laravel7-package",
1313
"laravel-wallet",
1414
"virtual",
1515
"wallet",
@@ -27,17 +27,17 @@
2727
"require": {
2828
"php": "^7.2|^8.0",
2929
"ext-pdo": "*",
30-
"illuminate/database": "^5.5|^6.0",
31-
"nesbot/carbon": "^1.20|^2.0",
30+
"illuminate/database": "^6.0|^7.0",
31+
"nesbot/carbon": "^2.0",
3232
"doctrine/dbal": "^2.8",
3333
"ramsey/uuid": "^3.0"
3434
},
3535
"require-dev": {
3636
"infection/infection": "^0.15",
37-
"orchestra/testbench": "^4.5",
37+
"orchestra/testbench": "^4.0|^5.0",
3838
"phpstan/phpstan": "^0.12",
39-
"phpunit/phpunit": "^8.5",
40-
"laravel/cashier": "^7.0|^8.0|^9.0|^10.0"
39+
"phpunit/phpunit": "^8.0|^9.0",
40+
"laravel/cashier": "^10.0"
4141
},
4242
"suggest": {
4343
"bavix/laravel-wallet-swap": "Addition to the laravel-wallet library for quick setting of exchange rates",

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
</testsuite>
1616
</testsuites>
1717
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
18+
<whitelist processUncoveredFilesFromWhitelist="true">
19+
<directory suffix=".php">./src/</directory>
2020
</whitelist>
2121
</filter>
2222
<logging>

src/Models/Transaction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function setAmountFloatAttribute(float $amount): void
116116
$decimalPlaces = app(WalletService::class)
117117
->decimalPlaces($this->wallet);
118118

119-
$this->amount = $amount * $decimalPlaces;
119+
$this->amount = (int)round($amount * $decimalPlaces);
120120
}
121121

122122
}

src/Simple/Store.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public function getBalance($object): int
2020
{
2121
$wallet = app(WalletService::class)->getWallet($object);
2222
if (!\array_key_exists($wallet->getKey(), $this->balanceSheets)) {
23-
$this->balanceSheets[$wallet->getKey()] = (int)$wallet->getOriginal('balance', 0);
23+
$balance = method_exists($wallet, 'getRawOriginal') ?
24+
$wallet->getRawOriginal('balance', 0) : $wallet->getOriginal('balance', 0);
25+
26+
$this->balanceSheets[$wallet->getKey()] = (int)$balance;
2427
}
2528

2629
return $this->balanceSheets[$wallet->getKey()];

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected function getEnvironmentSetUp($app): void
109109
*/
110110
public function expectExceptionMessageStrict(string $message): void
111111
{
112-
$this->expectExceptionMessageRegExp("~^{$message}$~");
112+
$this->expectExceptionMessageMatches("~^{$message}$~");
113113
}
114114

115115
}

tests/WalletFloatTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Bavix\Wallet\Exceptions\AmountInvalid;
66
use Bavix\Wallet\Exceptions\BalanceIsEmpty;
77
use Bavix\Wallet\Models\Transaction;
8+
use Bavix\Wallet\Services\WalletService;
89
use Bavix\Wallet\Test\Models\UserFloat as User;
910

1011
class WalletFloatTest extends TestCase
@@ -227,6 +228,39 @@ public function testMantissa(): void
227228
$this->assertEquals($user->balanceFloat, 10000.00 + 2556.72);
228229
}
229230

231+
/**
232+
* @return void
233+
*/
234+
public function testUpdateTransaction(): void
235+
{
236+
/**
237+
* @var User $user
238+
*/
239+
$user = factory(User::class)->create();
240+
$this->assertEquals($user->balance, 0);
241+
242+
$user->deposit(1000000);
243+
$this->assertEquals($user->balance, 1000000);
244+
$this->assertEquals($user->balanceFloat, 10000.00);
245+
246+
$transaction = $user->withdrawFloat(2556.72);
247+
$this->assertEquals($transaction->amount, -255672);
248+
$this->assertEquals($transaction->amountFloat, -2556.72);
249+
$this->assertEquals($transaction->type, Transaction::TYPE_WITHDRAW);
250+
251+
$transaction->type = Transaction::TYPE_DEPOSIT;
252+
$transaction->amountFloat = 2556.72;
253+
$this->assertTrue($transaction->save());
254+
$this->assertTrue($user->wallet->refreshBalance());
255+
256+
$this->assertEquals($transaction->amount, 255672);
257+
$this->assertEquals($transaction->amountFloat, 2556.72);
258+
$this->assertEquals($transaction->type, Transaction::TYPE_DEPOSIT);
259+
260+
$this->assertEquals($user->balance, 1000000 + 255672);
261+
$this->assertEquals($user->balanceFloat, 10000.00 + 2556.72);
262+
}
263+
230264
/**
231265
* @return void
232266
*/

0 commit comments

Comments
 (0)