Skip to content

Commit

Permalink
Merge pull request #2 from bavix/develop
Browse files Browse the repository at this point in the history
add support new laravel-wallet
  • Loading branch information
rez1dent3 authored Mar 13, 2020
2 parents 100262d + 8b59d14 commit 2804844
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 28 deletions.
18 changes: 11 additions & 7 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
build:
dependencies:
override:
- composer install

environment:
php:
version: 7.2
Expand All @@ -12,13 +16,13 @@ build:
override: true
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=some-file'
coverage:
file: 'some-file'
format: 'clover'
- 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
coverage:
file: clover.xml
format: php-clover

filter:
excluded_paths: [tests/*]
Expand Down
22 changes: 19 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@ language: php
php:
- '7.2'
- '7.3'
- '7.4snapshot'
- '7.4'
- 'nightly'

services:
- memcached

matrix:
allow_failures:
- php: '7.4snapshot'
- php: 'nightly'

before_script:
- "composer install"
- 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
- composer install

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

after_success:
- if [ $(phpenv version-name) = "7.4" ]; then ./cc-test-reporter after-build --coverage-input-type clover --exit-code $TRAVIS_TEST_RESULT; fi
- bash <(curl -s https://codecov.io/bash)
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![Code Coverage](https://scrutinizer-ci.com/g/bavix/laravel-wallet-swap/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/bavix/laravel-wallet-swap/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/bavix/laravel-wallet-swap/badges/build.png?b=master)](https://scrutinizer-ci.com/g/bavix/laravel-wallet-swap/build-status/master)
[![Code Intelligence Status](https://scrutinizer-ci.com/g/bavix/laravel-wallet-swap/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence)
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/bavix/laravel-wallet-swap/master)](https://packagist.org/packages/bavix/laravel-wallet-swap)

[![Package Rank](https://phppackages.org/p/bavix/laravel-wallet-swap/badge/rank.svg)](https://packagist.org/packages/bavix/laravel-wallet-swap)
[![Latest Stable Version](https://poser.pugx.org/bavix/laravel-wallet-swap/v/stable)](https://packagist.org/packages/bavix/laravel-wallet-swap)
Expand All @@ -15,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.0`
* **Laravel Version**: `5.5`, `5.6`, `5.7`, `5.8`, `6.x`, `7.x`
* **[Composer](https://getcomposer.org/):** `composer require bavix/laravel-wallet-swap`

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

## [Unreleased]

## [2.0.0] - 2020-03-13

### Added
- support laravel-wallet v5.0
- More unit tests

## [1.1.0] - 2019-10-21
### Added
- support laravel-wallet v4.0
Expand All @@ -30,7 +36,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/1.1.0...HEAD
[Unreleased]: https://github.com/bavix/laravel-wallet-swap/compare/2.0.0...develop
[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
[0.0.2]: https://github.com/bavix/laravel-wallet-swap/compare/0.0.1...0.0.2
Expand Down
24 changes: 14 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"keywords": [
"swap",
"laravel",
"laravel5",
"laravel6",
"laravel7",
"credits",
"bavix",
"currency",
"laravel5-package",
"laravel6-package",
"laravel7-package",
"laravel-wallet",
"virtual",
"wallet",
Expand All @@ -27,16 +27,17 @@
],
"require": {
"php": "^7.2",
"bavix/laravel-wallet": "^4.0",
"florianv/laravel-swap": "^2.0",
"nyholm/psr7": "^1.1",
"php-http/curl-client": "^2.0",
"php-http/message": "^1.7"
"bavix/laravel-wallet": "^5.0",
"florianv/laravel-swap": "^2.1",
"nyholm/psr7": "^1.2",
"php-http/curl-client": "^2.1",
"php-http/message": "^1.8"
},
"require-dev": {
"orchestra/testbench": "^4.0",
"phpstan/phpstan": "^0.11",
"phpunit/phpunit": "^8.3"
"infection/infection": "^0.15",
"orchestra/testbench": "^4.0|^5.0",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8.0|^9.0"
},
"autoload": {
"psr-4": {
Expand All @@ -49,6 +50,9 @@
}
},
"extra": {
"branch-alias": {
"dev-develop": "2.0.x-dev"
},
"laravel": {
"providers": [
"Bavix\\WalletSwap\\RateServiceProvider"
Expand Down
17 changes: 17 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"timeout": 10,
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "build/infection.log",
"badge": {
"branch": "master"
}
},
"mutators": {
"@default": true
}
}
14 changes: 9 additions & 5 deletions src/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bavix\WalletSwap;

use Bavix\Wallet\Interfaces\Mathable;
use Bavix\Wallet\Interfaces\Wallet;
use Bavix\Wallet\Services\WalletService;
use Bavix\Wallet\Simple\Rate as Rateable;
Expand All @@ -17,9 +18,9 @@ class Rate extends Rateable
* Makes a request for an API Swap and receives data.
*
* @param Wallet $wallet
* @return float
* @return int|float
*/
public function rate(Wallet $wallet): float
public function rate(Wallet $wallet)
{
$from = app(WalletService::class)->getWallet($this->withCurrency);
$to = app(WalletService::class)->getWallet($wallet);
Expand All @@ -36,17 +37,20 @@ public function rate(Wallet $wallet): float
/**
* @var ExchangeRate $rate
*/
$rate = Swap::latest((string)$pair);
$rate = Swap::latest($pair);
return $rate->getValue();
}

/**
* @param Wallet $wallet
* @return float
*/
public function convertTo(Wallet $wallet): float
public function convertTo(Wallet $wallet)
{
return parent::convertTo($wallet) * $this->rate($wallet);
return app(Mathable::class)->mul(
parent::convertTo($wallet),
$this->rate($wallet)
);
}

}
9 changes: 8 additions & 1 deletion tests/RateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +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));

/**
* @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));
}

}

0 comments on commit 2804844

Please sign in to comment.