Files
wc-licensed-product-client/tests/Dto/LicenseInfoTest.php
magdev af735df260 Add PHPUnit test suite
- Add PHPUnit 11.0 as dev dependency
- Add phpunit.xml configuration
- Add DTO tests (LicenseInfo, LicenseStatus, ActivationResult)
- Add Exception tests (factory method, all exception types)
- Add LicenseClient tests with mocked HTTP responses
- Update README with testing instructions
- Update CHANGELOG

32 tests, 93 assertions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 16:05:28 +01:00

72 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Magdev\WcLicensedProductClient\Tests\Dto;
use Magdev\WcLicensedProductClient\Dto\LicenseInfo;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
#[CoversClass(LicenseInfo::class)]
final class LicenseInfoTest extends TestCase
{
#[Test]
public function itCanBeCreatedFromArray(): void
{
$data = [
'product_id' => 123,
'expires_at' => '2027-01-21',
'version_id' => 5,
];
$licenseInfo = LicenseInfo::fromArray($data);
self::assertSame(123, $licenseInfo->productId);
self::assertInstanceOf(\DateTimeImmutable::class, $licenseInfo->expiresAt);
self::assertSame('2027-01-21', $licenseInfo->expiresAt->format('Y-m-d'));
self::assertSame(5, $licenseInfo->versionId);
}
#[Test]
public function itCanBeCreatedWithNullExpiresAt(): void
{
$data = [
'product_id' => 456,
'expires_at' => null,
'version_id' => null,
];
$licenseInfo = LicenseInfo::fromArray($data);
self::assertSame(456, $licenseInfo->productId);
self::assertNull($licenseInfo->expiresAt);
self::assertNull($licenseInfo->versionId);
}
#[Test]
public function itCanBeCreatedWithoutOptionalFields(): void
{
$data = [
'product_id' => 789,
];
$licenseInfo = LicenseInfo::fromArray($data);
self::assertSame(789, $licenseInfo->productId);
self::assertNull($licenseInfo->expiresAt);
self::assertNull($licenseInfo->versionId);
}
#[Test]
public function itIdentifiesLifetimeLicense(): void
{
$lifetime = LicenseInfo::fromArray(['product_id' => 1, 'expires_at' => null]);
$expiring = LicenseInfo::fromArray(['product_id' => 2, 'expires_at' => '2027-12-31']);
self::assertTrue($lifetime->isLifetime());
self::assertFalse($expiring->isLifetime());
}
}