-
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
3 changed files
with
111 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Payavel\Checkout\Tests\Models; | ||
|
||
use Payavel\Checkout\Models\Payment; | ||
|
||
class TestPayment extends Payment | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'payments'; | ||
|
||
/** | ||
* 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,22 @@ | ||
<?php | ||
|
||
namespace Payavel\Checkout\Tests\Models; | ||
|
||
use Payavel\Checkout\Models\PaymentType; | ||
|
||
class TestPaymentType extends PaymentType | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'payment_types'; | ||
|
||
/** | ||
* 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,67 @@ | ||
<?php | ||
|
||
namespace Payavel\Checkout\Tests\Unit\Models; | ||
|
||
use Payavel\Checkout\Models\Payment; | ||
use Payavel\Checkout\Models\PaymentRail; | ||
use Payavel\Checkout\Models\PaymentType; | ||
use Payavel\Checkout\Tests\Models\TestPayment; | ||
use Payavel\Checkout\Tests\Models\TestPaymentType; | ||
use Payavel\Checkout\Tests\TestCase; | ||
use Payavel\Orchestration\Support\ServiceConfig; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
class PaymentRailTest extends TestCase | ||
{ | ||
#[Test] | ||
public function payment_rail_generates_id_before_committing() | ||
{ | ||
$parentPaymentType = PaymentType::factory()->create(); | ||
$paymentType = PaymentType::factory()->create(); | ||
|
||
$paymentRail = PaymentRail::create([ | ||
'parent_type_id' => $parentPaymentType->id, | ||
'type_id' => $paymentType->id, | ||
]); | ||
|
||
$this->assertEquals("{$parentPaymentType->id}:{$paymentType->id}", $paymentRail->id); | ||
} | ||
|
||
#[Test] | ||
public function retrieve_payment_rail_parent_type() | ||
{ | ||
$paymentRail = PaymentRail::factory()->create(); | ||
$this->assertInstanceOf(PaymentType::class, $paymentRail->parentType); | ||
|
||
ServiceConfig::set('checkout', 'models.' . PaymentType::class, TestPaymentType::class); | ||
$paymentRailWithOverriddenParentType = PaymentRail::factory()->create(); | ||
$this->assertInstanceOf(TestPaymentType::class, $paymentRailWithOverriddenParentType->parentType); | ||
} | ||
|
||
#[Test] | ||
public function retrieve_payment_rail_type() | ||
{ | ||
$paymentRail = PaymentRail::factory()->create(); | ||
$this->assertInstanceOf(PaymentType::class, $paymentRail->type); | ||
|
||
ServiceConfig::set('checkout', 'models.' . PaymentType::class, TestPaymentType::class); | ||
$paymentRailWithOverriddenType = PaymentRail::factory()->create(); | ||
$this->assertInstanceOf(TestPaymentType::class, $paymentRailWithOverriddenType->type); | ||
} | ||
|
||
#[Test] | ||
public function retrieve_payment_rail_payments() | ||
{ | ||
$paymentRail = PaymentRail::factory()->create(); | ||
$this->assertEmpty($paymentRail->payments); | ||
|
||
$paymentRailWith2Payments = PaymentRail::factory()->hasPayments(2)->create(); | ||
$this->assertCount(2, $paymentRailWith2Payments->payments); | ||
$this->assertContainsOnlyInstancesOf(Payment::class, $paymentRailWith2Payments->payments); | ||
|
||
ServiceConfig::set('checkout', 'models.' . Payment::class, TestPayment::class); | ||
$paymentRailWith3OverriddenPayments = PaymentRail::factory()->hasPayments(3)->create(); | ||
$this->assertCount(3, $paymentRailWith3OverriddenPayments->payments); | ||
$this->assertContainsOnlyInstancesOf(TestPayment::class, $paymentRailWith3OverriddenPayments->payments); | ||
} | ||
} |