Skip to content

Commit

Permalink
Merge pull request #3 from bavix/develop
Browse files Browse the repository at this point in the history
add support laravel-wallet 6.x
  • Loading branch information
rez1dent3 authored Nov 13, 2020
2 parents 2804844 + 5eac4ca commit 54b694a
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 51 deletions.
8 changes: 2 additions & 6 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ build:

environment:
php:
version: 7.2
pecl_extensions:
- memcached
memcached: true
version: 7.3

nodes:
analysis:
Expand All @@ -17,9 +14,8 @@ build:
tests:
override:
- php-scrutinizer-run
- command: vendor/bin/phpunit --dump-xdebug-filter xdebug-filter.php
-
command: vendor/bin/phpunit --prepend xdebug-filter.php --coverage-clover=clover.xml
command: vendor/bin/phpunit --coverage-clover=clover.xml
coverage:
file: clover.xml
format: php-clover
Expand Down
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
language: php
php:
- '7.2'
- '7.3'
- '7.4'
- 'nightly'

services:
- memcached

matrix:
allow_failures:
- php: 'nightly'

before_script:
- pecl install pcov
- phpenv config-rm xdebug.ini || echo "xdebug not available"
- bash <(curl -s https://raw.githubusercontent.com/php-cache/cache/master/build/php/7.2/Memcached.sh)
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- if [ $(phpenv version-name) = "7.4" ]; then ./cc-test-reporter before-build; fi
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ laravel-wallet-swap - Addition to the package laravel-wallet.
* **Package**: laravel-wallet-swap
* **Version**: [![Latest Stable Version](https://poser.pugx.org/bavix/laravel-wallet-swap/v/stable)](https://packagist.org/packages/bavix/laravel-wallet-swap)
* **PHP Version**: 7.1+
* **Laravel Version**: `5.5`, `5.6`, `5.7`, `5.8`, `6.x`, `7.x`
* **Laravel Version**: `5.5`, `5.6`, `5.7`, `5.8`, `6.x`, `7.x`, `8.x`
* **[Composer](https://getcomposer.org/):** `composer require bavix/laravel-wallet-swap`

---
Expand Down
10 changes: 9 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.0.0] - 2020-11-13

### Added
- support laravel-wallet v6.0
- support php ^8.0
- More unit tests

## [2.0.0] - 2020-03-13

### Added
Expand Down Expand Up @@ -36,7 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add class provider `RateServiceProvider`.
- Add class rate for laravel-wallet `Rate`.

[Unreleased]: https://github.com/bavix/laravel-wallet-swap/compare/2.0.0...develop
[Unreleased]: https://github.com/bavix/laravel-wallet-swap/compare/3.0.0...develop
[3.0.0]: https://github.com/bavix/laravel-wallet-swap/compare/2.0.0...3.0.0
[2.0.0]: https://github.com/bavix/laravel-wallet-swap/compare/1.1.0...2.0.0
[1.1.0]: https://github.com/bavix/laravel-wallet-swap/compare/1.0.0...1.1.0
[1.0.0]: https://github.com/bavix/laravel-wallet-swap/compare/0.0.2...1.0.0
Expand Down
21 changes: 10 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"laravel",
"laravel6",
"laravel7",
"laravel8",
"credits",
"bavix",
"currency",
"laravel6-package",
"laravel7-package",
"laravel8-package",
"laravel-wallet",
"virtual",
"wallet",
Expand All @@ -26,18 +28,18 @@
}
],
"require": {
"php": "^7.2",
"bavix/laravel-wallet": "^5.0",
"florianv/laravel-swap": "^2.1",
"nyholm/psr7": "^1.2",
"php": "^7.3|^8.0",
"bavix/laravel-wallet": "^6.0",
"florianv/laravel-swap": "^2.2",
"nyholm/psr7": "^1.3",
"php-http/curl-client": "^2.1",
"php-http/message": "^1.8"
"php-http/message": "^1.9"
},
"require-dev": {
"infection/infection": "^0.15",
"orchestra/testbench": "^4.0|^5.0",
"infection/infection": "~0.17",
"orchestra/testbench": "^6.0",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8.0|^9.0"
"phpunit/phpunit": "^9.4"
},
"autoload": {
"psr-4": {
Expand All @@ -50,9 +52,6 @@
}
},
"extra": {
"branch-alias": {
"dev-develop": "2.0.x-dev"
},
"laravel": {
"providers": [
"Bavix\\WalletSwap\\RateServiceProvider"
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@
<log type="coverage-html" target="./build/html/"/>
<log type="coverage-clover" target="./build/logs/clover.xml"/>
</logging>
<php>
<env name="DB_CONNECTION" value="testing" />
</php>
</phpunit>
3 changes: 1 addition & 2 deletions src/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

class Rate extends Rateable
{

/**
* The method calculates the rate between currencies.
* Makes a request for an API Swap and receives data.
Expand All @@ -38,6 +37,7 @@ public function rate(Wallet $wallet)
* @var ExchangeRate $rate
*/
$rate = Swap::latest($pair);

return $rate->getValue();
}

Expand All @@ -52,5 +52,4 @@ public function convertTo(Wallet $wallet)
$this->rate($wallet)
);
}

}
6 changes: 2 additions & 4 deletions src/RateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace Bavix\WalletSwap;

use Illuminate\Support\ServiceProvider;
use Bavix\Wallet\Interfaces\Rateable;
use Illuminate\Support\ServiceProvider;

class RateServiceProvider extends ServiceProvider
{

/**
* Bootstrap services.
*
Expand All @@ -16,11 +15,10 @@ class RateServiceProvider extends ServiceProvider
*/
public function boot(): void
{
if (!$this->app->runningInConsole()) {
if (! $this->app->runningInConsole()) {
return;
}

$this->app->singleton(Rateable::class, Rate::class);
}

}
18 changes: 9 additions & 9 deletions tests/RateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Bavix\WalletSwap\Test;

use Bavix\Wallet\Interfaces\Mathable;
use Bavix\Wallet\Models\Wallet;
use Bavix\WalletSwap\Rate;
use Exchanger\ExchangeRate;
use Swap\Laravel\Facades\Swap;

class RateTest extends TestCase
{

/**
* @return void
*/
Expand All @@ -36,7 +36,7 @@ public function testSimple(): void
*/
$expected = Swap::latest('USD/EUR');

$this->assertEquals($expected->getValue() * 99, $rate->convertTo($eur));
self::assertEquals($expected->getValue() * 99, $rate->convertTo($eur));
}

/**
Expand All @@ -54,7 +54,7 @@ public function testIdentical(): void
->withCurrency($usd)
->withAmount(128);

$this->assertEquals(128, $rate->convertTo($usd));
self::assertEquals(128, $rate->convertTo($usd));
}

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ public function testCryptoBTCUSD(): void
*/
$expected = Swap::latest('BTC/USD');

$this->assertEquals($expected->getValue() * 20, $rate->convertTo($usd));
self::assertEquals($expected->getValue() * 20, $rate->convertTo($usd));
}

/**
Expand Down Expand Up @@ -111,15 +111,15 @@ public function testCryptoUSDBTC(): void
* @var ExchangeRate $expected
*/
$expected = Swap::latest('USD/BTC');
$this->assertEquals($expected->getValue() * 100, $rate->convertTo($btc));
$this->assertEquals($expected->getValue(), $rate->rate($btc));
self::assertEquals($expected->getValue() * 100, $rate->convertTo($btc));
self::assertEquals($expected->getValue(), $rate->rate($btc));

/**
* @var ExchangeRate $expected
*/
$expected = Swap::latest('BTC/USD');
$this->assertEquals($expected->getValue() * 100, $rate->withCurrency($btc)->convertTo($usd));
$this->assertEquals($expected->getValue(), $rate->withCurrency($btc)->rate($usd));
$expectedValue = app(Mathable::class)->mul($expected->getValue(), 100);
self::assertEquals($expectedValue, $rate->withCurrency($btc)->convertTo($usd));
self::assertEquals($expected->getValue(), $rate->withCurrency($btc)->rate($usd));
}

}
14 changes: 2 additions & 12 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

use Bavix\Wallet\WalletServiceProvider;
use Bavix\WalletSwap\RateServiceProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use Illuminate\Foundation\Application;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use Swap\Laravel\SwapServiceProvider;

class TestCase extends OrchestraTestCase
{

/**
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->artisan('migrate', ['--database' => 'testbench'])->run();
$this->artisan('migrate')->run();
}

/**
Expand Down Expand Up @@ -49,14 +48,5 @@ protected function getEnvironmentSetUp($app): void
'russian_central_bank' => true,
'cryptonator' => true,
]);

// database
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}

}

0 comments on commit 54b694a

Please sign in to comment.