-
Notifications
You must be signed in to change notification settings - Fork 5
/
EnumsFromFixturesTest.php
131 lines (118 loc) · 4.74 KB
/
EnumsFromFixturesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
declare(strict_types=1);
namespace Yokai\EnumBundle\Tests\Unit;
use Generator;
use PHPUnit\Framework\TestCase;
use Yokai\EnumBundle\EnumInterface;
use Yokai\EnumBundle\Tests\Unit\Fixtures\Action;
use Yokai\EnumBundle\Tests\Unit\Fixtures\ActionEnum;
use Yokai\EnumBundle\Tests\Unit\Fixtures\StateEnum;
use Yokai\EnumBundle\Tests\Unit\Fixtures\Status;
use Yokai\EnumBundle\Tests\Unit\Fixtures\StatusEnum;
use Yokai\EnumBundle\Tests\Unit\Fixtures\SubscriptionEnum;
use Yokai\EnumBundle\Tests\Unit\Fixtures\TypeEnum;
use Yokai\EnumBundle\Tests\Unit\Fixtures\Vehicle;
use Yokai\EnumBundle\Tests\Unit\Fixtures\VehicleBrandEnum;
use Yokai\EnumBundle\Tests\Unit\Fixtures\VehicleEngineEnum;
use Yokai\EnumBundle\Tests\Unit\Fixtures\VehicleTypeEnum;
use Yokai\EnumBundle\Tests\Unit\Fixtures\VehicleWheelsEnum;
/**
* @author Yann Eugoné <eugone.yann@gmail.com>
*/
class EnumsFromFixturesTest extends TestCase
{
/**
* @dataProvider enums
*/
public function testEnum(EnumInterface $enum, string $name, array $choices): void
{
self::assertSame($name, $enum->getName());
self::assertEquals($choices, $enum->getChoices());
self::assertEquals(\array_values($choices), $enum->getValues());
foreach ($choices as $label => $value) {
self::assertSame($label, $enum->getLabel($value));
}
}
public function enums(): Generator
{
yield ActionEnum::class . ' : myclabs/php-enum translated enum' => [
new ActionEnum(new Translator([
'action.VIEW' => 'Voir',
'action.EDIT' => 'Modifier',
])),
ActionEnum::class,
['Voir' => Action::VIEW(), 'Modifier' => Action::EDIT()],
];
yield StateEnum::class . ' : direct interface implementation' => [
new StateEnum(),
StateEnum::class,
['New' => 'new', 'Validated' => 'validated', 'Disabled' => 'disabled'],
];
yield StatusEnum::class . ' : myclabs/php-enum enum' => [
new StatusEnum(),
StatusEnum::class,
['SUCCESS' => Status::SUCCESS(), 'ERROR' => Status::ERROR()],
];
yield SubscriptionEnum::class . ' : translated enum with keyword name' => [
new SubscriptionEnum(new Translator([
'choice.subscription.none' => 'Aucune',
'choice.subscription.daily' => 'Journalière',
'choice.subscription.weekly' => 'Hebdomadaire',
'choice.subscription.monthly' => 'Mensuelle',
])),
'subscription',
['Aucune' => 'none', 'Journalière' => 'daily', 'Hebdomadaire' => 'weekly', 'Mensuelle' => 'monthly'],
];
yield TypeEnum::class . ' : enum with keyword name' => [
new TypeEnum(),
'type',
['Customer' => 'customer', 'Prospect' => 'prospect'],
];
yield VehicleBrandEnum::class . ' : constant list enum with keyword name' => [
new VehicleBrandEnum(),
'vehicle.brand',
[
Vehicle::BRAND_RENAULT => Vehicle::BRAND_RENAULT,
Vehicle::BRAND_VOLKSWAGEN => Vehicle::BRAND_VOLKSWAGEN,
Vehicle::BRAND_TOYOTA => Vehicle::BRAND_TOYOTA,
],
];
yield VehicleEngineEnum::class . ' : translated constant list enum with keyword name' => [
new VehicleEngineEnum(new Translator([
'vehicle.engine.electic' => 'Électrique',
'vehicle.engine.combustion' => 'Combustion',
])),
'vehicle.engine',
[
'Électrique' => Vehicle::ENGINE_ELECTRIC,
'Combustion' => Vehicle::ENGINE_COMBUSTION,
],
];
yield VehicleTypeEnum::class . ' : translated constant list enum with class name' => [
new VehicleTypeEnum(new Translator([
'vehicle.type.bike' => 'Vélo',
'vehicle.type.car' => 'Voiture',
'vehicle.type.bus' => 'Bus',
])),
VehicleTypeEnum::class,
[
'Vélo' => Vehicle::TYPE_BIKE,
'Voiture' => Vehicle::TYPE_CAR,
'Bus' => Vehicle::TYPE_BUS,
],
];
yield VehicleWheelsEnum::class . ' : translated integer enum with class name' => [
new VehicleWheelsEnum(new Translator([
'vehicle.wheels.two' => 'Deux',
'vehicle.wheels.four' => 'Quatre',
'vehicle.wheels.eight' => 'Huit',
])),
VehicleWheelsEnum::class,
[
'Deux' => Vehicle::WHEELS_TWO,
'Quatre' => Vehicle::WHEELS_FOUR,
'Huit' => Vehicle::WHEELS_EIGHT,
],
];
}
}