Skip to content

Commit

Permalink
Use TestCase::$checkoutConfig in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Jun 27, 2024
1 parent a50797c commit 329bff8
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions tests/Unit/Database/PaymentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function retrieve_payment_provider()
$paymentWithProvider = Payment::factory()->create($usingServiceables);
$this->assertInstanceOf(Provider::class, $paymentWithProvider->provider);

ServiceConfig::find('checkout')->set('models.' . Provider::class, TestProvider::class);
$this->checkoutConfig->set('models.' . Provider::class, TestProvider::class);
$paymentWithOverriddenProvider = Payment::factory()->create($usingServiceables);
$this->assertInstanceOf(TestProvider::class, $paymentWithOverriddenProvider->provider);
}
Expand All @@ -45,7 +45,7 @@ public function retrieve_payment_account()
$paymentWithAccount = Payment::factory()->create($usingServiceables);
$this->assertInstanceOf(Account::class, $paymentWithAccount->account);

ServiceConfig::find('checkout')->set('models.' . Account::class, TestAccount::class);
$this->checkoutConfig->set('models.' . Account::class, TestAccount::class);
$paymentWithOverriddenAccount = Payment::factory()->create($usingServiceables);
$this->assertInstanceOf(TestAccount::class, $paymentWithOverriddenAccount->account);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Database/WalletModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function retrieve_wallet_provider()
$walletWithProvider = Wallet::factory()->create($usingServiceables);
$this->assertInstanceOf(Provider::class, $walletWithProvider->provider);

ServiceConfig::find('checkout')->set('models.' . Provider::class, TestProvider::class);
$this->checkoutConfig->set('models.' . Provider::class, TestProvider::class);
$walletWithOverriddenProvider = Wallet::factory()->create($usingServiceables);
$this->assertInstanceOF(TestProvider::class, $walletWithOverriddenProvider->provider);
}
Expand All @@ -45,7 +45,7 @@ public function retrieve_wallet_account()
$walletWithAccount = Wallet::factory()->create($usingServiceables);
$this->assertInstanceOf(Account::class, $walletWithAccount->account);

ServiceConfig::find('checkout')->set('models.' . Account::class, TestAccount::class);
$this->checkoutConfig->set('models.' . Account::class, TestAccount::class);
$walletWithOverriddenAccount = Wallet::factory()->create($usingServiceables);
$this->assertInstanceOF(TestAccount::class, $walletWithOverriddenAccount->account);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/TestBillableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function retrieve_billable_wallets()
$this->assertCount(2, $billableWith2Wallets->wallets);
$this->assertContainsOnlyInstancesOf(Wallet::class, $billableWith2Wallets->wallets);

ServiceConfig::find('checkout')->set('models.'.Wallet::class, TestWallet::class);
$this->checkoutConfig->set('models.'.Wallet::class, TestWallet::class);
$billableWith3OverriddenWallets = User::factory()->has(Wallet::factory()->count(3)->sequence(fn () => [
'provider_id' => $this->createProvider($this->checkoutConfig)->getId(),
'account_id' => $this->createAccount($this->checkoutConfig)->getId(),
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/TestDisputeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function retrieve_dispute_payment()
$disputeWithPayment = Dispute::factory()->for(Payment::factory()->create($usingServiceables))->create();
$this->assertInstanceOf(Payment::class, $disputeWithPayment->payment);

ServiceConfig::find('checkout')->set('models.' . Payment::class, TestPayment::class);
$this->checkoutConfig->set('models.' . Payment::class, TestPayment::class);
$disputeWithOverriddenPayment = Dispute::factory()->for(Payment::factory()->create($usingServiceables))->create();
$this->assertInstanceOf(TestPayment::class, $disputeWithOverriddenPayment->payment);
}
Expand All @@ -45,7 +45,7 @@ public function retrieve_dispute_transaction_events()
$this->assertCount(2, $disputeWith2TransactionEvents->transactionEvents);
$this->assertContainsOnlyInstancesOf(TransactionEvent::class, $disputeWith2TransactionEvents->transactionEvents);

ServiceConfig::find('checkout')->set('models.' . TransactionEvent::class, TestTransactionEvent::class);
$this->checkoutConfig->set('models.' . TransactionEvent::class, TestTransactionEvent::class);
$disputeWith3OverriddenTransactionEvents = Dispute::factory()->for($paymentForDisputeWith3TransactionEvents = Payment::factory()->create($usingServiceables))->hasTransactionEvents(3, ['payment_id' => $paymentForDisputeWith3TransactionEvents->id])->create();
$this->assertCount(3, $disputeWith3OverriddenTransactionEvents->transactionEvents);
$this->assertContainsOnlyInstancesOf(TestTransactionEvent::class, $disputeWith3OverriddenTransactionEvents->transactionEvents);
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/TestPaymentInstrumentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function retrieve_payment_instrument_wallet()
$paymentInstrumentWithWallet = PaymentInstrument::factory()->for($wallet)->create();
$this->assertInstanceOf(Wallet::class, $paymentInstrumentWithWallet->wallet);

ServiceConfig::find('checkout')->set('models.' . Wallet::class, TestWallet::class);
$this->checkoutConfig->set('models.' . Wallet::class, TestWallet::class);
$paymentInstrumentWithOverriddenWallet = PaymentInstrument::factory()->for($wallet)->create();
$this->assertInstanceOf(TestWallet::class, $paymentInstrumentWithOverriddenWallet->wallet);
}
Expand All @@ -43,7 +43,7 @@ public function retrieve_payment_instrument_type()
$paymentInstrumentWithType = PaymentInstrument::factory()->for($wallet)->create();
$this->assertInstanceOf(PaymentType::class, $paymentInstrumentWithType->type);

ServiceConfig::find('checkout')->set('models.' . PaymentType::class, TestPaymentType::class);
$this->checkoutConfig->set('models.' . PaymentType::class, TestPaymentType::class);
$paymentInstrumentWithOverriddenType = PaymentInstrument::factory()->for($wallet)->create();
$this->assertInstanceOf(TestPaymentType::class, $paymentInstrumentWithOverriddenType->type);
}
Expand All @@ -63,7 +63,7 @@ public function retrieve_payment_instrument_payments()
$this->assertCount(2, $paymentInstrumentWith2Payments->payments);
$this->assertContainsOnlyInstancesOf(Payment::class, $paymentInstrumentWith2Payments->payments);

