Search code examples
phpyiicodeception

Codeception datetime error


I'm trying to learn Codeception and am using it with Yii (which i'm also new to).

Straight out of the box, i'm having some issues with running the tests. I've walked through the quickstart guide and when I run it through terminal, I get this error:

Codeception PHP Testing Framework v1.6.6
Powered by PHPUnit 3.7.24 by Sebastian Bergmann.

  [Exception]                                                                                                                                         
  DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date  
  _default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the tim  
  ezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead                                                                          

Now, I'm using MAMP, and have set the timezone in my php.ini file. I've also tried manually setting it in the index.php file with _default_timezone_set('America/Chicago'); and I still get the same message.

As I'm using Yii, I've tried enabling the Yii module for Codeception, but that doesn't seem to make any difference.

Update

I've tried installing codeception on a non-yii based project, so a straight forward website and I get the exact same error as above.


Solution

  • Although yes the problem is the php.ini file, ultimately, my issue was in using php straight out of the box on mac. Apparently, the default installation (in /usr/bin) is what's used from terminal, rather than the installation of PHP from mac. also, that default install doesn't have a php.ini file associated.

    I found the following instruction from a forum for Yii, which was also playing up and turned out to be the same error:

    A note on PHP and Mac OSX:
    A version of PHP4 comes bundled on Mac OSX and is typically what is executed when you try the php command from the command line.  You need to have the php command execute a version of PHP5.x or higher.  Usually, you have already installed a version of PHP5.x or higher, but need to tell the php command to execute the newer version rather than the older one.  There are certainly many ways to achieve this, but here is one:
    at any terminal prompt, type in:
    prompt>which php
    this should tell you where the OS is looking for the php command
    mine tells me /usr/bin/php
    if I navigate to /usr/bin and issue an ls *php* I will see three files
    php
    php-config
    phpize
    These are all for the bundled version PHP4.x
    rename these files to use a 4 in their names, to remember these are the executables for PHP4
    mv php php4
    mv php-config php-config4
    mv phpize phpize4
    Then, create sym links for each of these these to point to the PHP5.x or higher version you have installed.  In my case these are located in /usr/local/apache/php/bin.  So I would issue from the /usr/bin directory
    ln -s [absolute path to your php5.x] php
    and similarly for the other files.