-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrey Helldar
committed
Jul 23, 2021
1 parent
7e4d8ff
commit dcf26f5
Showing
9 changed files
with
413 additions
and
2 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
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 Tests\Fixtures\Models; | ||
|
||
use Helldar\CashierDriver\Tinkoff\QrCode\Resources\Response; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Tests\TestCase; | ||
|
||
/** | ||
* @property-read string $payment_id | ||
* @property-read Response $details | ||
*/ | ||
class CashierDetail extends Model | ||
{ | ||
protected function getPaymentIdAttribute(): string | ||
{ | ||
return TestCase::PAYMENT_ID; | ||
} | ||
|
||
protected function getDetailsAttribute(): Response | ||
{ | ||
return Response::make([ | ||
Response::KEY_PAYMENT_ID => TestCase::PAYMENT_ID, | ||
Response::KEY_STATUS => TestCase::STATUS, | ||
], false); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Tests\Fixtures\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @property-read \Tests\Fixtures\Models\CashierDetail $cashier | ||
*/ | ||
class Payment extends Model | ||
{ | ||
public function getCashierAttribute(): CashierDetail | ||
{ | ||
return new CashierDetail(); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Tests\Fixtures\Requests; | ||
|
||
use Carbon\Carbon; | ||
use Helldar\Cashier\Constants\Currency; | ||
use Helldar\CashierDriver\Tinkoff\QrCode\Resources\Request as BaseRequest; | ||
use Tests\TestCase; | ||
|
||
class Request extends BaseRequest | ||
{ | ||
protected function paymentId(): string | ||
{ | ||
return TestCase::PAYMENT_ID; | ||
} | ||
|
||
protected function sum(): float | ||
{ | ||
return TestCase::PAYMENT_SUM; | ||
} | ||
|
||
protected function currency(): int | ||
{ | ||
return Currency::RUB; | ||
} | ||
|
||
protected function createdAt(): Carbon | ||
{ | ||
return Carbon::parse(TestCase::PAYMENT_DATE); | ||
} | ||
} |
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,169 @@ | ||
<?php | ||
|
||
namespace Tests\Helpers; | ||
|
||
use Helldar\CashierDriver\Tinkoff\QrCode\Helpers\Statuses; | ||
use Tests\TestCase; | ||
|
||
final class StatusesTest extends TestCase | ||
{ | ||
public function testModel() | ||
{ | ||
$this->assertTrue($this->statuses()->hasCreated()); | ||
$this->assertTrue($this->statuses()->inProgress()); | ||
|
||
$this->assertFalse($this->statuses()->hasSuccess()); | ||
$this->assertFalse($this->statuses()->hasFailed()); | ||
$this->assertFalse($this->statuses()->hasRefunding()); | ||
$this->assertFalse($this->statuses()->hasRefunded()); | ||
} | ||
|
||
public function testHasCreated() | ||
{ | ||
$this->assertTrue($this->statuses()->hasCreated('FORM_SHOWED')); | ||
$this->assertTrue($this->statuses()->hasCreated('NEW')); | ||
|
||
$this->assertFalse($this->statuses()->hasCreated('AUTHORIZED')); | ||
$this->assertFalse($this->statuses()->hasCreated('AUTHORIZING')); | ||
$this->assertFalse($this->statuses()->hasCreated('CONFIRMING')); | ||
$this->assertFalse($this->statuses()->hasCreated('REFUNDING')); | ||
|
||
$this->assertFalse($this->statuses()->hasCreated('PARTIAL_REFUNDED')); | ||
$this->assertFalse($this->statuses()->hasCreated('REFUNDED')); | ||
$this->assertFalse($this->statuses()->hasCreated('REVERSED')); | ||
|
||
$this->assertFalse($this->statuses()->hasCreated('ATTEMPTS_EXPIRED')); | ||
$this->assertFalse($this->statuses()->hasCreated('CANCELED')); | ||
$this->assertFalse($this->statuses()->hasCreated('DEADLINE_EXPIRED')); | ||
$this->assertFalse($this->statuses()->hasCreated('REJECTED')); | ||
|
||
$this->assertFalse($this->statuses()->hasCreated('CONFIRMED')); | ||
|
||
$this->assertFalse($this->statuses()->hasCreated('UNKNOWN')); | ||
} | ||
|
||
public function testHasSuccess() | ||
{ | ||
$this->assertFalse($this->statuses()->hasSuccess('FORM_SHOWED')); | ||
$this->assertFalse($this->statuses()->hasSuccess('NEW')); | ||
|
||
$this->assertFalse($this->statuses()->hasSuccess('AUTHORIZED')); | ||
$this->assertFalse($this->statuses()->hasSuccess('AUTHORIZING')); | ||
$this->assertFalse($this->statuses()->hasSuccess('CONFIRMING')); | ||
$this->assertFalse($this->statuses()->hasSuccess('REFUNDING')); | ||
|
||
$this->assertFalse($this->statuses()->hasSuccess('PARTIAL_REFUNDED')); | ||
$this->assertFalse($this->statuses()->hasSuccess('REFUNDED')); | ||
$this->assertFalse($this->statuses()->hasSuccess('REVERSED')); | ||
|
||
$this->assertFalse($this->statuses()->hasSuccess('ATTEMPTS_EXPIRED')); | ||
$this->assertFalse($this->statuses()->hasSuccess('CANCELED')); | ||
$this->assertFalse($this->statuses()->hasSuccess('DEADLINE_EXPIRED')); | ||
$this->assertFalse($this->statuses()->hasSuccess('REJECTED')); | ||
|
||
$this->assertTrue($this->statuses()->hasSuccess('CONFIRMED')); | ||
|
||
$this->assertFalse($this->statuses()->hasSuccess('UNKNOWN')); | ||
} | ||
|
||
public function testHasFailed() | ||
{ | ||
$this->assertFalse($this->statuses()->hasFailed('FORM_SHOWED')); | ||
$this->assertFalse($this->statuses()->hasFailed('NEW')); | ||
|
||
$this->assertFalse($this->statuses()->hasFailed('AUTHORIZED')); | ||
$this->assertFalse($this->statuses()->hasFailed('AUTHORIZING')); | ||
$this->assertFalse($this->statuses()->hasFailed('CONFIRMING')); | ||
$this->assertFalse($this->statuses()->hasFailed('REFUNDING')); | ||
|
||
$this->assertFalse($this->statuses()->hasFailed('PARTIAL_REFUNDED')); | ||
$this->assertFalse($this->statuses()->hasFailed('REFUNDED')); | ||
$this->assertFalse($this->statuses()->hasFailed('REVERSED')); | ||
|
||
$this->assertTrue($this->statuses()->hasFailed('ATTEMPTS_EXPIRED')); | ||
$this->assertTrue($this->statuses()->hasFailed('CANCELED')); | ||
$this->assertTrue($this->statuses()->hasFailed('DEADLINE_EXPIRED')); | ||
$this->assertTrue($this->statuses()->hasFailed('REJECTED')); | ||
|
||
$this->assertFalse($this->statuses()->hasFailed('CONFIRMED')); | ||
|
||
$this->assertFalse($this->statuses()->hasFailed('UNKNOWN')); | ||
} | ||
|
||
public function testHasRefunding() | ||
{ | ||
$this->assertFalse($this->statuses()->hasRefunding('FORM_SHOWED')); | ||
$this->assertFalse($this->statuses()->hasRefunding('NEW')); | ||
|
||
$this->assertTrue($this->statuses()->hasRefunding('AUTHORIZED')); | ||
$this->assertTrue($this->statuses()->hasRefunding('AUTHORIZING')); | ||
$this->assertTrue($this->statuses()->hasRefunding('CONFIRMING')); | ||
$this->assertTrue($this->statuses()->hasRefunding('REFUNDING')); | ||
|
||
$this->assertFalse($this->statuses()->hasRefunding('PARTIAL_REFUNDED')); | ||
$this->assertFalse($this->statuses()->hasRefunding('REFUNDED')); | ||
$this->assertFalse($this->statuses()->hasRefunding('REVERSED')); | ||
|
||
$this->assertFalse($this->statuses()->hasRefunding('ATTEMPTS_EXPIRED')); | ||
$this->assertFalse($this->statuses()->hasRefunding('CANCELED')); | ||
$this->assertFalse($this->statuses()->hasRefunding('DEADLINE_EXPIRED')); | ||
$this->assertFalse($this->statuses()->hasRefunding('REJECTED')); | ||
|
||
$this->assertFalse($this->statuses()->hasRefunding('CONFIRMED')); | ||
|
||
$this->assertFalse($this->statuses()->hasRefunding('UNKNOWN')); | ||
} | ||
|
||
public function testHasRefunded() | ||
{ | ||
$this->assertFalse($this->statuses()->hasRefunded('FORM_SHOWED')); | ||
$this->assertFalse($this->statuses()->hasRefunded('NEW')); | ||
|
||
$this->assertFalse($this->statuses()->hasRefunded('AUTHORIZED')); | ||
$this->assertFalse($this->statuses()->hasRefunded('AUTHORIZING')); | ||
$this->assertFalse($this->statuses()->hasRefunded('CONFIRMING')); | ||
$this->assertFalse($this->statuses()->hasRefunded('REFUNDING')); | ||
|
||
$this->assertTrue($this->statuses()->hasRefunded('PARTIAL_REFUNDED')); | ||
$this->assertTrue($this->statuses()->hasRefunded('REFUNDED')); | ||
$this->assertTrue($this->statuses()->hasRefunded('REVERSED')); | ||
|
||
$this->assertFalse($this->statuses()->hasRefunded('ATTEMPTS_EXPIRED')); | ||
$this->assertFalse($this->statuses()->hasRefunded('CANCELED')); | ||
$this->assertFalse($this->statuses()->hasRefunded('DEADLINE_EXPIRED')); | ||
$this->assertFalse($this->statuses()->hasRefunded('REJECTED')); | ||
|
||
$this->assertFalse($this->statuses()->hasRefunded('CONFIRMED')); | ||
|
||
$this->assertFalse($this->statuses()->hasRefunded('UNKNOWN')); | ||
} | ||
|
||
public function testInProgress() | ||
{ | ||
$this->assertTrue($this->statuses()->inProgress('FORM_SHOWED')); | ||
$this->assertTrue($this->statuses()->inProgress('NEW')); | ||
|
||
$this->assertTrue($this->statuses()->inProgress('AUTHORIZED')); | ||
$this->assertTrue($this->statuses()->inProgress('AUTHORIZING')); | ||
$this->assertTrue($this->statuses()->inProgress('CONFIRMING')); | ||
$this->assertTrue($this->statuses()->inProgress('REFUNDING')); | ||
|
||
$this->assertFalse($this->statuses()->inProgress('PARTIAL_REFUNDED')); | ||
$this->assertFalse($this->statuses()->inProgress('REFUNDED')); | ||
$this->assertFalse($this->statuses()->inProgress('REVERSED')); | ||
|
||
$this->assertFalse($this->statuses()->inProgress('ATTEMPTS_EXPIRED')); | ||
$this->assertFalse($this->statuses()->inProgress('CANCELED')); | ||
$this->assertFalse($this->statuses()->inProgress('DEADLINE_EXPIRED')); | ||
$this->assertFalse($this->statuses()->inProgress('REJECTED')); | ||
|
||
$this->assertFalse($this->statuses()->inProgress('CONFIRMED')); | ||
|
||
$this->assertTrue($this->statuses()->inProgress('UNKNOWN')); | ||
} | ||
|
||
protected function statuses(): Statuses | ||
{ | ||
return Statuses::make()->model($this->model()); | ||
} | ||
} |
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,80 @@ | ||
<?php | ||
|
||
namespace Tests\Resources; | ||
|
||
use Helldar\Cashier\Constants\Currency; | ||
use Tests\Fixtures\Requests\Request; | ||
use Tests\TestCase; | ||
|
||
class RequestTest extends TestCase | ||
{ | ||
public function testParams() | ||
{ | ||
$this->assertSame(TestCase::PAYMENT_ID, $this->request()->getPaymentId()); | ||
$this->assertSame(TestCase::PAYMENT_SUM_FORMATTED, $this->request()->getSum()); | ||
$this->assertSame((string) Currency::RUB, $this->request()->getCurrency()); | ||
} | ||
|
||
public function testCreatedAt() | ||
{ | ||
$this->assertSame(TestCase::PAYMENT_DATE_FORMATTED, $this->request()->getCreatedAt()); | ||
|
||
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/', $this->request()->getCreatedAt()); | ||
} | ||
|
||
public function testNow() | ||
{ | ||
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/', $this->request()->getCreatedAt()); | ||
$this->assertMatchesRegularExpression('/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/', $this->request()->getCreatedAt()); | ||
} | ||
|
||
public function testUniqueId() | ||
{ | ||
$request = $this->request(); | ||
|
||
$this->assertMatchesRegularExpression('/^(([0-9]|[a-f]|[A-F]){32})$/', $request->getUniqueId()); | ||
$this->assertMatchesRegularExpression('/^(([0-9]|[a-f]|[A-F]){32})$/', $request->getUniqueId()); | ||
} | ||
|
||
public function testSameUniqueId() | ||
{ | ||
$request = $this->request(); | ||
|
||
$unique_id = $request->getUniqueId(); | ||
|
||
$this->assertSame($unique_id, $request->getUniqueId()); | ||
$this->assertSame($unique_id, $request->getUniqueId()); | ||
} | ||
|
||
public function testRandomUniqueId() | ||
{ | ||
$request = $this->request(); | ||
|
||
$unique_id = $request->getUniqueId(); | ||
|
||
$this->assertSame($unique_id, $request->getUniqueId()); | ||
$this->assertSame($unique_id, $request->getUniqueId()); | ||
|
||
$this->assertNotSame($unique_id, $request->getUniqueId(true)); | ||
$this->assertNotSame($unique_id, $request->getUniqueId(true)); | ||
$this->assertNotSame($unique_id, $request->getUniqueId()); | ||
} | ||
|
||
public function testToArray() | ||
{ | ||
$expected = [ | ||
'OrderId' => TestCase::PAYMENT_ID, | ||
|
||
'Amount' => TestCase::PAYMENT_SUM_FORMATTED, | ||
|
||
'Currency' => (string) Currency::RUB, | ||
]; | ||
|
||
$this->assertSame($expected, $this->request()->toArray()); | ||
} | ||
|
||
protected function request(): Request | ||
{ | ||
return Request::make($this->model()); | ||
} | ||
} |
Oops, something went wrong.