From 17f841965baad5985cb69d056347713578fb3ecb Mon Sep 17 00:00:00 2001 From: Fernando Herrero Date: Fri, 26 Jan 2024 03:03:31 +0100 Subject: [PATCH] Tests: use assertThat instead assertMatchesRegularExpression --- tests/LocaleTests/Locale_en_EN_TestTrait.php | 10 ++++++++-- tests/LocaleTests/Locale_es_ES_TestTrait.php | 15 ++++++++++++--- tests/LocaleTests/Locale_eu_TestTrait.php | 11 +++++++++-- tests/LocaleTests/Locale_it_CH_TestTrait.php | 5 ++++- tests/LocaleTests/Locale_it_IT_TestTrait.php | 5 ++++- tests/strftimeTest.php | 10 ++++++++-- 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/tests/LocaleTests/Locale_en_EN_TestTrait.php b/tests/LocaleTests/Locale_en_EN_TestTrait.php index 4f0baca..a11be1e 100644 --- a/tests/LocaleTests/Locale_en_EN_TestTrait.php +++ b/tests/LocaleTests/Locale_en_EN_TestTrait.php @@ -26,10 +26,16 @@ public function testLocale_en_EN () { $this->assertEquals('Mar', $result, '%h: Abbreviated month name, based on the locale (an alias of %b)'); $result = strftime('%X', '20220306 13:02:03', $locale); - $this->assertMatchesRegularExpression('~1:02:03 PM|13:02:03~', $result, '%X: Preferred time representation based on locale, without the date'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('1:02:03 PM'), // PHP-7 + $this->equalTo('13:02:03') // PHP-8 + ), '%X: Preferred time representation based on locale, without the date'); $result = strftime('%c', '20220306 13:02:03', $locale); - $this->assertMatchesRegularExpression('~March 6, 2022 at (1:02 PM|13:02)~', $result, '%c: Preferred date and time stamp based on locale'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('March 6, 2022 at 1:02 PM'), // PHP-7 + $this->equalTo('March 6, 2022 at 13:02') // PHP-8 + ), '%c: Preferred date and time stamp based on locale'); $result = strftime('%x', '20220306 13:02:03', $locale); $this->assertEquals('3/6/22', $result, '%x: Preferred date representation based on locale, without the time'); diff --git a/tests/LocaleTests/Locale_es_ES_TestTrait.php b/tests/LocaleTests/Locale_es_ES_TestTrait.php index 0b626a0..a009735 100644 --- a/tests/LocaleTests/Locale_es_ES_TestTrait.php +++ b/tests/LocaleTests/Locale_es_ES_TestTrait.php @@ -11,19 +11,28 @@ public function testLocale_es_ES () { $locale = 'es-ES'; $result = strftime('%a', '20220306 13:02:03', $locale); - $this->assertMatchesRegularExpression('~dom\.?~', $result, '%a: An abbreviated textual representation of the day'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('dom.'), // PHP-7 + $this->equalTo('dom') // PHP-8 + ), '%a: An abbreviated textual representation of the day'); $result = strftime('%A', '20220306 13:02:03', $locale); $this->assertEquals('domingo', $result, '%A: A full textual representation of the day'); $result = strftime('%b', '20220306 13:02:03', $locale); - $this->assertMatchesRegularExpression('~mar\.?~', $result, '%b: Abbreviated month name, based on the locale'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('mar.'), // PHP-7 + $this->equalTo('mar') // PHP-8 + ), '%b: Abbreviated month name, based on the locale'); $result = strftime('%B', '20220306 13:02:03', $locale); $this->assertEquals('marzo', $result, '%B: Full month name, based on the locale'); $result = strftime('%h', '20220306 13:02:03', $locale); - $this->assertMatchesRegularExpression('~mar\.?~', $result, '%h: Abbreviated month name, based on the locale (an alias of %b)'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('mar.'), // PHP-7 + $this->equalTo('mar') // PHP-8 + ), '%h: Abbreviated month name, based on the locale (an alias of %b)'); $result = strftime('%X', '20220306 13:02:03', $locale); $this->assertEquals('13:02:03', $result, '%X: Preferred time representation based on locale, without the date'); diff --git a/tests/LocaleTests/Locale_eu_TestTrait.php b/tests/LocaleTests/Locale_eu_TestTrait.php index 7e03a0c..2d30502 100644 --- a/tests/LocaleTests/Locale_eu_TestTrait.php +++ b/tests/LocaleTests/Locale_eu_TestTrait.php @@ -20,7 +20,10 @@ public function testLocale_eu () { $this->assertEquals('mar.', $result, '%b: Abbreviated month name, based on the locale'); $result = strftime('%B', '20220306 13:02:03', $locale); - $this->assertMatchesRegularExpression('~martxoak?~', $result, '%B: Full month name, based on the locale'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('martxoak'), + $this->equalTo('martxoa') // PHP-7.4, PHP-8.3 + ), '%B: Full month name, based on the locale'); $result = strftime('%h', '20220306 13:02:03', $locale); $this->assertEquals('mar.', $result, '%h: Abbreviated month name, based on the locale (an alias of %b)'); @@ -29,7 +32,11 @@ public function testLocale_eu () { $this->assertEquals('13:02:03', $result, '%X: Preferred time representation based on locale, without the date'); $result = strftime('%c', '20220306 13:02:03', $locale); - $this->assertMatchesRegularExpression('~2022\(e\)ko martxoak?ren 6\(a\) \(?13:02\)?~', $result, '%c: Preferred date and time stamp based on locale'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('2022(e)ko martxoaren 6(a) 13:02'), // PHP-7.4 + $this->equalTo('2022(e)ko martxoakren 6(a) 13:02'), + $this->equalTo('2022(e)ko martxoaren 6(a) (13:02)') // PHP-8.3 + ), '%c: Preferred date and time stamp based on locale'); $result = strftime('%x', '20220306 13:02:03', $locale); $this->assertEquals('22/3/6', $result, '%x: Preferred date representation based on locale, without the time'); diff --git a/tests/LocaleTests/Locale_it_CH_TestTrait.php b/tests/LocaleTests/Locale_it_CH_TestTrait.php index 2ba2fcc..335b3be 100644 --- a/tests/LocaleTests/Locale_it_CH_TestTrait.php +++ b/tests/LocaleTests/Locale_it_CH_TestTrait.php @@ -29,7 +29,10 @@ public function testLocale_it_CH () { $this->assertEquals('13:02:03', $result, '%X: Preferred time representation based on locale, without the date'); $result = strftime('%c', '20220306 13:02:03', $locale); - $this->assertMatchesRegularExpression('~6 marzo 2022 (alle ore )?13:02~', $result, '%c: Preferred date and time stamp based on locale'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('6 marzo 2022 13:02'), + $this->equalTo('6 marzo 2022 alle ore 13:02') // PHP-8.3 + ), '%c: Preferred date and time stamp based on locale'); $result = strftime('%x', '20220306 13:02:03', $locale); $this->assertEquals('06.03.22', $result, '%x: Preferred date representation based on locale, without the time'); diff --git a/tests/LocaleTests/Locale_it_IT_TestTrait.php b/tests/LocaleTests/Locale_it_IT_TestTrait.php index c398ad3..ab6737e 100644 --- a/tests/LocaleTests/Locale_it_IT_TestTrait.php +++ b/tests/LocaleTests/Locale_it_IT_TestTrait.php @@ -29,7 +29,10 @@ public function testLocale_it_IT () { $this->assertEquals('13:02:03', $result, '%X: Preferred time representation based on locale, without the date'); $result = strftime('%c', '20220306 13:02:03', $locale); - $this->assertMatchesRegularExpression('~6 marzo 2022 (alle ore )?13:02~', $result, '%c: Preferred date and time stamp based on locale'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('6 marzo 2022 13:02'), + $this->equalTo('6 marzo 2022 alle ore 13:02') // PHP-8.3 + ), '%c: Preferred date and time stamp based on locale'); $result = strftime('%x', '20220306 13:02:03', $locale); $this->assertEquals('06/03/22', $result, '%x: Preferred date representation based on locale, without the time'); diff --git a/tests/strftimeTest.php b/tests/strftimeTest.php index 42cbea6..a0ca3fe 100644 --- a/tests/strftimeTest.php +++ b/tests/strftimeTest.php @@ -135,7 +135,10 @@ public function testTimeFormats () { $this->assertEquals('13:02:03', $result, '%T: Same as "%H:%M:%S"'); $result = strftime('%X', '20220306 13:02:03', 'en-EN'); - $this->assertMatchesRegularExpression('~1:02:03 PM|13:02:03~', $result, '%X: Preferred time representation based on locale, without the date'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('1:02:03 PM'), + $this->equalTo('13:02:03') // PHP-8 + ), '%X: Preferred time representation based on locale, without the date'); $result = strftime('%z', '20220306 13:02:03'); $this->assertEquals('+0100', $result, '%z: The time zone offset'); @@ -146,7 +149,10 @@ public function testTimeFormats () { public function testStampsFormats () { $result = strftime('%c', '20220306 13:02:03', 'en-EN'); - $this->assertMatchesRegularExpression('~March 6, 2022 at (1:02 PM|13:02)~', $result, '%c: Preferred date and time stamp based on locale'); + $this->assertThat($result, $this->logicalOr( + $this->equalTo('March 6, 2022 at 1:02 PM'), + $this->equalTo('March 6, 2022 at 13:02') // PHP-8 + ), '%c: Preferred date and time stamp based on locale'); $result = strftime('%D', '20220306 13:02:03'); $this->assertEquals('03/06/2022', $result, '%D: Same as "%m/%d/%y"');