148 lines
4.7 KiB
PHP
148 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Cqs\Actions\Customers\RegisterCustomerInput;
|
|
use Domain\Models\ValueObjects\Code;
|
|
use Domain\Models\ValueObjects\Email;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
use Domain\Models\ValueObjects\PhoneNumber;
|
|
|
|
describe('RegisterCustomerInput', function () {
|
|
it('creates a valid instance with all fields', function () {
|
|
// GIVEN
|
|
$matricule = new Matricule('1234567');
|
|
$code = new Code('ABCDEF');
|
|
$email = new Email('john.doe@example.com');
|
|
$birthDate = new \DateTimeImmutable('1990-01-01');
|
|
$phone = new PhoneNumber('+33612345678');
|
|
|
|
// WHEN
|
|
$input = new RegisterCustomerInput(
|
|
matricule: $matricule,
|
|
code: $code,
|
|
firstname: 'John',
|
|
lastname: 'Doe',
|
|
email: $email,
|
|
password: 'secretPassword123!',
|
|
birthDate: $birthDate,
|
|
phone: $phone,
|
|
address: '10 rue de Paris',
|
|
postcode: '75001',
|
|
city: 'Paris',
|
|
optIn: true
|
|
);
|
|
|
|
// THEN
|
|
expect($input->matricule)->toBe($matricule)
|
|
->and($input->code)->toBe($code)
|
|
->and($input->firstname)->toBe('John')
|
|
->and($input->lastname)->toBe('Doe')
|
|
->and($input->email)->toBe($email)
|
|
->and($input->password)->toBe('secretPassword123!')
|
|
->and($input->birthDate)->toBe($birthDate)
|
|
->and($input->phone)->toBe($phone)
|
|
->and($input->address)->toBe('10 rue de Paris')
|
|
->and($input->postcode)->toBe('75001')
|
|
->and($input->city)->toBe('Paris')
|
|
->and($input->optIn)->toBeTrue();
|
|
});
|
|
|
|
it('creates a valid instance with nullable fields as null', function () {
|
|
// GIVEN
|
|
$matricule = new Matricule('1234567');
|
|
$code = new Code('ABCDEF');
|
|
$email = new Email('jane.doe@example.com');
|
|
$birthDate = new \DateTimeImmutable('1995-05-15');
|
|
|
|
// WHEN
|
|
$input = new RegisterCustomerInput(
|
|
matricule: $matricule,
|
|
code: $code,
|
|
firstname: 'Jane',
|
|
lastname: 'Doe',
|
|
email: $email,
|
|
password: 'secretPassword123!',
|
|
birthDate: $birthDate,
|
|
phone: null,
|
|
address: null,
|
|
postcode: '75001',
|
|
city: 'Paris',
|
|
optIn: false
|
|
);
|
|
|
|
// THEN
|
|
expect($input->phone)->toBeNull()
|
|
->and($input->address)->toBeNull()
|
|
->and($input->optIn)->toBeFalse();
|
|
});
|
|
|
|
it('throws when firstname is empty', function () {
|
|
// GIVEN
|
|
$matricule = new Matricule('1234567');
|
|
$code = new Code('ABCDEF');
|
|
$email = new Email('jane.doe@example.com');
|
|
$birthDate = new \DateTimeImmutable('1995-05-15');
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new RegisterCustomerInput(
|
|
matricule: $matricule,
|
|
code: $code,
|
|
firstname: ' ',
|
|
lastname: 'Doe',
|
|
email: $email,
|
|
password: 'secretPassword123!',
|
|
birthDate: $birthDate,
|
|
phone: null,
|
|
address: null,
|
|
postcode: '75001',
|
|
city: 'Paris'
|
|
))->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
|
|
it('throws when lastname is empty', function () {
|
|
// GIVEN
|
|
$matricule = new Matricule('1234567');
|
|
$code = new Code('ABCDEF');
|
|
$email = new Email('jane.doe@example.com');
|
|
$birthDate = new \DateTimeImmutable('1995-05-15');
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new RegisterCustomerInput(
|
|
matricule: $matricule,
|
|
code: $code,
|
|
firstname: 'Jane',
|
|
lastname: '',
|
|
email: $email,
|
|
password: 'secretPassword123!',
|
|
birthDate: $birthDate,
|
|
phone: null,
|
|
address: null,
|
|
postcode: '75001',
|
|
city: 'Paris'
|
|
))->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
|
|
it('throws when postcode is empty', function () {
|
|
// GIVEN
|
|
$matricule = new Matricule('1234567');
|
|
$code = new Code('ABCDEF');
|
|
$email = new Email('jane.doe@example.com');
|
|
$birthDate = new \DateTimeImmutable('1995-05-15');
|
|
|
|
// WHEN & THEN
|
|
expect(fn () => new RegisterCustomerInput(
|
|
matricule: $matricule,
|
|
code: $code,
|
|
firstname: 'Jane',
|
|
lastname: 'Doe',
|
|
email: $email,
|
|
password: 'secretPassword123!',
|
|
birthDate: $birthDate,
|
|
phone: null,
|
|
address: null,
|
|
postcode: ' ',
|
|
city: 'Paris'
|
|
))->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
});
|