|
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,54 +590,60 @@ public function testCastAsJSONErrorUTF8()
|
589 | 590 |
|
590 | 591 | public function testCastAsJSONSyntaxError()
|
591 | 592 | {
|
592 |
| - $entity = new Entity(); |
593 |
| - |
594 |
| - $method = $this->getPrivateMethodInvoker($entity, 'castAsJson'); |
595 |
| - |
596 | 593 | $this->expectException(CastException::class);
|
597 | 594 | $this->expectExceptionMessage('Syntax error, malformed JSON');
|
598 | 595 |
|
599 |
| - $method('{ this is bad string', true); |
| 596 | + (Closure::bind(static function (string $value) { |
| 597 | + $entity = new Entity(); |
| 598 | + $entity->casts['dummy'] = 'json[array]'; |
| 599 | + |
| 600 | + return $entity->castAs($value, 'dummy'); |
| 601 | + }, null, Entity::class))('{ this is bad string'); |
600 | 602 | }
|
601 | 603 |
|
602 | 604 | public function testCastAsJSONAnotherErrorDepth()
|
603 | 605 | {
|
604 |
| - $entity = new Entity(); |
605 |
| - |
606 |
| - $method = $this->getPrivateMethodInvoker($entity, 'castAsJson'); |
607 |
| - |
608 | 606 | $this->expectException(CastException::class);
|
609 | 607 | $this->expectExceptionMessage('Maximum stack depth exceeded');
|
610 | 608 |
|
611 | 609 | $string = '{' . str_repeat('"test":{', 513) . '"test":"value"' . str_repeat('}', 513) . '}';
|
612 | 610 |
|
613 |
| - $method($string, true); |
| 611 | + (Closure::bind(static function (string $value) { |
| 612 | + $entity = new Entity(); |
| 613 | + $entity->casts['dummy'] = 'json[array]'; |
| 614 | + |
| 615 | + return $entity->castAs($value, 'dummy'); |
| 616 | + }, null, Entity::class))($string); |
614 | 617 | }
|
615 | 618 |
|
616 | 619 | public function testCastAsJSONControlCharCheck()
|
617 | 620 | {
|
618 |
| - $entity = new Entity(); |
619 |
| - $method = $this->getPrivateMethodInvoker($entity, 'castAsJson'); |
620 |
| - |
621 | 621 | $this->expectException(CastException::class);
|
622 | 622 | $this->expectExceptionMessage('Unexpected control character found');
|
623 | 623 |
|
624 | 624 | $string = "{\n\t\"property1\": \"The quick brown fox\njumps over the lazy dog\",\n\t\"property2\":\"value2\"\n}";
|
625 | 625 |
|
626 |
| - $method($string, true); |
| 626 | + (Closure::bind(static function (string $value) { |
| 627 | + $entity = new Entity(); |
| 628 | + $entity->casts['dummy'] = 'json[array]'; |
| 629 | + |
| 630 | + return $entity->castAs($value, 'dummy'); |
| 631 | + }, null, Entity::class))($string); |
627 | 632 | }
|
628 | 633 |
|
629 | 634 | public function testCastAsJSONStateMismatch()
|
630 | 635 | {
|
631 |
| - $entity = new Entity(); |
632 |
| - $method = $this->getPrivateMethodInvoker($entity, 'castAsJson'); |
633 |
| - |
634 | 636 | $this->expectException(CastException::class);
|
635 | 637 | $this->expectExceptionMessage('Underflow or the modes mismatch');
|
636 | 638 |
|
637 | 639 | $string = '[{"name":"jack","product_id":"1234"]';
|
638 | 640 |
|
639 |
| - $method($string, true); |
| 641 | + (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))($string); |
640 | 647 | }
|
641 | 648 |
|
642 | 649 | public function testCastSetter()
|
|
0 commit comments