Updated functional tests with iterator and locale issues (#1153)
This commit is contained in:
parent
0caf160cad
commit
48e3dd01be
|
@ -56,6 +56,9 @@ function checkInterface($stmt)
|
||||||
unset($expected['__wakeup']);
|
unset($expected['__wakeup']);
|
||||||
unset($expected['__sleep']);
|
unset($expected['__sleep']);
|
||||||
}
|
}
|
||||||
|
if ($phpver >= '8.0') {
|
||||||
|
$expected = array_merge($expected, ['getIterator' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
$classname = get_class($stmt);
|
$classname = get_class($stmt);
|
||||||
$methods = get_class_methods($classname);
|
$methods = get_class_methods($classname);
|
||||||
|
|
|
@ -71,7 +71,7 @@ class PDOStatementAggregate extends PDOStatement implements IteratorAggregate
|
||||||
$this->setFetchMode(PDO::FETCH_NUM);
|
$this->setFetchMode(PDO::FETCH_NUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIterator()
|
function getIterator() : Iterator
|
||||||
{
|
{
|
||||||
echo __METHOD__ . "\n";
|
echo __METHOD__ . "\n";
|
||||||
$this->execute();
|
$this->execute();
|
||||||
|
|
|
@ -69,7 +69,7 @@ class PDOStatementAggregate extends PDOStatement implements IteratorAggregate
|
||||||
$this->setFetchMode(PDO::FETCH_NUM);
|
$this->setFetchMode(PDO::FETCH_NUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIterator()
|
function getIterator() : Iterator
|
||||||
{
|
{
|
||||||
echo __METHOD__ . "\n";
|
echo __METHOD__ . "\n";
|
||||||
$this->execute();
|
$this->execute();
|
||||||
|
|
|
@ -34,13 +34,11 @@ pdo_sqlsrv.set_locale_info = 0***
|
||||||
Amount formatted: 10000.99
|
Amount formatted: 10000.99
|
||||||
Friday
|
Friday
|
||||||
December
|
December
|
||||||
3.14159
|
|
||||||
**End**
|
**End**
|
||||||
**Begin**
|
**Begin**
|
||||||
Amount formatted: $10,000.99
|
Amount formatted: $10,000.99
|
||||||
Friday
|
Friday
|
||||||
December
|
December
|
||||||
3.14159
|
|
||||||
**End**
|
**End**
|
||||||
|
|
||||||
***sqlsrv.SetLocaleInfo = 1
|
***sqlsrv.SetLocaleInfo = 1
|
||||||
|
@ -50,13 +48,11 @@ pdo_sqlsrv.set_locale_info = 1***
|
||||||
Amount formatted: 10000.99
|
Amount formatted: 10000.99
|
||||||
Friday
|
Friday
|
||||||
December
|
December
|
||||||
3.14159
|
|
||||||
**End**
|
**End**
|
||||||
**Begin**
|
**Begin**
|
||||||
Amount formatted: 10.000,99 €
|
Amount formatted: 10.000,99 €
|
||||||
Freitag
|
Freitag
|
||||||
Dezember
|
Dezember
|
||||||
3,14159
|
|
||||||
**End**
|
**End**
|
||||||
|
|
||||||
***sqlsrv.SetLocaleInfo = 2
|
***sqlsrv.SetLocaleInfo = 2
|
||||||
|
@ -66,11 +62,9 @@ pdo_sqlsrv.set_locale_info = 2***
|
||||||
Amount formatted: $10,000.99
|
Amount formatted: $10,000.99
|
||||||
Friday
|
Friday
|
||||||
December
|
December
|
||||||
3.14159
|
|
||||||
**End**
|
**End**
|
||||||
**Begin**
|
**Begin**
|
||||||
Amount formatted: 10.000,99 €
|
Amount formatted: 10.000,99 €
|
||||||
Freitag
|
Freitag
|
||||||
Dezember
|
Dezember
|
||||||
3,14159
|
|
||||||
**End**
|
**End**
|
||||||
|
|
|
@ -32,9 +32,9 @@ $locale = ($_SERVER['argv'][2] ?? '');
|
||||||
|
|
||||||
echo "**Begin**" . PHP_EOL;
|
echo "**Begin**" . PHP_EOL;
|
||||||
|
|
||||||
// Assuming LC_ALL is 'en_US.UTF-8', so is LC_CTYPE
|
// Assuming LC_ALL is 'en_US.UTF-8', so is LC_CTYPE, except in PHP 8 (TODO)
|
||||||
// But default LC_MONETARY varies
|
// But default LC_MONETARY varies
|
||||||
$ctype = 'en_US.UTF-8';
|
$ctype = (PHP_MAJOR_VERSION == 8 && $setLocaleInfo == 0) ? 'C' : 'en_US.UTF-8';
|
||||||
switch ($setLocaleInfo) {
|
switch ($setLocaleInfo) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -55,9 +55,11 @@ if ($m !== $m1) {
|
||||||
$c1 = setlocale(LC_CTYPE, 0);
|
$c1 = setlocale(LC_CTYPE, 0);
|
||||||
if ($ctype !== $c1) {
|
if ($ctype !== $c1) {
|
||||||
echo "Unexpected LC_CTYPE: $c1" . PHP_EOL;
|
echo "Unexpected LC_CTYPE: $c1" . PHP_EOL;
|
||||||
|
echo "LC_NUMERIC for $setLocaleInfo: " . setlocale(LC_NUMERIC, 0) . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a different locale, if the input is not empty
|
// Set a different locale, if the input is not empty
|
||||||
|
$english = true;
|
||||||
if (!empty($locale)) {
|
if (!empty($locale)) {
|
||||||
$loc = setlocale(LC_ALL, $locale);
|
$loc = setlocale(LC_ALL, $locale);
|
||||||
if ($loc !== $locale) {
|
if ($loc !== $locale) {
|
||||||
|
@ -68,6 +70,7 @@ if (!empty($locale)) {
|
||||||
if ($loc === 'de_DE.UTF-8') {
|
if ($loc === 'de_DE.UTF-8') {
|
||||||
$symbol = strtoupper(PHP_OS) === 'LINUX' ? '€' : 'Eu';
|
$symbol = strtoupper(PHP_OS) === 'LINUX' ? '€' : 'Eu';
|
||||||
$sep = strtoupper(PHP_OS) === 'LINUX' ? '.' : '';
|
$sep = strtoupper(PHP_OS) === 'LINUX' ? '.' : '';
|
||||||
|
$english = false;
|
||||||
} else {
|
} else {
|
||||||
$symbol = '$';
|
$symbol = '$';
|
||||||
$sep = ',';
|
$sep = ',';
|
||||||
|
@ -106,8 +109,20 @@ try {
|
||||||
$stmt = $conn->prepare($sql, array(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true));
|
$stmt = $conn->prepare($sql, array(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true));
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
|
// The following change is required for the breaking change introduced in PHP 8
|
||||||
|
// https://wiki.php.net/rfc/locale_independent_float_to_string
|
||||||
$row = $stmt->fetch(PDO::FETCH_NUM);
|
$row = $stmt->fetch(PDO::FETCH_NUM);
|
||||||
echo ($row[0]) . PHP_EOL;
|
$value = $row[0];
|
||||||
|
$expected = 3.14159;
|
||||||
|
if (PHP_MAJOR_VERSION < 8) {
|
||||||
|
if ($setLocaleInfo > 0 && $english === false) {
|
||||||
|
$expected = floatval($pi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($value != $expected) {
|
||||||
|
echo "Expected: '$expected' but got '$value'\n";
|
||||||
|
}
|
||||||
|
|
||||||
unset($stmt);
|
unset($stmt);
|
||||||
|
|
||||||
dropTable($conn, $tableName);
|
dropTable($conn, $tableName);
|
||||||
|
|
|
@ -19,7 +19,7 @@ sqlsrv_close returns true even if an error happens.
|
||||||
function compareMessages($err, $exp8x, $exp7x)
|
function compareMessages($err, $exp8x, $exp7x)
|
||||||
{
|
{
|
||||||
$expected = (PHP_MAJOR_VERSION == 8) ? $exp8x : $exp7x;
|
$expected = (PHP_MAJOR_VERSION == 8) ? $exp8x : $exp7x;
|
||||||
if ($err->getMessage() !== $expected) {
|
if (!fnmatch($expected, $err->getMessage())) {
|
||||||
echo $err->getMessage() . PHP_EOL;
|
echo $err->getMessage() . PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ sqlsrv_close returns true even if an error happens.
|
||||||
} catch (TypeError $e) {
|
} catch (TypeError $e) {
|
||||||
compareMessages($e,
|
compareMessages($e,
|
||||||
"sqlsrv_close(): Argument #1 (\$conn) must be of type resource, bool given",
|
"sqlsrv_close(): Argument #1 (\$conn) must be of type resource, bool given",
|
||||||
"sqlsrv_close() expects parameter 1 to be resource, bool given");
|
"sqlsrv_close() expects parameter 1 to be resource, bool* given");
|
||||||
}
|
}
|
||||||
|
|
||||||
$errors = sqlsrv_errors();
|
$errors = sqlsrv_errors();
|
||||||
|
@ -140,7 +140,7 @@ sqlsrv_close returns true even if an error happens.
|
||||||
} catch (TypeError $e) {
|
} catch (TypeError $e) {
|
||||||
compareMessages($e,
|
compareMessages($e,
|
||||||
"sqlsrv_free_stmt(): Argument #1 (\$stmt) must be of type resource, int given",
|
"sqlsrv_free_stmt(): Argument #1 (\$stmt) must be of type resource, int given",
|
||||||
"sqlsrv_free_stmt() expects parameter 1 to be resource, int given");
|
"sqlsrv_free_stmt() expects parameter 1 to be resource, int* given");
|
||||||
}
|
}
|
||||||
|
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
|
@ -180,7 +180,7 @@ sqlsrv_close returns true even if an error happens.
|
||||||
} catch (TypeError $e) {
|
} catch (TypeError $e) {
|
||||||
compareMessages($e,
|
compareMessages($e,
|
||||||
"sqlsrv_close(): Argument #1 (\$conn) must be of type resource, int given",
|
"sqlsrv_close(): Argument #1 (\$conn) must be of type resource, int given",
|
||||||
"sqlsrv_close() expects parameter 1 to be resource, int given");
|
"sqlsrv_close() expects parameter 1 to be resource, int* given");
|
||||||
}
|
}
|
||||||
|
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
|
|
|
@ -34,13 +34,11 @@ pdo_sqlsrv.set_locale_info = 0***
|
||||||
Amount formatted: 10000.99
|
Amount formatted: 10000.99
|
||||||
Friday
|
Friday
|
||||||
December
|
December
|
||||||
3.14159
|
|
||||||
**End**
|
**End**
|
||||||
**Begin**
|
**Begin**
|
||||||
Amount formatted: $10,000.99
|
Amount formatted: $10,000.99
|
||||||
Friday
|
Friday
|
||||||
December
|
December
|
||||||
3.14159
|
|
||||||
**End**
|
**End**
|
||||||
|
|
||||||
***sqlsrv.SetLocaleInfo = 1
|
***sqlsrv.SetLocaleInfo = 1
|
||||||
|
@ -50,13 +48,11 @@ pdo_sqlsrv.set_locale_info = 1***
|
||||||
Amount formatted: 10000.99
|
Amount formatted: 10000.99
|
||||||
Friday
|
Friday
|
||||||
December
|
December
|
||||||
3.14159
|
|
||||||
**End**
|
**End**
|
||||||
**Begin**
|
**Begin**
|
||||||
Amount formatted: 10.000,99 €
|
Amount formatted: 10.000,99 €
|
||||||
Freitag
|
Freitag
|
||||||
Dezember
|
Dezember
|
||||||
3,14159
|
|
||||||
**End**
|
**End**
|
||||||
|
|
||||||
***sqlsrv.SetLocaleInfo = 2
|
***sqlsrv.SetLocaleInfo = 2
|
||||||
|
@ -66,11 +62,9 @@ pdo_sqlsrv.set_locale_info = 2***
|
||||||
Amount formatted: $10,000.99
|
Amount formatted: $10,000.99
|
||||||
Friday
|
Friday
|
||||||
December
|
December
|
||||||
3.14159
|
|
||||||
**End**
|
**End**
|
||||||
**Begin**
|
**Begin**
|
||||||
Amount formatted: 10.000,99 €
|
Amount formatted: 10.000,99 €
|
||||||
Freitag
|
Freitag
|
||||||
Dezember
|
Dezember
|
||||||
3,14159
|
|
||||||
**End**
|
**End**
|
||||||
|
|
|
@ -37,9 +37,9 @@ $locale = ($_SERVER['argv'][2] ?? '');
|
||||||
|
|
||||||
echo "**Begin**" . PHP_EOL;
|
echo "**Begin**" . PHP_EOL;
|
||||||
|
|
||||||
// Assuming LC_ALL is 'en_US.UTF-8', so is LC_CTYPE
|
// Assuming LC_ALL is 'en_US.UTF-8', so is LC_CTYPE, except in PHP 8 (TODO)
|
||||||
// But default LC_MONETARY varies
|
// But default LC_MONETARY varies
|
||||||
$ctype = 'en_US.UTF-8';
|
$ctype = (PHP_MAJOR_VERSION == 8 && $setLocaleInfo == 0) ? 'C' : 'en_US.UTF-8';
|
||||||
switch ($setLocaleInfo) {
|
switch ($setLocaleInfo) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -60,9 +60,11 @@ if ($m !== $m1) {
|
||||||
$c1 = setlocale(LC_CTYPE, 0);
|
$c1 = setlocale(LC_CTYPE, 0);
|
||||||
if ($ctype !== $c1) {
|
if ($ctype !== $c1) {
|
||||||
echo "Unexpected LC_CTYPE: $c1" . PHP_EOL;
|
echo "Unexpected LC_CTYPE: $c1" . PHP_EOL;
|
||||||
|
echo "LC_NUMERIC for $setLocaleInfo: " . setlocale(LC_NUMERIC, 0) . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a different locale, if the input is not empty
|
// Set a different locale, if the input is not empty
|
||||||
|
$english = true;
|
||||||
if (!empty($locale)) {
|
if (!empty($locale)) {
|
||||||
$loc = setlocale(LC_ALL, $locale);
|
$loc = setlocale(LC_ALL, $locale);
|
||||||
if ($loc !== $locale) {
|
if ($loc !== $locale) {
|
||||||
|
@ -73,6 +75,7 @@ if (!empty($locale)) {
|
||||||
if ($loc === 'de_DE.UTF-8') {
|
if ($loc === 'de_DE.UTF-8') {
|
||||||
$symbol = strtoupper(PHP_OS) === 'LINUX' ? '€' : 'Eu';
|
$symbol = strtoupper(PHP_OS) === 'LINUX' ? '€' : 'Eu';
|
||||||
$sep = strtoupper(PHP_OS) === 'LINUX' ? '.' : '';
|
$sep = strtoupper(PHP_OS) === 'LINUX' ? '.' : '';
|
||||||
|
$english = false;
|
||||||
} else {
|
} else {
|
||||||
$symbol = '$';
|
$symbol = '$';
|
||||||
$sep = ',';
|
$sep = ',';
|
||||||
|
@ -121,9 +124,19 @@ if (!$stmt) {
|
||||||
fatalError("Failed in running query $sql");
|
fatalError("Failed in running query $sql");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The following change is required for the breaking change introduced in PHP 8
|
||||||
|
// https://wiki.php.net/rfc/locale_independent_float_to_string
|
||||||
while (sqlsrv_fetch($stmt)) {
|
while (sqlsrv_fetch($stmt)) {
|
||||||
$value = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_FLOAT);
|
$value = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_FLOAT);
|
||||||
echo $value . PHP_EOL;
|
$expected = 3.14159;
|
||||||
|
if (PHP_MAJOR_VERSION < 8) {
|
||||||
|
if ($setLocaleInfo > 0 && $english === false) {
|
||||||
|
$expected = floatval($pi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($value != $expected) {
|
||||||
|
echo "Expected: '$expected' but got '$value'\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
|
@ -15,7 +15,7 @@ crash caused by a statement being orphaned when an error occurred during sqlsrv_
|
||||||
function compareMessages($err, $exp8x, $exp7x)
|
function compareMessages($err, $exp8x, $exp7x)
|
||||||
{
|
{
|
||||||
$expected = (PHP_MAJOR_VERSION == 8) ? $exp8x : $exp7x;
|
$expected = (PHP_MAJOR_VERSION == 8) ? $exp8x : $exp7x;
|
||||||
if ($err->getMessage() !== $expected) {
|
if (!fnmatch($expected, $err->getMessage())) {
|
||||||
echo $err->getMessage() . PHP_EOL;
|
echo $err->getMessage() . PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ crash caused by a statement being orphaned when an error occurred during sqlsrv_
|
||||||
} catch (TypeError $e) {
|
} catch (TypeError $e) {
|
||||||
compareMessages($e,
|
compareMessages($e,
|
||||||
"sqlsrv_fetch_array(): Argument #1 (\$stmt) must be of type resource, bool given",
|
"sqlsrv_fetch_array(): Argument #1 (\$stmt) must be of type resource, bool given",
|
||||||
"sqlsrv_fetch_array() expects parameter 1 to be resource, bool given");
|
"sqlsrv_fetch_array() expects parameter 1 to be resource, bool* given");
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Done\n";
|
echo "Done\n";
|
||||||
|
|
Loading…
Reference in a new issue