-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from bavix/dev
Version 1.2.0
- Loading branch information
Showing
25 changed files
with
598 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ composer.phar | |
/vendor/ | ||
composer.lock | ||
.idea/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
build: | ||
|
||
environment: | ||
php: | ||
version: 7.1 | ||
|
||
nodes: | ||
analysis: | ||
project_setup: | ||
override: true | ||
tests: | ||
override: | ||
- php-scrutinizer-run | ||
- | ||
command: 'vendor/bin/phpunit --coverage-clover=some-file' | ||
coverage: | ||
file: 'some-file' | ||
format: 'clover' | ||
|
||
filter: | ||
excluded_paths: [tests/*, database/*, config/*] | ||
|
||
checks: | ||
|
||
php: | ||
remove_extra_empty_lines: true | ||
remove_php_closing_tag: true | ||
remove_trailing_whitespace: true | ||
|
||
fix_use_statements: | ||
remove_unused: true | ||
preserve_multiple: false | ||
preserve_blanklines: true | ||
order_alphabetically: true | ||
|
||
fix_php_opening_tag: true | ||
fix_linefeed: true | ||
fix_line_ending: true | ||
fix_identation_4spaces: true | ||
fix_doc_comments: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: php | ||
php: | ||
- '7.1' | ||
- '7.2' | ||
|
||
before_script: | ||
- "composer install" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Wallet Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-html" target="./build/html/"/> | ||
<log type="coverage-clover" target="./build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
|
||
class AmountInvalid extends \InvalidArgumentException | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
|
||
class BalanceIsEmpty extends \LogicException | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
|
||
class ProductEnded extends \LogicException | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,5 @@ public function getAmountProduct(): int; | |
* @return array | ||
*/ | ||
public function getMetaProduct(): ?array; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Bavix\Wallet\Test\Models; | ||
|
||
use Bavix\Wallet\Traits\CanBePaid; | ||
use Bavix\Wallet\Interfaces\Customer; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* Class User | ||
* | ||
* @package Bavix\Wallet\Test\Models | ||
* @property string $name | ||
* @property string $email | ||
*/ | ||
class Buyer extends Model implements Customer | ||
{ | ||
use CanBePaid; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTable(): string | ||
{ | ||
return 'users'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Bavix\Wallet\Test\Models; | ||
|
||
use Bavix\Wallet\Interfaces\Customer; | ||
use Bavix\Wallet\Interfaces\Product; | ||
use Bavix\Wallet\Traits\HasWallet; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* Class Item | ||
* | ||
* @package Bavix\Wallet\Test\Models | ||
* @property string $name | ||
* @property int $quantity | ||
* @property int $price | ||
*/ | ||
class Item extends Model implements Product | ||
{ | ||
|
||
use HasWallet; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $fillable = ['name', 'quantity', 'price']; | ||
|
||
/** | ||
* @param Customer $customer | ||
* | ||
* @return bool | ||
*/ | ||
public function canBuy(Customer $customer): bool | ||
{ | ||
return $this->quantity > 0 && !$customer->paid($this); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getAmountProduct(): int | ||
{ | ||
return $this->price; | ||
} | ||
|
||
/** | ||
* @return array|null | ||
*/ | ||
public function getMetaProduct(): ?array | ||
{ | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Bavix\Wallet\Test\Models; | ||
|
||
use Bavix\Wallet\Traits\HasWallet; | ||
use Bavix\Wallet\Interfaces\Wallet; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* Class User | ||
* | ||
* @package Bavix\Wallet\Test\Models | ||
* @property string $name | ||
* @property string $email | ||
*/ | ||
class User extends Model implements Wallet | ||
{ | ||
use HasWallet; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $fillable = ['name', 'email']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Bavix\Wallet\Test; | ||
|
||
use Bavix\Wallet\Test\Models\Buyer; | ||
use Bavix\Wallet\Test\Models\Item; | ||
|
||
class ProductTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testPay(): void | ||
{ | ||
$buyer = factory(Buyer::class)->create(); | ||
$product = factory(Item::class)->create([ | ||
'quantity' => 1, | ||
]); | ||
|
||
$this->assertEquals($buyer->balance, 0); | ||
$buyer->deposit($product->price); | ||
|
||
$this->assertEquals($buyer->balance, $product->price); | ||
$this->assertNotNull($buyer->pay($product)); | ||
|
||
$this->assertEquals($buyer->balance, 0); | ||
$this->assertNull($buyer->safePay($product)); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testRefund(): void | ||
{ | ||
$buyer = factory(Buyer::class)->create(); | ||
$product = factory(Item::class)->create([ | ||
'quantity' => 1, | ||
]); | ||
|
||
$this->assertEquals($buyer->balance, 0); | ||
$buyer->deposit($product->price); | ||
|
||
$this->assertEquals($buyer->balance, $product->price); | ||
$this->assertNotNull($buyer->pay($product)); | ||
|
||
$this->assertTrue($buyer->refund($product)); | ||
$this->assertEquals($buyer->balance, $product->price); | ||
|
||
$this->assertFalse($buyer->safeRefund($product)); | ||
$this->assertEquals($buyer->balance, $product->price); | ||
|
||
$this->assertNotNull($buyer->pay($product)); | ||
$this->assertEquals($buyer->balance, 0); | ||
} | ||
|
||
} |
Oops, something went wrong.