summaryrefslogtreecommitdiff
path: root/ext/standard/tests
diff options
context:
space:
mode:
authorkharhamel <oognic@gmail.com>2019-10-15 17:51:39 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-10-28 11:58:59 +0100
commit82dc9a31c335d8cf7aff68d76698bc3d24f761f8 (patch)
tree20bf9e2500ad33927810b24015ef74a20740c2a4 /ext/standard/tests
parent9d48bf5152295fb63ab5da8570c9b2fd73aa2cf7 (diff)
downloadphp-git-82dc9a31c335d8cf7aff68d76698bc3d24f761f8.tar.gz
Convert warnings to Errors in sprintf() functions
Closes GH-4837.
Diffstat (limited to 'ext/standard/tests')
-rw-r--r--ext/standard/tests/file/fscanf_variation14.phpt8
-rw-r--r--ext/standard/tests/strings/printf_64bit.phpt10
-rw-r--r--ext/standard/tests/strings/printf_error.phpt60
-rw-r--r--ext/standard/tests/strings/sprintf_error.phpt60
-rw-r--r--ext/standard/tests/strings/vfprintf_error4.phpt11
-rw-r--r--ext/standard/tests/strings/vfprintf_variation21.phpt21
-rw-r--r--ext/standard/tests/strings/vprintf_variation2.phpt35
-rw-r--r--ext/standard/tests/strings/vsprintf_variation2.phpt26
8 files changed, 122 insertions, 109 deletions
diff --git a/ext/standard/tests/file/fscanf_variation14.phpt b/ext/standard/tests/file/fscanf_variation14.phpt
index 47caaa3568..151c975776 100644
--- a/ext/standard/tests/file/fscanf_variation14.phpt
+++ b/ext/standard/tests/file/fscanf_variation14.phpt
@@ -76,8 +76,12 @@ $counter = 1;
// writing to the file
foreach($valid_strings as $string) {
- @fprintf($file_handle, $string);
- @fprintf($file_handle, "\n");
+ try {
+ fprintf($file_handle, $string);
+ } catch (\ValueError $e) {
+ } catch (\ArgumentCountError $e) {
+ }
+ fprintf($file_handle, "\n");
}
// closing the file
fclose($file_handle);
diff --git a/ext/standard/tests/strings/printf_64bit.phpt b/ext/standard/tests/strings/printf_64bit.phpt
index 0106f71445..9d3b448495 100644
--- a/ext/standard/tests/strings/printf_64bit.phpt
+++ b/ext/standard/tests/strings/printf_64bit.phpt
@@ -39,7 +39,11 @@ echo "\n*** Output for insufficient number of arguments ***\n";
$string = "dingy%sflem%dwombat";
$nbr = 5;
$name = "voudras";
-printf("%d $string %s", $nbr, $name);
+try {
+ printf("%d $string %s", $nbr, $name);
+} catch (\ArgumentCountError $e) {
+ print('Error found: '.$e->getMessage());
+}
/* Scalar argument */
@@ -233,9 +237,7 @@ printf("%d", $tempstring);
printf() expects at least 1 parameter, 0 given
*** Output for insufficient number of arguments ***
-
-Warning: printf(): Too few arguments in %s on line %d
-
+Error found: 5 parameters are required, 3 given
*** Output for scalar argument ***
3
*** Output for NULL as argument ***
diff --git a/ext/standard/tests/strings/printf_error.phpt b/ext/standard/tests/strings/printf_error.phpt
index aff95426e6..e5bd8c7e21 100644
--- a/ext/standard/tests/strings/printf_error.phpt
+++ b/ext/standard/tests/strings/printf_error.phpt
@@ -25,16 +25,40 @@ $arg1 = 'one';
$arg2 = 'two';
echo "\n-- Call printf with one argument less than expected --\n";
-var_dump( printf($format1) );
-var_dump( printf($format2,$arg1) );
-var_dump( printf($format3,$arg1,$arg2) );
+try {
+ var_dump( printf($format1) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump( printf($format2,$arg1) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump( printf($format3,$arg1,$arg2) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
echo "\n-- Call printf with two argument less than expected --\n";
-var_dump( printf($format2) );
-var_dump( printf($format3,$arg1) );
+try {
+ var_dump( printf($format2) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump( printf($format3,$arg1) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
echo "\n-- Call printf with three argument less than expected --\n";
-var_dump( printf($format3) );
+try {
+ var_dump( printf($format3) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
?>
===DONE===
@@ -47,26 +71,14 @@ printf() expects at least 1 parameter, 0 given
-- Testing printf() function with less than expected no. of arguments --
-- Call printf with one argument less than expected --
-
-Warning: printf(): Too few arguments in %s on line %d
-bool(false)
-
-Warning: printf(): Too few arguments in %s on line %d
-bool(false)
-
-Warning: printf(): Too few arguments in %s on line %d
-bool(false)
+2 parameters are required, 1 given
+3 parameters are required, 2 given
+4 parameters are required, 3 given
-- Call printf with two argument less than expected --
-
-Warning: printf(): Too few arguments in %s on line %d
-bool(false)
-
-Warning: printf(): Too few arguments in %s on line %d
-bool(false)
+3 parameters are required, 1 given
+4 parameters are required, 2 given
-- Call printf with three argument less than expected --
-
-Warning: printf(): Too few arguments in %s on line %d
-bool(false)
+4 parameters are required, 1 given
===DONE===
diff --git a/ext/standard/tests/strings/sprintf_error.phpt b/ext/standard/tests/strings/sprintf_error.phpt
index 1b21b8b141..4ba7a539fe 100644
--- a/ext/standard/tests/strings/sprintf_error.phpt
+++ b/ext/standard/tests/strings/sprintf_error.phpt
@@ -25,16 +25,40 @@ $arg1 = 'one';
$arg2 = 'two';
// with one argument less than expected
-var_dump( sprintf($format1) );
-var_dump( sprintf($format2,$arg1) );
-var_dump( sprintf($format3,$arg1,$arg2) );
+try {
+ var_dump( sprintf($format1) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump( sprintf($format2,$arg1) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump( sprintf($format3,$arg1,$arg2) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
// with two argument less than expected
-var_dump( sprintf($format2) );
-var_dump( sprintf($format3,$arg1) );
+try {
+ var_dump( sprintf($format2) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ var_dump( sprintf($format3,$arg1) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
// with three argument less than expected
-var_dump( sprintf($format3) );
+try {
+ var_dump( sprintf($format3) );
+} catch (\ArgumentCountError $e) {
+ echo $e->getMessage(), "\n";
+}
echo "Done";
?>
@@ -45,22 +69,10 @@ echo "Done";
sprintf() expects at least %d parameter, %d given
-- Testing sprintf() function with less than expected no. of arguments --
-
-Warning: sprintf(): Too few arguments in %s on line %d
-bool(false)
-
-Warning: sprintf(): Too few arguments in %s on line %d
-bool(false)
-
-Warning: sprintf(): Too few arguments in %s on line %d
-bool(false)
-
-Warning: sprintf(): Too few arguments in %s on line %d
-bool(false)
-
-Warning: sprintf(): Too few arguments in %s on line %d
-bool(false)
-
-Warning: sprintf(): Too few arguments in %s on line %d
-bool(false)
+2 parameters are required, 1 given
+3 parameters are required, 2 given
+4 parameters are required, 3 given
+3 parameters are required, 1 given
+4 parameters are required, 2 given
+4 parameters are required, 1 given
Done
diff --git a/ext/standard/tests/strings/vfprintf_error4.phpt b/ext/standard/tests/strings/vfprintf_error4.phpt
index e54e34f4cd..9ccd83b2d8 100644
--- a/ext/standard/tests/strings/vfprintf_error4.phpt
+++ b/ext/standard/tests/strings/vfprintf_error4.phpt
@@ -22,8 +22,11 @@ try {
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
-var_dump( vfprintf( $fp, 'Foo %$c-0202Sd', array( 2 ) ) );
-
+try {
+ var_dump( vfprintf( $fp, 'Foo %$c-0202Sd', array( 2 ) ) );
+} catch(\ValueError $e) {
+ print('Error found: '.$e->getMessage().".\n");
+}
// Close handle
fclose( $fp );
@@ -39,7 +42,5 @@ unlink( $file );
--EXPECTF--
-- Testing vfprintf() function with other strangeties --
vfprintf() expects parameter 1 to be resource, string given
-
-Warning: vfprintf(): Argument number must be greater than zero in %s on line %d
-bool(false)
+Error found: Argument number must be greater than zero.
===DONE===
diff --git a/ext/standard/tests/strings/vfprintf_variation21.phpt b/ext/standard/tests/strings/vfprintf_variation21.phpt
index 11f29e87ac..1358154f95 100644
--- a/ext/standard/tests/strings/vfprintf_variation21.phpt
+++ b/ext/standard/tests/strings/vfprintf_variation21.phpt
@@ -90,7 +90,11 @@ fprintf($fp, "\n*** Testing vprintf() with unexpected values for args argument *
$counter = 1;
foreach( $values as $value ) {
fprintf($fp, "\n-- Iteration %d --\n",$counter);
- vfprintf($fp, $format, $value);
+ try {
+ vfprintf($fp, $format, $value);
+ } catch (\ValueError $e) {
+ fwrite($fp, $e->getMessage() . "\n");
+ }
$counter++;
}
@@ -106,16 +110,6 @@ unlink($data_file);
--EXPECTF--
*** Testing vfprintf() : with unexpected values for args argument ***
-Warning: vfprintf(): Too few arguments in %s on line %d
-
-Warning: vfprintf(): Too few arguments in %s on line %d
-
-Warning: vfprintf(): Too few arguments in %s on line %d
-
-Warning: vfprintf(): Too few arguments in %s on line %d
-
-Warning: vfprintf(): Too few arguments in %s on line %d
-
*** Testing vprintf() with unexpected values for args argument ***
-- Iteration 1 --
@@ -137,8 +131,10 @@ Warning: vfprintf(): Too few arguments in %s on line %d
-- Iteration 9 --
0.5
-- Iteration 10 --
+The arguments array must contain 1 items, 0 given
-- Iteration 11 --
+The arguments array must contain 1 items, 0 given
-- Iteration 12 --
1
@@ -157,10 +153,13 @@ string
-- Iteration 19 --
string
-- Iteration 20 --
+The arguments array must contain 1 items, 0 given
-- Iteration 21 --
+The arguments array must contain 1 items, 0 given
-- Iteration 22 --
+The arguments array must contain 1 items, 0 given
-- Iteration 23 --
Resource id #%d
diff --git a/ext/standard/tests/strings/vprintf_variation2.phpt b/ext/standard/tests/strings/vprintf_variation2.phpt
index 69e17d21a7..a26d3590bc 100644
--- a/ext/standard/tests/strings/vprintf_variation2.phpt
+++ b/ext/standard/tests/strings/vprintf_variation2.phpt
@@ -84,9 +84,13 @@ $values = array(
$counter = 1;
foreach($values as $value) {
echo "\n-- Iteration $counter --\n";
- $result = vprintf($format,$value);
- echo "\n";
- var_dump($result);
+ try {
+ $result = vprintf($format,$value);
+ echo "\n";
+ var_dump($result);
+ } catch (\ValueError $e) {
+ echo $e->getMessage(), "\n";
+ }
$counter++;
};
@@ -135,16 +139,10 @@ int(13)
int(3)
-- Iteration 10 --
-
-Warning: vprintf(): Too few arguments in %s on line %d
-
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 11 --
-
-Warning: vprintf(): Too few arguments in %s on line %d
-
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 12 --
1
@@ -179,22 +177,13 @@ string
int(6)
-- Iteration 20 --
-
-Warning: vprintf(): Too few arguments in %s on line %d
-
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 21 --
-
-Warning: vprintf(): Too few arguments in %s on line %d
-
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 22 --
-
-Warning: vprintf(): Too few arguments in %s on line %d
-
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 23 --
Resource id #%d
diff --git a/ext/standard/tests/strings/vsprintf_variation2.phpt b/ext/standard/tests/strings/vsprintf_variation2.phpt
index 838093cdb1..3af9b854fe 100644
--- a/ext/standard/tests/strings/vsprintf_variation2.phpt
+++ b/ext/standard/tests/strings/vsprintf_variation2.phpt
@@ -84,7 +84,11 @@ $values = array(
$counter = 1;
foreach($values as $value) {
echo "\n-- Iteration $counter --\n";
- var_dump( vsprintf($format,$value) );
+ try {
+ var_dump( vsprintf($format,$value) );
+ } catch (\ValueError $e) {
+ echo $e->getMessage(), "\n";
+ }
$counter++;
};
@@ -124,14 +128,10 @@ string(13) "1.07654321E-9"
string(3) "0.5"
-- Iteration 10 --
-
-Warning: vsprintf(): Too few arguments in %s on line %d
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 11 --
-
-Warning: vsprintf(): Too few arguments in %s on line %d
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 12 --
string(1) "1"
@@ -158,19 +158,13 @@ string(6) "string"
string(6) "string"
-- Iteration 20 --
-
-Warning: vsprintf(): Too few arguments in %s on line %d
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 21 --
-
-Warning: vsprintf(): Too few arguments in %s on line %d
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 22 --
-
-Warning: vsprintf(): Too few arguments in %s on line %d
-bool(false)
+The arguments array must contain 1 items, 0 given
-- Iteration 23 --
string(%d) "Resource id #%d"