alphp / strftime

This provides a cross-platform alternative to strftime() for when it will be removed from PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add phpunit tests

alphp opened this issue · comments

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?

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.