81 lines
2.5 KiB
PHP
81 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Shared\Enums;
|
|
|
|
use Domain\Enums\BarcodeFormat;
|
|
|
|
covers(BarcodeFormat::class);
|
|
|
|
describe('barcode format', function (): void {
|
|
it('has the expected cases with their backing values', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::EAN13->value())->toBe(1)
|
|
->and(BarcodeFormat::CODE128->value())->toBe(2)
|
|
->and(BarcodeFormat::GS1_128->value())->toBe(3);
|
|
});
|
|
|
|
it('exposes its case name', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::EAN13->name())->toBe('EAN13');
|
|
});
|
|
|
|
it('returns the defined label', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::EAN13->label())->toBe('EAN')
|
|
->and(BarcodeFormat::CODE128->label())->toBe('CODE 128')
|
|
->and(BarcodeFormat::GS1_128->label())->toBe('GS1_128');
|
|
});
|
|
|
|
it('lists all labels keyed by case name', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::toLabels())->toBe([
|
|
'EAN13' => 'EAN',
|
|
'CODE128' => 'CODE 128',
|
|
'GS1_128' => 'GS1_128',
|
|
]);
|
|
});
|
|
|
|
it('lists all values keyed by case name', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::toValues())->toBe([
|
|
'EAN13' => 1,
|
|
'CODE128' => 2,
|
|
'GS1_128' => 3,
|
|
]);
|
|
});
|
|
|
|
it('makes an instance from its backing value', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::make(1))->toBe(BarcodeFormat::EAN13);
|
|
});
|
|
|
|
it('makes an instance from a label', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::make('CODE 128', 'label'))->toBe(BarcodeFormat::CODE128);
|
|
});
|
|
|
|
it('returns the same instance when already an enum case', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::make(BarcodeFormat::GS1_128))->toBe(BarcodeFormat::GS1_128);
|
|
});
|
|
|
|
it('returns null for an unknown value', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::make(99))->toBeNull();
|
|
});
|
|
|
|
it('implements equals correctly', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::EAN13->equals(BarcodeFormat::EAN13))->toBeTrue()
|
|
->and(BarcodeFormat::EAN13->equals(BarcodeFormat::CODE128))->toBeFalse()
|
|
->and(BarcodeFormat::EAN13->equals(null))->toBeFalse();
|
|
});
|
|
|
|
it('serializes to json as its backing value', function (): void {
|
|
// THEN
|
|
expect(BarcodeFormat::EAN13->jsonSerialize())->toBe(1)
|
|
->and(json_encode(BarcodeFormat::EAN13))->toBe('1');
|
|
});
|
|
});
|