81 lines
2.6 KiB
PHP
81 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Enums\Campaign;
|
|
|
|
use Domain\Enums\Campaign\CampaignStatus;
|
|
|
|
covers(CampaignStatus::class);
|
|
|
|
describe('campaign status', function (): void {
|
|
it('has the expected cases with their backing values', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::CREATED->value())->toBe(1)
|
|
->and(CampaignStatus::TRANSFORMED->value())->toBe(2)
|
|
->and(CampaignStatus::REJECTED->value())->toBe(3);
|
|
});
|
|
|
|
it('exposes its case name', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::CREATED->name())->toBe('CREATED');
|
|
});
|
|
|
|
it('returns the defined label', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::CREATED->label())->toBe('Crée')
|
|
->and(CampaignStatus::TRANSFORMED->label())->toBe('Transformé')
|
|
->and(CampaignStatus::REJECTED->label())->toBe('Rejeté');
|
|
});
|
|
|
|
it('lists all labels keyed by case name', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::toLabels())->toBe([
|
|
'CREATED' => 'Crée',
|
|
'TRANSFORMED' => 'Transformé',
|
|
'REJECTED' => 'Rejeté',
|
|
]);
|
|
});
|
|
|
|
it('lists all values keyed by case name', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::toValues())->toBe([
|
|
'CREATED' => 1,
|
|
'TRANSFORMED' => 2,
|
|
'REJECTED' => 3,
|
|
]);
|
|
});
|
|
|
|
it('makes an instance from its backing value', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::make(1))->toBe(CampaignStatus::CREATED);
|
|
});
|
|
|
|
it('makes an instance from a label', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::make('Transformé', 'label'))->toBe(CampaignStatus::TRANSFORMED);
|
|
});
|
|
|
|
it('returns the same instance when already an enum case', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::make(CampaignStatus::REJECTED))->toBe(CampaignStatus::REJECTED);
|
|
});
|
|
|
|
it('returns null for an unknown value', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::make(99))->toBeNull();
|
|
});
|
|
|
|
it('implements equals correctly', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::CREATED->equals(CampaignStatus::CREATED))->toBeTrue()
|
|
->and(CampaignStatus::CREATED->equals(CampaignStatus::REJECTED))->toBeFalse()
|
|
->and(CampaignStatus::CREATED->equals(null))->toBeFalse();
|
|
});
|
|
|
|
it('serializes to json as its backing value', function (): void {
|
|
// THEN
|
|
expect(CampaignStatus::CREATED->jsonSerialize())->toBe(1)
|
|
->and(json_encode(CampaignStatus::CREATED))->toBe('1');
|
|
});
|
|
});
|