test: Restore if LC_NUMERIC is changed during testing.

Improved PostgresTest::testLocalizedFloats().
This test changes the locale (LC_NUMERIC) and restores it last. Therefore, if the test failed, subsequent tests referencing the locale could fail.
This commit is contained in:
Koji Tanaka 2023-02-05 16:16:00 +09:00 committed by Kamil Wylegala
parent 0ec6365f9d
commit ca2c909ac9

View file

@ -209,6 +209,13 @@ class PostgresTest extends CakeTestCase {
*/
public $Dbo2 = null;
/**
* Number locale before changing during testing
*
* @var string
*/
public $restoreLocaleNumeric = null;
/**
* Sets up a Dbo class instance for testing
*
@ -232,6 +239,11 @@ class PostgresTest extends CakeTestCase {
parent::tearDown();
Configure::write('Cache.disable', false);
unset($this->Dbo2);
if (!is_null($this->restoreLocaleNumeric)) {
setlocale(LC_NUMERIC, $this->restoreLocaleNumeric);
$this->restoreLocaleNumeric = null;
}
}
/**
@ -349,7 +361,7 @@ class PostgresTest extends CakeTestCase {
* @return void
*/
public function testLocalizedFloats() {
$restore = setlocale(LC_NUMERIC, 0);
$this->restoreLocaleNumeric = setlocale(LC_NUMERIC, 0);
$this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available.");
@ -358,8 +370,6 @@ class PostgresTest extends CakeTestCase {
$result = $this->db->value(3.14);
$this->assertEquals("3.140000", $result);
setlocale(LC_NUMERIC, $restore);
}
/**