From ca2c909ac95a7e5cbe17531735f6601656590fb2 Mon Sep 17 00:00:00 2001 From: Koji Tanaka Date: Sun, 5 Feb 2023 16:16:00 +0900 Subject: [PATCH] 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. --- .../Model/Datasource/Database/PostgresTest.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index 415237017..01da8ebcd 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -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); } /**