@@ -176,7 +176,7 @@ public function testGetJsonSchema(): void
176
176
177
177
// Check required fields
178
178
$ this ->assertArrayHasKey ('required ' , $ schema );
179
- $ this ->assertEquals ([SupportedOption::KEY_NAME , SupportedOption:: KEY_SUPPORTED_VALUES ], $ schema ['required ' ]);
179
+ $ this ->assertEquals ([SupportedOption::KEY_NAME ], $ schema ['required ' ]);
180
180
}
181
181
182
182
/**
@@ -408,5 +408,114 @@ public function testImplementsCorrectInterfaces(): void
408
408
$ option
409
409
);
410
410
}
411
+
412
+ /**
413
+ * Tests with null supportedValues (any value is supported).
414
+ *
415
+ * @return void
416
+ */
417
+ public function testWithNullSupportedValues (): void
418
+ {
419
+ $ option = new SupportedOption ('any_value_option ' );
420
+
421
+ $ this ->assertEquals ('any_value_option ' , $ option ->getName ());
422
+ $ this ->assertNull ($ option ->getSupportedValues ());
423
+
424
+ // Any value should be supported when supportedValues is null
425
+ $ this ->assertTrue ($ option ->isSupportedValue ('string ' ));
426
+ $ this ->assertTrue ($ option ->isSupportedValue (123 ));
427
+ $ this ->assertTrue ($ option ->isSupportedValue (45.67 ));
428
+ $ this ->assertTrue ($ option ->isSupportedValue (true ));
429
+ $ this ->assertTrue ($ option ->isSupportedValue (false ));
430
+ $ this ->assertTrue ($ option ->isSupportedValue (null ));
431
+ $ this ->assertTrue ($ option ->isSupportedValue (['array ' ]));
432
+ $ this ->assertTrue ($ option ->isSupportedValue (['key ' => 'value ' ]));
433
+ $ this ->assertTrue ($ option ->isSupportedValue (new \stdClass ()));
434
+ }
435
+
436
+ /**
437
+ * Tests toArray with null supportedValues.
438
+ *
439
+ * @return void
440
+ */
441
+ public function testToArrayWithNullSupportedValues (): void
442
+ {
443
+ $ option = new SupportedOption ('flexible_option ' );
444
+ $ array = $ option ->toArray ();
445
+
446
+ $ this ->assertIsArray ($ array );
447
+ $ this ->assertEquals ('flexible_option ' , $ array [SupportedOption::KEY_NAME ]);
448
+ $ this ->assertArrayNotHasKey (SupportedOption::KEY_SUPPORTED_VALUES , $ array );
449
+ $ this ->assertCount (1 , $ array );
450
+ }
451
+
452
+ /**
453
+ * Tests fromArray with missing supportedValues.
454
+ *
455
+ * @return void
456
+ */
457
+ public function testFromArrayWithMissingSupportedValues (): void
458
+ {
459
+ $ data = [
460
+ SupportedOption::KEY_NAME => 'open_option '
461
+ ];
462
+
463
+ $ option = SupportedOption::fromArray ($ data );
464
+
465
+ $ this ->assertInstanceOf (SupportedOption::class, $ option );
466
+ $ this ->assertEquals ('open_option ' , $ option ->getName ());
467
+ $ this ->assertNull ($ option ->getSupportedValues ());
468
+ $ this ->assertTrue ($ option ->isSupportedValue ('anything ' ));
469
+ }
470
+
471
+ /**
472
+ * Tests round-trip with null supportedValues.
473
+ *
474
+ * @return void
475
+ */
476
+ public function testRoundTripWithNullSupportedValues (): void
477
+ {
478
+ $ original = new SupportedOption ('unrestricted ' );
479
+
480
+ $ array = $ original ->toArray ();
481
+ $ restored = SupportedOption::fromArray ($ array );
482
+
483
+ $ this ->assertEquals ($ original ->getName (), $ restored ->getName ());
484
+ $ this ->assertEquals ($ original ->getSupportedValues (), $ restored ->getSupportedValues ());
485
+ $ this ->assertNull ($ restored ->getSupportedValues ());
486
+ }
487
+
488
+ /**
489
+ * Tests JSON serialization with null supportedValues.
490
+ *
491
+ * @return void
492
+ */
493
+ public function testJsonSerializationWithNullSupportedValues (): void
494
+ {
495
+ $ option = new SupportedOption ('json_option ' );
496
+
497
+ $ json = json_encode ($ option );
498
+ $ decoded = json_decode ($ json , true );
499
+
500
+ $ this ->assertIsString ($ json );
501
+ $ this ->assertIsArray ($ decoded );
502
+ $ this ->assertEquals ('json_option ' , $ decoded [SupportedOption::KEY_NAME ]);
503
+ $ this ->assertArrayNotHasKey (SupportedOption::KEY_SUPPORTED_VALUES , $ decoded );
504
+ }
505
+
506
+ /**
507
+ * Tests JSON schema reflects optional supportedValues.
508
+ *
509
+ * @return void
510
+ */
511
+ public function testJsonSchemaReflectsOptionalSupportedValues (): void
512
+ {
513
+ $ schema = SupportedOption::getJsonSchema ();
514
+
515
+ // Check that supportedValues is not in required fields
516
+ $ this ->assertArrayHasKey ('required ' , $ schema );
517
+ $ this ->assertEquals ([SupportedOption::KEY_NAME ], $ schema ['required ' ]);
518
+ $ this ->assertNotContains (SupportedOption::KEY_SUPPORTED_VALUES , $ schema ['required ' ]);
519
+ }
411
520
}
412
521
0 commit comments