value())->toBe(1) ->and(Country::BE->value())->toBe(2) ->and(Country::LU->value())->toBe(3); }); it('exposes its case name', function (): void { // THEN expect(Country::FR->name())->toBe('FR'); }); it('returns the defined label', function (): void { // THEN expect(Country::FR->label())->toBe('FR') ->and(Country::BE->label())->toBe('BE') ->and(Country::LU->label())->toBe('LU'); }); it('lists all labels keyed by case name', function (): void { // THEN expect(Country::toLabels())->toBe([ 'FR' => 'FR', 'BE' => 'BE', 'LU' => 'LU', ]); }); it('lists all values keyed by case name', function (): void { // THEN expect(Country::toValues())->toBe([ 'FR' => 1, 'BE' => 2, 'LU' => 3, ]); }); it('makes an instance from its backing value', function (): void { // THEN expect(Country::make(1))->toBe(Country::FR); }); it('makes an instance from a label', function (): void { // THEN expect(Country::make('BE', 'label'))->toBe(Country::BE); }); it('returns the same instance when already an enum case', function (): void { // THEN expect(Country::make(Country::LU))->toBe(Country::LU); }); it('returns null for an unknown value', function (): void { // THEN expect(Country::make(99))->toBeNull(); }); it('implements equals correctly', function (): void { // THEN expect(Country::FR->equals(Country::FR))->toBeTrue() ->and(Country::FR->equals(Country::BE))->toBeFalse() ->and(Country::FR->equals(null))->toBeFalse(); }); it('serializes to json as its backing value', function (): void { // THEN expect(Country::FR->jsonSerialize())->toBe(1) ->and(json_encode(Country::FR))->toBe('1'); }); });