-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
6 changed files
with
118 additions
and
11 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
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,22 @@ | ||
<?php | ||
|
||
namespace Payavel\Checkout\Tests\Models; | ||
|
||
use Payavel\Checkout\Models\Dispute; | ||
|
||
class TestDispute extends Dispute | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'disputes'; | ||
|
||
/** | ||
* Check if model is overridden for testing purposes. | ||
* | ||
* @var bool | ||
*/ | ||
public bool $overridden = 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,23 @@ | ||
<?php | ||
|
||
namespace Payavel\Checkout\Tests\Models; | ||
|
||
use Payavel\Checkout\Models\Refund; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
class TestRefund extends Refund | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'refunds'; | ||
|
||
/** | ||
* Check if model is overridden for testing purposes. | ||
* | ||
* @var bool | ||
*/ | ||
public bool $overridden = 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,50 @@ | ||
<?php | ||
|
||
namespace Payavel\Checkout\Tests\Unit; | ||
|
||
use Payavel\Checkout\Models\Dispute; | ||
use Payavel\Checkout\Models\Payment; | ||
use Payavel\Checkout\Models\Refund; | ||
use Payavel\Checkout\Models\TransactionEvent; | ||
use Payavel\Checkout\Tests\Models\TestDispute; | ||
use Payavel\Checkout\Tests\Models\TestPayment; | ||
use Payavel\Checkout\Tests\Models\TestRefund; | ||
use Payavel\Checkout\Tests\TestCase; | ||
use Payavel\Orchestration\Support\ServiceConfig; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
class TransactionEventModelTest extends TestCase | ||
{ | ||
#[Test] | ||
public function retrieve_transaction_event_payment() | ||
{ | ||
$transactionEventWithPayment = TransactionEvent::factory()->create(); | ||
$this->assertInstanceOf(Payment::class, $transactionEventWithPayment->payment); | ||
|
||
ServiceConfig::set('checkout', 'models.' . Payment::class, TestPayment::class); | ||
$transactionEventWithOverriddenPayment = TransactionEvent::factory()->create(); | ||
$this->assertInstanceOf(TestPayment::class, $transactionEventWithOverriddenPayment->payment); | ||
} | ||
|
||
#[Test] | ||
public function retrieve_transaction_event_transactionable() | ||
{ | ||
$transactionEvent = TransactionEvent::factory()->create(); | ||
$this->assertNull($transactionEvent->transactionable); | ||
|
||
$transactionables = [ | ||
Payment::class => TestPayment::class, | ||
Refund::class => TestRefund::class, | ||
Dispute::class => TestDispute::class, | ||
]; | ||
|
||
$randomTransactionable = $this->faker->randomElement(array_keys($transactionables)); | ||
$transactionEventWithTransactionable = TransactionEvent::factory()->for($randomTransactionable::factory(), 'transactionable')->create(); | ||
$this->assertInstanceOf($randomTransactionable, $transactionEventWithTransactionable->transactionable); | ||
|
||
$randomTransactionable = $this->faker->randomElement(array_keys($transactionables)); | ||
ServiceConfig::set('checkout', 'models.' . $randomTransactionable, $transactionables[$randomTransactionable]); | ||
$transactionEventWithOverriddenTransactionable = TransactionEvent::factory()->for($transactionables[$randomTransactionable]::factory(), 'transactionable')->create(); | ||
$this->assertInstanceOf($transactionables[$randomTransactionable], $transactionEventWithOverriddenTransactionable->transactionable); | ||
} | ||
} |