ldc-mesbr-app/tests/Unit/Domain/Models/Entities/ProductTest.php
2026-09-08 16:33:54 +02:00

41 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\Entities\ValueObjects;
use Domain\Models\Entities\Product;
use Domain\Models\ValueObjects\ProductId;
describe('product', function (): void {
it('creates a product with a generated id and a name', function (): void {
$productName = 'New Product';
$productId = ProductId::generate();
$product = new Product($productId, $productName);
expect($product->id())->toBe($productId)
->and($product->name())->toBe($productName);
});
it('rejects an empty name', function (): void {
expect(fn (): Product => new Product(ProductId::generate(), ''))
->toThrow(\DomainException::class, 'Product name cannot be empty.');
});
it('considers two products with the same id as equal', function (): void {
$productId = ProductId::generate();
$first = new Product($productId, 'New Product 1');
$second = new Product($productId, 'New Product 2');
expect($first->equals($second))->toBeTrue();
});
it('considers two products with different ids as not equal', function (): void {
$productName = 'New Product';
$first = new Product(ProductId::generate(), $productName);
$second = new Product(ProductId::generate(), $productName);
expect($first->equals($second))->toBeFalse();
});
});