File tree 2 files changed +28
-2
lines changed
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ public function __construct($value)
68
68
$ value = $ value ->getValue ();
69
69
}
70
70
71
- $ this ->key = static ::assertValidValue ($ value );
71
+ $ this ->key = static ::assertValidValueReturningKey ($ value );
72
72
73
73
/** @psalm-var T */
74
74
$ this ->value = $ value ;
@@ -213,7 +213,18 @@ public static function isValid($value)
213
213
* @psalm-pure
214
214
* @psalm-assert T $value
215
215
*/
216
- private static function assertValidValue ($ value ): string
216
+ public static function assertValidValue ($ value ): void
217
+ {
218
+ self ::assertValidValueReturningKey ($ value );
219
+ }
220
+
221
+ /**
222
+ * Asserts valid enum value
223
+ *
224
+ * @psalm-pure
225
+ * @psalm-assert T $value
226
+ */
227
+ private static function assertValidValueReturningKey ($ value ): string
217
228
{
218
229
if (false === ($ key = static ::search ($ value ))) {
219
230
throw new \UnexpectedValueException ("Value ' $ value' is not part of the enum " . static ::class);
Original file line number Diff line number Diff line change @@ -369,4 +369,19 @@ public function testEnumValuesInheritance()
369
369
$ inheritedEnumFixture = InheritedEnumFixture::VALUE ();
370
370
new EnumFixture ($ inheritedEnumFixture );
371
371
}
372
+
373
+ /**
374
+ * @dataProvider isValidProvider
375
+ */
376
+ public function testAssertValidValue ($ value , $ isValid ): void
377
+ {
378
+ if (!$ isValid ) {
379
+ $ this ->expectException (\UnexpectedValueException::class);
380
+ $ this ->expectExceptionMessage ("Value ' $ value' is not part of the enum " . EnumFixture::class);
381
+ }
382
+
383
+ EnumFixture::assertValidValue ($ value );
384
+
385
+ self ::assertTrue (EnumFixture::isValid ($ value ));
386
+ }
372
387
}
You can’t perform that action at this time.
0 commit comments