laravel-shop/tests/Feature/Checkout/PaymentMethodFieldsTest.php

85 lines
2.5 KiB
PHP
Raw Normal View History

2025-11-29 11:05:02 +00:00
<?php
namespace Blax\Shop\Tests\Feature;
use Blax\Shop\Models\PaymentMethod;
use Blax\Shop\Models\PaymentProviderIdentity;
use Blax\Shop\Tests\TestCase;
use Illuminate\Support\Carbon;
2025-12-24 18:40:10 +00:00
use PHPUnit\Framework\Attributes\Test;
2025-11-29 11:05:02 +00:00
class PaymentMethodFieldsTest extends TestCase
{
2025-12-24 18:40:10 +00:00
#[Test]
2025-11-29 11:05:02 +00:00
public function test_can_store_last_alphanumeric(): void
{
$identity = PaymentProviderIdentity::factory()->stripe()->create();
$method = PaymentMethod::factory()
->forProviderIdentity($identity)
->create([
'type' => 'wallet',
'last_alphanumeric' => 'abc123xyz',
'expires_at' => null,
]);
$this->assertNotNull($method->id);
$this->assertSame('abc123xyz', $method->last_alphanumeric);
}
2025-12-24 18:40:10 +00:00
#[Test]
2025-11-29 11:05:02 +00:00
public function test_expiration_via_expires_at(): void
{
$identity = PaymentProviderIdentity::factory()->stripe()->create();
$past = Carbon::now()->subDay();
$future = Carbon::now()->addDay();
$expired = PaymentMethod::factory()
->forProviderIdentity($identity)
->create([
'type' => 'wallet',
'expires_at' => $past,
'exp_month' => null,
'exp_year' => null,
]);
$this->assertTrue($expired->isExpired());
$active = PaymentMethod::factory()
->forProviderIdentity($identity)
->create([
'type' => 'wallet',
'expires_at' => $future,
'exp_month' => null,
'exp_year' => null,
]);
$this->assertFalse($active->isExpired());
}
2025-12-24 18:40:10 +00:00
#[Test]
2025-11-29 11:05:02 +00:00
public function test_expiration_via_month_year(): void
{
$identity = PaymentProviderIdentity::factory()->stripe()->create();
$expired = PaymentMethod::factory()
->forProviderIdentity($identity)
->create([
'type' => 'card',
'exp_month' => 1,
'exp_year' => Carbon::now()->year - 1,
'expires_at' => null,
]);
$this->assertTrue($expired->isExpired());
$nonExpired = PaymentMethod::factory()
->forProviderIdentity($identity)
->create([
'type' => 'card',
'exp_month' => Carbon::now()->month,
'exp_year' => Carbon::now()->year + 1,
'expires_at' => null,
]);
$this->assertFalse($nonExpired->isExpired());
}
}