@@ -813,6 +813,131 @@ function ($i) {
813
813
);
814
814
}
815
815
816
+ /**
817
+ * @group withCount
818
+ */
819
+ public function testWithCount ()
820
+ {
821
+ Helper::clearClass ('BoxedNumber ' );
822
+ $ this ->saveObjects (
823
+ 3 ,
824
+ function ($ i ) {
825
+ $ boxedNumber = ParseObject::create ('BoxedNumber ' );
826
+ $ boxedNumber ->set ('x ' , $ i + 1 );
827
+
828
+ return $ boxedNumber ;
829
+ }
830
+ );
831
+ $ query = new ParseQuery ('BoxedNumber ' );
832
+ $ query ->withCount ();
833
+ $ response = $ query ->find ();
834
+ $ this ->assertEquals ($ response ['count ' ], 3 );
835
+ $ this ->assertEquals (count ($ response ['results ' ]), 3 );
836
+ }
837
+
838
+ /**
839
+ * @group withCount
840
+ */
841
+ public function testWithCountDestructure ()
842
+ {
843
+ Helper::clearClass ('BoxedNumber ' );
844
+ $ this ->saveObjects (
845
+ 3 ,
846
+ function ($ i ) {
847
+ $ boxedNumber = ParseObject::create ('BoxedNumber ' );
848
+ $ boxedNumber ->set ('x ' , $ i + 1 );
849
+
850
+ return $ boxedNumber ;
851
+ }
852
+ );
853
+ $ query = new ParseQuery ('BoxedNumber ' );
854
+ $ query ->withCount ();
855
+ ['count ' => $ count , 'results ' => $ results ] = $ query ->find ();
856
+ $ this ->assertEquals ($ count , 3 );
857
+ $ this ->assertEquals (count ($ results ), 3 );
858
+ }
859
+
860
+ /**
861
+ * @group withCount
862
+ */
863
+ public function testWithCountFalse ()
864
+ {
865
+ Helper::clearClass ('BoxedNumber ' );
866
+ $ this ->saveObjects (
867
+ 3 ,
868
+ function ($ i ) {
869
+ $ boxedNumber = ParseObject::create ('BoxedNumber ' );
870
+ $ boxedNumber ->set ('x ' , $ i + 1 );
871
+
872
+ return $ boxedNumber ;
873
+ }
874
+ );
875
+ $ query = new ParseQuery ('BoxedNumber ' );
876
+ $ query ->withCount (false );
877
+ $ response = $ query ->find ();
878
+ $ this ->assertEquals (isset ($ response ['count ' ]), false );
879
+ $ this ->assertEquals (count ($ response ), 3 );
880
+ }
881
+
882
+ /**
883
+ * @group withCount
884
+ */
885
+ public function testWithCountEmptyClass ()
886
+ {
887
+ Helper::clearClass ('BoxedNumber ' );
888
+ $ query = new ParseQuery ('BoxedNumber ' );
889
+ $ query ->withCount ();
890
+ $ response = $ query ->find ();
891
+ $ this ->assertEquals ($ response ['count ' ], 0 );
892
+ $ this ->assertEquals (count ($ response ['results ' ]), 0 );
893
+ }
894
+
895
+ /**
896
+ * @group withCount
897
+ */
898
+ public function testWithCountAndLimit ()
899
+ {
900
+ Helper::clearClass ('BoxedNumber ' );
901
+ $ this ->saveObjects (
902
+ 4 ,
903
+ function ($ i ) {
904
+ $ boxedNumber = ParseObject::create ('BoxedNumber ' );
905
+ $ boxedNumber ->set ('x ' , $ i + 1 );
906
+
907
+ return $ boxedNumber ;
908
+ }
909
+ );
910
+ $ query = new ParseQuery ('BoxedNumber ' );
911
+ $ query ->withCount ();
912
+ $ query ->limit (2 );
913
+ $ response = $ query ->find ();
914
+ $ this ->assertEquals ($ response ['count ' ], 4 );
915
+ $ this ->assertEquals (count ($ response ['results ' ]), 2 );
916
+ }
917
+
918
+ /**
919
+ * @group withCount
920
+ */
921
+ public function testWithCountAndSkip ()
922
+ {
923
+ Helper::clearClass ('BoxedNumber ' );
924
+ $ this ->saveObjects (
925
+ 4 ,
926
+ function ($ i ) {
927
+ $ boxedNumber = ParseObject::create ('BoxedNumber ' );
928
+ $ boxedNumber ->set ('x ' , $ i + 1 );
929
+
930
+ return $ boxedNumber ;
931
+ }
932
+ );
933
+ $ query = new ParseQuery ('BoxedNumber ' );
934
+ $ query ->withCount ();
935
+ $ query ->skip (3 );
936
+ $ response = $ query ->find ();
937
+ $ this ->assertEquals ($ response ['count ' ], 4 );
938
+ $ this ->assertEquals (count ($ response ['results ' ]), 1 );
939
+ }
940
+
816
941
public function testCountError ()
817
942
{
818
943
$ query = new ParseQuery ('Test ' );
0 commit comments