@@ -704,6 +704,144 @@ public function testAssertWhereAllFailsWhenAtLeastOnePropDoesNotMatchValue()
704
704
]);
705
705
}
706
706
707
+ public function testAssertWhereTypeString ()
708
+ {
709
+ $ assert = AssertableJson::fromArray ([
710
+ 'foo ' => 'bar ' ,
711
+ ]);
712
+
713
+ $ assert ->whereType ('foo ' , 'string ' );
714
+ }
715
+
716
+ public function testAssertWhereTypeInteger ()
717
+ {
718
+ $ assert = AssertableJson::fromArray ([
719
+ 'foo ' => 123 ,
720
+ ]);
721
+
722
+ $ assert ->whereType ('foo ' , 'integer ' );
723
+ }
724
+
725
+ public function testAssertWhereTypeBoolean ()
726
+ {
727
+ $ assert = AssertableJson::fromArray ([
728
+ 'foo ' => true ,
729
+ ]);
730
+
731
+ $ assert ->whereType ('foo ' , 'boolean ' );
732
+ }
733
+
734
+ public function testAssertWhereTypeDouble ()
735
+ {
736
+ $ assert = AssertableJson::fromArray ([
737
+ 'foo ' => 12.3 ,
738
+ ]);
739
+
740
+ $ assert ->whereType ('foo ' , 'double ' );
741
+ }
742
+
743
+ public function testAssertWhereTypeArray ()
744
+ {
745
+ $ assert = AssertableJson::fromArray ([
746
+ 'foo ' => ['bar ' , 'baz ' ],
747
+ 'bar ' => ['foo ' => 'baz ' ],
748
+ ]);
749
+
750
+ $ assert ->whereType ('foo ' , 'array ' );
751
+ $ assert ->whereType ('bar ' , 'array ' );
752
+ }
753
+
754
+ public function testAssertWhereTypeNull ()
755
+ {
756
+ $ assert = AssertableJson::fromArray ([
757
+ 'foo ' => null ,
758
+ ]);
759
+
760
+ $ assert ->whereType ('foo ' , 'null ' );
761
+ }
762
+
763
+ public function testAssertWhereAllType ()
764
+ {
765
+ $ assert = AssertableJson::fromArray ([
766
+ 'one ' => 'foo ' ,
767
+ 'two ' => 123 ,
768
+ 'three ' => true ,
769
+ 'four ' => 12.3 ,
770
+ 'five ' => ['foo ' , 'bar ' ],
771
+ 'six ' => ['foo ' => 'bar ' ],
772
+ 'seven ' => null ,
773
+ ]);
774
+
775
+ $ assert ->whereAllType ([
776
+ 'one ' => 'string ' ,
777
+ 'two ' => 'integer ' ,
778
+ 'three ' => 'boolean ' ,
779
+ 'four ' => 'double ' ,
780
+ 'five ' => 'array ' ,
781
+ 'six ' => 'array ' ,
782
+ 'seven ' => 'null ' ,
783
+ ]);
784
+ }
785
+
786
+ public function testAssertWhereTypeWhenWrongTypeIsGiven ()
787
+ {
788
+ $ assert = AssertableJson::fromArray ([
789
+ 'foo ' => 'bar ' ,
790
+ ]);
791
+
792
+ $ this ->expectException (AssertionFailedError::class);
793
+ $ this ->expectExceptionMessage ('Property [foo] is not of expected type [integer]. ' );
794
+
795
+ $ assert ->whereType ('foo ' , 'integer ' );
796
+ }
797
+
798
+ public function testAssertWhereTypeWithUnionTypes ()
799
+ {
800
+ $ firstAssert = AssertableJson::fromArray ([
801
+ 'foo ' => 'bar ' ,
802
+ ]);
803
+
804
+ $ secondAssert = AssertableJson::fromArray ([
805
+ 'foo ' => null ,
806
+ ]);
807
+
808
+ $ firstAssert ->whereType ('foo ' , ['string ' , 'null ' ]);
809
+ $ secondAssert ->whereType ('foo ' , ['string ' , 'null ' ]);
810
+ }
811
+
812
+ public function testAssertWhereTypeWhenWrongUnionTypeIsGiven ()
813
+ {
814
+ $ assert = AssertableJson::fromArray ([
815
+ 'foo ' => 123 ,
816
+ ]);
817
+
818
+ $ this ->expectException (AssertionFailedError::class);
819
+ $ this ->expectExceptionMessage ('Property [foo] is not of expected type [string|null]. ' );
820
+
821
+ $ assert ->whereType ('foo ' , ['string ' , 'null ' ]);
822
+ }
823
+
824
+ public function testAssertWhereTypeWithPipeInUnionType ()
825
+ {
826
+ $ assert = AssertableJson::fromArray ([
827
+ 'foo ' => 'bar ' ,
828
+ ]);
829
+
830
+ $ assert ->whereType ('foo ' , 'string|null ' );
831
+ }
832
+
833
+ public function testAssertWhereTypeWithPipeInWrongUnionType ()
834
+ {
835
+ $ assert = AssertableJson::fromArray ([
836
+ 'foo ' => 'bar ' ,
837
+ ]);
838
+
839
+ $ this ->expectException (AssertionFailedError::class);
840
+ $ this ->expectExceptionMessage ('Property [foo] is not of expected type [integer|null]. ' );
841
+
842
+ $ assert ->whereType ('foo ' , 'integer|null ' );
843
+ }
844
+
707
845
public function testAssertHasAll ()
708
846
{
709
847
$ assert = AssertableJson::fromArray ([
0 commit comments