This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree 2 files changed +27
-3
lines changed 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -437,9 +437,10 @@ public function generate()
437
437
break ;
438
438
case self ::TYPE_OTHER :
439
439
default :
440
- throw new Exception \RuntimeException (
441
- sprintf ('Type "%s" is unknown or cannot be used as property default value. ' , get_class ($ value ))
442
- );
440
+ throw new Exception \RuntimeException (sprintf (
441
+ 'Type "%s" is unknown or cannot be used as property default value. ' ,
442
+ is_object ($ value ) ? get_class ($ value ) : gettype ($ value )
443
+ ));
443
444
}
444
445
445
446
return $ output ;
Original file line number Diff line number Diff line change 11
11
12
12
use ArrayAccess ;
13
13
use ArrayObject as SplArrayObject ;
14
+ use DateTime ;
15
+ use Generator ;
14
16
use PHPUnit \Framework \TestCase ;
15
17
use Zend \Code \Exception \InvalidArgumentException ;
18
+ use Zend \Code \Exception \RuntimeException ;
16
19
use Zend \Code \Generator \PropertyGenerator ;
17
20
use Zend \Code \Generator \PropertyValueGenerator ;
18
21
use Zend \Code \Generator \ValueGenerator ;
@@ -462,4 +465,24 @@ public function getEscapedParameters()
462
465
["\\' " , "\\\\\\' " ],
463
466
];
464
467
}
468
+
4
A39A
69
+ public function invalidValue () : Generator
470
+ {
471
+ yield 'object ' => [new DateTime (), DateTime::class];
472
+ yield 'resource ' => [fopen ('php://input ' , 'r ' ), 'resource ' ];
473
+ }
474
+
475
+ /**
476
+ * @dataProvider invalidValue
477
+ *
478
+ * @param mixed $value
479
+ */
480
+ public function testExceptionInvalidValue ($ value , string $ type ) : void
481
+ {
482
+ $ valueGenerator = new ValueGenerator ($ value );
483
+
484
+ $ this ->expectException (RuntimeException::class);
485
+ $ this ->expectExceptionMessage ('Type " ' .$ type .'" is unknown or cannot be used ' );
486
+ $ valueGenerator ->generate ();
487
+ }
465
488
}
You can’t perform that action at this time.
0 commit comments