11
11
12
12
namespace CodeIgniter \Entity ;
13
13
14
+ use Closure ;
14
15
use CodeIgniter \Entity \Exceptions \CastException ;
15
16
use CodeIgniter \HTTP \URI ;
16
17
use CodeIgniter \I18n \Time ;
@@ -589,34 +590,43 @@ public function testCastAsJSONErrorUTF8()
589
590
590
591
public function testCastAsJSONSyntaxError ()
591
592
{
592
- $ entity = new Entity ();
593
+ $ method = Closure::bind (static function (string $ value ) {
594
+ $ entity = new Entity ();
595
+ $ entity ->casts ['dummy ' ] = 'json[array] ' ;
593
596
594
- $ method = $ this ->getPrivateMethodInvoker ($ entity , 'castAsJson ' );
597
+ return $ entity ->castAs ($ value , 'dummy ' );
598
+ }, null , Entity::class);
595
599
596
600
$ this ->expectException (CastException::class);
597
601
$ this ->expectExceptionMessage ('Syntax error, malformed JSON ' );
598
602
599
- $ method ('{ this is bad string ' , true );
603
+ $ method ('{ this is bad string ' );
600
604
}
601
605
602
606
public function testCastAsJSONAnotherErrorDepth ()
603
607
{
604
- $ entity = new Entity ();
608
+ $ method = Closure::bind (static function (string $ value ) {
609
+ $ entity = new Entity ();
610
+ $ entity ->casts ['dummy ' ] = 'json[array] ' ;
605
611
606
- $ method = $ this ->getPrivateMethodInvoker ($ entity , 'castAsJson ' );
612
+ return $ entity ->castAs ($ value , 'dummy ' );
613
+ }, null , Entity::class);
607
614
608
615
$ this ->expectException (CastException::class);
609
616
$ this ->expectExceptionMessage ('Maximum stack depth exceeded ' );
610
617
611
618
$ string = '{ ' . str_repeat ('"test":{ ' , 513 ) . '"test":"value" ' . str_repeat ('} ' , 513 ) . '} ' ;
612
-
613
- $ method ($ string , true );
619
+ $ method ($ string );
614
620
}
615
621
616
622
public function testCastAsJSONControlCharCheck ()
617
623
{
618
- $ entity = new Entity ();
619
- $ method = $ this ->getPrivateMethodInvoker ($ entity , 'castAsJson ' );
624
+ $ method = Closure::bind (static function (string $ value ) {
625
+ $ entity = new Entity ();
626
+ $ entity ->casts ['dummy ' ] = 'json[array] ' ;
627
+
628
+ return $ entity ->castAs ($ value , 'dummy ' );
629
+ }, null , Entity::class);
620
630
621
631
$ this ->expectException (CastException::class);
622
632
$ this ->expectExceptionMessage ('Unexpected control character found ' );
@@ -628,8 +638,12 @@ public function testCastAsJSONControlCharCheck()
628
638
629
639
public function testCastAsJSONStateMismatch ()
630
640
{
631
- $ entity = new Entity ();
632
- $ method = $ this ->getPrivateMethodInvoker ($ entity , 'castAsJson ' );
641
+ $ method = Closure::bind (static function (string $ value ) {
642
+ $ entity = new Entity ();
643
+ $ entity ->casts ['dummy ' ] = 'json[array] ' ;
644
+
645
+ return $ entity ->castAs ($ value , 'dummy ' );
646
+ }, null , Entity::class);
633
647
634
648
$ this ->expectException (CastException::class);
635
649
$ this ->expectExceptionMessage ('Underflow or the modes mismatch ' );
0 commit comments