ServiceConfig::find('checkout')->set('models.' . Payment::class, TestPayment::class);
$this->checkoutConfig->set('models.' . Payment::class, TestPayment::class);
$paymentInstrumentWith3OverriddenPayments = PaymentInstrument::factory()->for($wallet)->hasPayments(3)->create();
$this->assertCount(3, $paymentInstrumentWith3OverriddenPayments->payments);
$this->assertContainsOnlyInstancesOf(TestPayment::class, $paymentInstrumentWith3OverriddenPayments->payments);
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/TestPaymentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function retrieve_payment_rail()
$paymentWithRail = Payment::factory()->create($usingServiceables);
$this->assertInstanceOf(PaymentRail::class, $paymentWithRail->rail);

ServiceConfig::find('checkout')->set('models.' . PaymentRail::class, TestPaymentRail::class);
$this->checkoutConfig->set('models.' . PaymentRail::class, TestPaymentRail::class);
$paymentWithOverriddenRail = Payment::factory()->create($usingServiceables);
$this->assertInstanceOf(TestPaymentRail::class, $paymentWithOverriddenRail->rail);
}
Expand All @@ -50,7 +50,7 @@ public function retrieve_payment_instrument()
$paymentWithInstrument = Payment::factory()->for(PaymentInstrument::factory()->for(Wallet::factory()->create($usingServiceables))->create(), 'instrument')->create($usingServiceables);
$this->assertInstanceOf(PaymentInstrument::class, $paymentWithInstrument->instrument);

ServiceConfig::find('checkout')->set('models.' . PaymentInstrument::class, TestPaymentInstrument::class);
$this->checkoutConfig->set('models.' . PaymentInstrument::class, TestPaymentInstrument::class);
$paymentWithOverriddenInstrument = Payment::factory()->for(PaymentInstrument::factory()->for(Wallet::factory()->create($usingServiceables))->create(), 'instrument')->create($usingServiceables);
$this->assertInstanceOf(TestPaymentInstrument::class, $paymentWithOverriddenInstrument->instrument);
}
Expand All @@ -70,7 +70,7 @@ public function retrieve_payment_events()
$this->assertCount(2, $paymentWith2Events->events);
$this->assertContainsOnlyInstancesOf(TransactionEvent::class, $paymentWith2Events->events);

ServiceConfig::find('checkout')->set('models.' . TransactionEvent::class, TestTransactionEvent::class);
$this->checkoutConfig->set('models.' . TransactionEvent::class, TestTransactionEvent::class);
$paymentWith3OverriddenEvents = Payment::factory()->hasEvents(3, ['status_code' => CheckoutStatus::AUTHORIZED])->create($usingServiceables);
$this->assertCount(3, $paymentWith3OverriddenEvents->events);
$this->assertContainsOnlyInstancesOf(TestTransactionEvent::class, $paymentWith3OverriddenEvents->events);
Expand All @@ -91,7 +91,7 @@ public function retrieve_payment_transaction_events()
$this->assertCount(2, $paymentWith2TransactionEvents->transactionEvents);
$this->assertContainsOnlyInstancesOf(TransactionEvent::class, $paymentWith2TransactionEvents->transactionEvents);

