@@ -693,4 +693,71 @@ public static function graphemeStrSplitDataProvider(): array
693
693
694
694
return $ cases ;
695
695
}
696
+
697
+ /**
698
+ * @requires extension bcmath
699
+ *
700
+ * @covers \Symfony\Polyfill\Php84\Php84::bcdivmod
701
+ *
702
+ * @dataProvider bcDivModProvider
703
+ */
704
+ public function testBcDivMod (string $ num1 , string $ num2 , ?int $ scale , array $ expected )
705
+ {
706
+ $ this ->assertSame ($ expected , bcdivmod ($ num1 , $ num2 , $ scale ));
707
+ }
708
+
709
+ /**
710
+ * @requires extension bcmath
711
+ */
712
+ public function testBcDivModDivideByZero ()
713
+ {
714
+ $ this ->expectException (\DivisionByZeroError::class);
715
+
716
+ bcdivmod ('1 ' , '0 ' );
717
+ }
718
+
719
+ /**
720
+ * @requires extension bcmath
721
+ */
722
+ public function testBcDivModDivideByFloatingZero ()
723
+ {
724
+ $ this ->expectException (\DivisionByZeroError::class);
725
+
726
+ bcdivmod ('1 ' , '0.00 ' );
727
+ }
728
+
729
+ /**
730
+ * @requires PHP 8.0
731
+ * @requires extension bcmath
732
+ */
733
+ public function testBcDivModMalformedNumber ()
734
+ {
735
+ $ this ->expectException (\ValueError::class);
736
+ $ this ->expectExceptionMessage ('Argument #1 ($num1) is not well-formed ' );
737
+
738
+ bcdivmod ('a ' , '1 ' );
739
+ }
740
+
741
+ /**
742
+ * @requires PHP 8.0
743
+ * @requires extension bcmath
744
+ */
745
+ public function testBcDivModMalformedNumber2 ()
746
+ {
747
+ $ this ->expectException (\ValueError::class);
748
+ $ this ->expectExceptionMessage ('Argument #2 ($num2) is not well-formed ' );
749
+
750
+ bcdivmod ('1 ' , 'a ' );
751
+ }
752
+
753
+ public static function bcDivModProvider (): iterable
754
+ {
755
+ yield ['1 ' , '1 ' , null , ['1 ' , '0 ' ]];
756
+ yield ['1 ' , '2 ' , null , ['0 ' , '1 ' ]];
757
+ yield ['5 ' , '2 ' , null , ['2 ' , '1 ' ]];
758
+ yield ['5 ' , '2 ' , 0 , ['2 ' , '1 ' ]];
759
+ yield ['5 ' , '2 ' , 1 , ['2 ' , '1.0 ' ]];
760
+ yield ['5 ' , '2 ' , 2 , ['2 ' , '1.00 ' ]];
761
+ yield ['7.2 ' , '3 ' , 2 , ['2 ' , '1.20 ' ]];
762
+ }
696
763
}
0 commit comments