|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use DevWizardHQ\Enumify\Tests\Fixtures\CampusStatus; |
| 6 | +use DevWizardHQ\Enumify\Tests\Fixtures\OrderStatus; |
| 7 | +use DevWizardHQ\Enumify\Tests\Fixtures\PaymentMethod; |
| 8 | + |
| 9 | +it('returns options as value => label pairs', function () { |
| 10 | + $options = PaymentMethod::options(); |
| 11 | + |
| 12 | + expect($options)->toBe([ |
| 13 | + 'credit_card' => 'Credit Card', |
| 14 | + 'debit_card' => 'Debit Card', |
| 15 | + 'bank_transfer' => 'Bank Transfer', |
| 16 | + 'paypal' => 'PayPal', |
| 17 | + 'crypto' => 'Cryptocurrency', |
| 18 | + ]); |
| 19 | +}); |
| 20 | + |
| 21 | +it('returns options using a custom method name', function () { |
| 22 | + $options = CampusStatus::options('color'); |
| 23 | + |
| 24 | + expect($options)->toBe([ |
| 25 | + 'active' => 'green', |
| 26 | + 'suspended' => 'red', |
| 27 | + 'inactive' => 'gray', |
| 28 | + ]); |
| 29 | +}); |
| 30 | + |
| 31 | +it('falls back to humanized case name when label method does not exist', function () { |
| 32 | + $options = OrderStatus::options(); |
| 33 | + |
| 34 | + expect($options)->toBe([ |
| 35 | + 'pending' => 'Pending', |
| 36 | + 'processing' => 'Processing', |
| 37 | + 'shipped' => 'Shipped', |
| 38 | + 'delivered' => 'Delivered', |
| 39 | + 'cancelled' => 'Cancelled', |
| 40 | + ]); |
| 41 | +}); |
| 42 | + |
| 43 | +it('returns select options as value/label arrays', function () { |
| 44 | + $options = PaymentMethod::selectOptions(); |
| 45 | + |
| 46 | + expect($options)->toBe([ |
| 47 | + ['value' => 'credit_card', 'label' => 'Credit Card'], |
| 48 | + ['value' => 'debit_card', 'label' => 'Debit Card'], |
| 49 | + ['value' => 'bank_transfer', 'label' => 'Bank Transfer'], |
| 50 | + ['value' => 'paypal', 'label' => 'PayPal'], |
| 51 | + ['value' => 'crypto', 'label' => 'Cryptocurrency'], |
| 52 | + ]); |
| 53 | +}); |
| 54 | + |
| 55 | +it('returns select options using a custom method name', function () { |
| 56 | + $options = CampusStatus::selectOptions('color'); |
| 57 | + |
| 58 | + expect($options)->toBe([ |
| 59 | + ['value' => 'active', 'label' => 'green'], |
| 60 | + ['value' => 'suspended', 'label' => 'red'], |
| 61 | + ['value' => 'inactive', 'label' => 'gray'], |
| 62 | + ]); |
| 63 | +}); |
| 64 | + |
| 65 | +it('falls back to humanized case name in select options when method does not exist', function () { |
| 66 | + $options = OrderStatus::selectOptions(); |
| 67 | + |
| 68 | + expect($options)->toBe([ |
| 69 | + ['value' => 'pending', 'label' => 'Pending'], |
| 70 | + ['value' => 'processing', 'label' => 'Processing'], |
| 71 | + ['value' => 'shipped', 'label' => 'Shipped'], |
| 72 | + ['value' => 'delivered', 'label' => 'Delivered'], |
| 73 | + ['value' => 'cancelled', 'label' => 'Cancelled'], |
| 74 | + ]); |
| 75 | +}); |
| 76 | + |
| 77 | +it('returns all enum values', function () { |
| 78 | + expect(PaymentMethod::values())->toBe([ |
| 79 | + 'credit_card', |
| 80 | + 'debit_card', |
| 81 | + 'bank_transfer', |
| 82 | + 'paypal', |
| 83 | + 'crypto', |
| 84 | + ]); |
| 85 | +}); |
| 86 | + |
| 87 | +it('returns all enum names', function () { |
| 88 | + expect(PaymentMethod::names())->toBe([ |
| 89 | + 'CREDIT_CARD', |
| 90 | + 'DEBIT_CARD', |
| 91 | + 'BANK_TRANSFER', |
| 92 | + 'PAYPAL', |
| 93 | + 'CRYPTO', |
| 94 | + ]); |
| 95 | +}); |
| 96 | + |
| 97 | +it('checks if a value exists', function () { |
| 98 | + expect(PaymentMethod::hasValue('credit_card'))->toBeTrue(); |
| 99 | + expect(PaymentMethod::hasValue('nonexistent'))->toBeFalse(); |
| 100 | +}); |
| 101 | + |
| 102 | +it('uses strict comparison for hasValue', function () { |
| 103 | + expect(PaymentMethod::hasValue(''))->toBeFalse(); |
| 104 | +}); |
0 commit comments