ServiceConfig::find('checkout')->set('models.' . TransactionEvent::class, TestTransactionEvent::class);
$this->checkoutConfig->set('models.' . TransactionEvent::class, TestTransactionEvent::class);
$paymentWith3OverriddenTransactionEvents = Payment::factory()->hasTransactionEvents(3)->create($usingServiceables);
$this->assertCount(3, $paymentWith3OverriddenTransactionEvents->transactionEvents);
$this->assertContainsOnlyInstancesOf(TestTransactionEvent::class, $paymentWith3OverriddenTransactionEvents->transactionEvents);
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/TestPaymentRailModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function retrieve_payment_rail_parent_type()
$paymentRail = PaymentRail::factory()->create();
$this->assertInstanceOf(PaymentType::class, $paymentRail->parentType);

ServiceConfig::find('checkout')->set('models.' . PaymentType::class, TestPaymentType::class);
$this->checkoutConfig->set('models.' . PaymentType::class, TestPaymentType::class);
$paymentRailWithOverriddenParentType = PaymentRail::factory()->create();
$this->assertInstanceOf(TestPaymentType::class, $paymentRailWithOverriddenParentType->parentType);
}
Expand All @@ -58,7 +58,7 @@ public function retrieve_payment_rail_type()
$paymentRail = PaymentRail::factory()->create();
$this->assertInstanceOf(PaymentType::class, $paymentRail->type);

ServiceConfig::find('checkout')->set('models.' . PaymentType::class, TestPaymentType::class);
$this->checkoutConfig->set('models.' . PaymentType::class, TestPaymentType::class);
$paymentRailWithOverriddenType = PaymentRail::factory()->create();
$this->assertInstanceOf(TestPaymentType::class, $paymentRailWithOverriddenType->type);
}
Expand All @@ -78,7 +78,7 @@ public function retrieve_payment_rail_payments()
$this->assertCount(2, $paymentRailWith2Payments->payments);
$this->assertContainsOnlyInstancesOf(Payment::class, $paymentRailWith2Payments->payments);

ServiceConfig::find('checkout')->set('models.' . Payment::class, TestPayment::class);
$this->checkoutConfig->set('models.' . Payment::class, TestPayment::class);
$paymentRailWith3OverriddenPayments = PaymentRail::factory()->hasPayments(3, $usingServiceables)->create();
$this->assertCount(3, $paymentRailWith3OverriddenPayments->payments);
$this->assertContainsOnlyInstancesOf(TestPayment::class, $paymentRailWith3OverriddenPayments->payments);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/TestPaymentTypeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function retrieve_payment_type_rails()
$this->assertCount(2, $paymentTypeWith2Rails->rails);
$this->assertContainsOnlyInstancesOf(PaymentRail::class, $paymentTypeWith2Rails->rails);

ServiceConfig::find('checkout')->set('models.' . PaymentRail::class, TestPaymentRail::class);
$this->checkoutConfig->set('models.' . PaymentRail::class, TestPaymentRail::class);
$paymentTypeWith3OverriddenRails = PaymentType::factory()->hasRails(3)->create();
$this->assertCount(3, $paymentTypeWith3OverriddenRails->rails);
$this->assertContainsOnlyInstancesOf(TestPaymentRail::class, $paymentTypeWith3OverriddenRails->rails);
Expand All @@ -46,7 +46,7 @@ public function retrieve_payment_type_instruments()
$this->assertCount(2, $paymentTypeWith2Instruments->instruments);
$this->assertContainsOnlyInstancesOf(PaymentInstrument::class, $paymentTypeWith2Instruments->instruments);

ServiceConfig::find('checkout')->set('models.' . PaymentInstrument::class, TestPaymentInstrument::class);
$this->checkoutConfig->set('models.' . PaymentInstrument::class, TestPaymentInstrument::class);
$paymentTypeWith3OverriddenInstruments = PaymentType::factory()->has(PaymentInstrument::factory()->count(3)->for($wallet), 'instruments')->create();
$this->assertCount(3, $paymentTypeWith3OverriddenInstruments->instruments);
$this->assertContainsOnlyInstancesOf(TestPaymentInstrument::class, $paymentTypeWith3OverriddenInstruments->instruments);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/TestRefundModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function retrieve_refund_payment()
$refundWithPayment = Refund::factory()->for(Payment::factory()->create($usingServiceables))->create();
$this->assertInstanceOf(Payment::class, $refundWithPayment->payment);

