ZF-2318: Zend_Service_Delicious execution failed when called on Mac shell

Description

I created a simple PHP script to bulk fetch and update a set of links in my delicious account. The script correctly fetches all items from delicious, however a Zend_Locale_Exception exception is raised as soon as Zend_Locale_Delicious parses the first item date.

Note. My computer is a MacBook Pro and I run the script via shell. This is an important information (see below).

Here's the script.


$delicious = new Zend_Service_Delicious(DELICIOUS_USERNAME, DELICIOUS_PASSWORD);

$posts = $delicious->getPosts('myhtml-blog');
echo count($posts) . " posts retrieved";
foreach($posts as $post) {
    echo $post->getTitle() . "\n";
}

Unit tests failed as well.


weppos-mac:~/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious weppos$ php AllTests.php 
PHPUnit 3.2.5 by Sebastian Bergmann.

.......E.EEE....................

Time: 01:03

There were 4 errors:

1) testLastUpdate(Zend_Service_Delicious_PrivateDataTest)
Zend_Locale_Exception: Autodetection of Locale has been failed!
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Locale.php:952
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Date.php:4453
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Date.php:173
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious.php:156
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/PrivateDataTest.php:81
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/AllTests.php:64
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/AllTests.php:118

2) testGetAllPosts(Zend_Service_Delicious_PrivateDataTest)
Zend_Locale_Exception: Autodetection of Locale has been failed!
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Locale.php:952
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Date.php:4453
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Date.php:173
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious/Post.php:287
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious/Post.php:87
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious/PostList.php:77
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious/PostList.php:60
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious.php:568
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious.php:321
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/PrivateDataTest.php:203
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/AllTests.php:64
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/AllTests.php:118

3) testGetRecentPosts(Zend_Service_Delicious_PrivateDataTest)
Zend_Locale_Exception: Autodetection of Locale has been failed!
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Locale.php:952
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Date.php:4453
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Date.php:173
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious/Post.php:287
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious/Post.php:87
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious/PostList.php:77
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious/PostList.php:60
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious.php:568
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Service/Delicious.php:343
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/PrivateDataTest.php:218
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/AllTests.php:64
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/AllTests.php:118

4) testGetPosts(Zend_Service_Delicious_PrivateDataTest)
Zend_Locale_Exception: Autodetection of Locale has been failed!
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Locale.php:952
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Date.php:4453
/Users/weppos/Sites/svn/zend.com.framework/trunk/library/Zend/Date.php:173
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/PrivateDataTest.php:234
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/AllTests.php:64
/Users/weppos/Sites/svn/zend.com.framework/trunk/tests/Zend/Service/Delicious/AllTests.php:118

FAILURES!
Tests: 32, Errors: 4.

I investigated the error and the issue is caused by the usage of Zend_Date for parsing post item date.

Zend_Date asks to Zend_Locale to provide a valid locale setting and the latter component guesses my locale settings. Unfortunately, locale detection fails because I run the script via shell and I don't provide any accepted language header and environment is empty as well.

I went deep on the issue and I found this is caused by an undetectable "C" locale problem. I just noticed a ticket is already open for this issue (ZF-2310), I'm going to post there more details.

Even if the bug doesn't really belong to Zend_Service_Delicious, I posted it here because this class might want to provide a custom solution instead of rely on ZF-2310.

Comments

Already fixed by ZF-2310.