Skip to content

Commit

Permalink
Reformat DisputeModelTest
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Jun 9, 2024
1 parent 6b6a0ae commit 8edcc1d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
13 changes: 13 additions & 0 deletions tests/Unit/Config/DisputeModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Payavel\Checkout\Tests\Unit\Config;

use Payavel\Checkout\Tests\Unit\TestDisputeModel;
use Payavel\Orchestration\Tests\Traits\CreatesConfigServiceables;
use Payavel\Orchestration\Tests\Traits\SetsConfigDriver;

class DisputeModelTest extends TestDisputeModel
{
use CreatesConfigServiceables;
use SetsConfigDriver;
}
13 changes: 13 additions & 0 deletions tests/Unit/Database/DisputeModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Payavel\Checkout\Tests\Unit\Database;

use Payavel\Checkout\Tests\Unit\TestDisputeModel;
use Payavel\Orchestration\Tests\Traits\CreatesDatabaseServiceables;
use Payavel\Orchestration\Tests\Traits\SetsDatabaseDriver;

class DisputeModelTest extends TestDisputeModel
{
use CreatesDatabaseServiceables;
use SetsDatabaseDriver;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,44 @@
use Payavel\Checkout\Tests\Models\TestTransactionEvent;
use Payavel\Checkout\Tests\TestCase;
use Payavel\Orchestration\Support\ServiceConfig;
use Payavel\Orchestration\Tests\Contracts\CreatesServiceables;
use PHPUnit\Framework\Attributes\Test;

class DisputeModelTest extends TestCase
abstract class TestDisputeModel extends TestCase implements CreatesServiceables
{
#[Test]
public function retrieve_dispute_payment()
{
$disputeWithPayment = Dispute::factory()->create();
$usingServiceables = [
'provider_id' => $this->createProvider($this->checkoutService)->getId(),
'account_id' => $this->createAccount($this->checkoutService)->getID(),
];

$disputeWithPayment = Dispute::factory()->for(Payment::factory()->create($usingServiceables))->create();
$this->assertInstanceOf(Payment::class, $disputeWithPayment->payment);

ServiceConfig::set('checkout', 'models.' . Payment::class, TestPayment::class);
$disputeWithOverriddenPayment = Dispute::factory()->create();
$disputeWithOverriddenPayment = Dispute::factory()->for(Payment::factory()->create($usingServiceables))->create();
$this->assertInstanceOf(TestPayment::class, $disputeWithOverriddenPayment->payment);
}

#[Test]
public function retrieve_dispute_transaction_events()
{
$dispute = Dispute::factory()->create();
$usingServiceables = [
'provider_id' => $this->createProvider($this->checkoutService)->getId(),
'account_id' => $this->createAccount($this->checkoutService)->getID(),
];

$dispute = Dispute::factory()->for(Payment::factory()->create($usingServiceables))->create();
$this->assertEmpty($dispute->transactionEvents);

$disputeWith2TransactionEvents = Dispute::factory()->hasTransactionEvents(2)->create();
$disputeWith2TransactionEvents = Dispute::factory()->for($paymentForDisputeWith2TransactionEvents = Payment::factory()->create($usingServiceables))->hasTransactionEvents(2, ['payment_id' => $paymentForDisputeWith2TransactionEvents->id])->create();
$this->assertCount(2, $disputeWith2TransactionEvents->transactionEvents);
$this->assertContainsOnlyInstancesOf(TransactionEvent::class, $disputeWith2TransactionEvents->transactionEvents);

ServiceConfig::set('checkout', 'models.' . TransactionEvent::class, TestTransactionEvent::class);
$disputeWith3OverriddenTransactionEvents = Dispute::factory()->hasTransactionEvents(3)->create();
$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

0 comments on commit 8edcc1d

Please sign in to comment.