ServiceConfig::find('checkout')->set('models.' . Payment::class, TestPayment::class);
$this->checkoutConfig->set('models.' . Payment::class, TestPayment::class);
$refundWithOverriddenPayment = Refund::factory()->for(Payment::factory()->create($usingServiceables))->create();
$this->assertInstanceOf(TestPayment::class, $refundWithOverriddenPayment->payment);
}
Expand All @@ -45,7 +45,7 @@ public function retrieve_refund_transaction_events()
$this->assertCount(2, $refundWith2TransactionEvents->transactionEvents);
$this->assertContainsOnlyInstancesOf(TransactionEvent::class, $refundWith2TransactionEvents->transactionEvents);

ServiceConfig::find('checkout')->set('models.' . TransactionEvent::class, TestTransactionEvent::class);
$this->checkoutConfig->set('models.' . TransactionEvent::class, TestTransactionEvent::class);
$refundWith3OverriddenTransactionEvents = Refund::factory()->for($paymentForRefundWith3TransactionEvents = Payment::factory()->create($usingServiceables))->hasTransactionEvents(3, ['payment_id' => $paymentForRefundWith3TransactionEvents->id])->create();
$this->assertCount(3, $refundWith3OverriddenTransactionEvents->transactionEvents);
$this->assertContainsOnlyInstancesOf(TestTransactionEvent::class, $refundWith3OverriddenTransactionEvents->transactionEvents);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/TestTransactionEventModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function retrieve_transaction_event_payment()
$transactionEventWithPayment = TransactionEvent::factory()->for(Payment::factory()->create($usingServiceables))->create(['status_code' => CheckoutStatus::AUTHORIZED]);
$this->assertInstanceOf(Payment::class, $transactionEventWithPayment->payment);

ServiceConfig::find('checkout')->set('models.' . Payment::class, TestPayment::class);
$this->checkoutConfig->set('models.' . Payment::class, TestPayment::class);
$transactionEventWithOverriddenPayment = TransactionEvent::factory()->for(Payment::factory()->create($usingServiceables))->create(['status_code' => CheckoutStatus::AUTHORIZED]);
$this->assertInstanceOf(TestPayment::class, $transactionEventWithOverriddenPayment->payment);
}
Expand All @@ -46,7 +46,7 @@ public function retrieve_transaction_event_transactionable()
$transactionEventWithTransactionable = TransactionEvent::factory()->for($paymentForTransactionEventWithTransactionable = Payment::factory()->create($usingServiceables))->for(Refund::factory()->for($paymentForTransactionEventWithTransactionable)->create(), 'transactionable')->create(['status_code' => CheckoutStatus::AUTHORIZED]);
$this->assertInstanceOf(Refund::class, $transactionEventWithTransactionable->transactionable);

ServiceConfig::find('checkout')->set('models.' . Dispute::class, TestDispute::class);
$this->checkoutConfig->set('models.' . Dispute::class, TestDispute::class);
$transactionEventWithOverriddenTransactionable = TransactionEvent::factory()->for($paymentForTransactionEventWithOverriddenTransactionable = Payment::factory()->create($usingServiceables))->create(['status_code' => CheckoutStatus::AUTHORIZED]);
$transactionEventWithOverriddenTransactionable->transactionable()->associate(transform(Dispute::factory()->for($paymentForTransactionEventWithOverriddenTransactionable)->create(), fn ($dispute) => TestDispute::find($dispute->id)));
$this->assertInstanceOf(TestDispute::class, $transactionEventWithOverriddenTransactionable->transactionable);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/TestWalletModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function retrieve_wallet_payment_instruments()
$this->assertCount(2, $walletWith2PaymentInstruments->paymentInstruments);
$this->assertContainsOnlyInstancesOf(PaymentInstrument::class, $walletWith2PaymentInstruments->paymentInstruments);

ServiceConfig::find('checkout')->set('models.' . PaymentInstrument::class, TestPaymentInstrument::class);
$this->checkoutConfig->set('models.' . PaymentInstrument::class, TestPaymentInstrument::class);
$walletWith3OverriddenPaymentInstruments = Wallet::factory()->hasPaymentInstruments(3)->create($usingServiceables);
$this->assertCount(3, $walletWith3OverriddenPaymentInstruments->paymentInstruments);
$this->assertContainsOnlyInstancesOf(TestPaymentInstrument::class, $walletWith3OverriddenPaymentInstruments->paymentInstruments);
Expand Down

0 comments on commit 329bff8

Please sign in to comment.