strftime icon indicating copy to clipboard operation
strftime copied to clipboard

Add phpunit tests

Open alphp opened this issue 3 years ago • 2 comments

alphp avatar Mar 17 '22 11:03 alphp

Current master's tests fail on my local machine (PHP 8.1.4):

There were 3 failures:

1) strftimeTest::testTimeFormats
%X: Preferred time representation based on locale, without the date
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'1:02:03 PM'
+'13:02:03'

/home/andi/www/devel/strftime/tests/strftimeTest.php:132

2) strftimeTest::testStampsFormats
%c: Preferred date and time stamp based on locale
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'March 6, 2022 at 1:02 PM'
+'March 6, 2022 at 13:02'

/home/andi/www/devel/strftime/tests/strftimeTest.php:143

3) strftimeTest::testLocale
%c: Preferred date and time stamp based on locale
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'2022(e)ko martxoaren 6(a) 13:02'
+'2022(e)ko martxoakren 6(a) 13:02'

/home/andi/www/devel/strftime/tests/strftimeTest.php:177

Is that a known issue? Are the tests somehow dependent on the locale setup of my machine?

splitbrain avatar Apr 28 '22 10:04 splitbrain

Is an bug in the test setUp:

public function setUp () : void {
    setlocale(LC_TIME, 'en');
    date_default_timezone_set('Europe/Madrid');
}

In my experience there are differences in the values supported by the php setlocale function. It was a mistake on my part to trust that setlocale(LC_TIME, 'en') would work in all environments. I've removed the setlocale from setUp and used the locale option of the strftime function with the string 'en-EN', hopefully that's more universal.

alphp avatar Apr 28 '22 15:04 alphp