1

I'm using symfony3 and I want to use phpunit

I'm using MAMP and I created an alias to use its php

my php version is 5.6.10

which php
php: aliased to /Applications/MAMP/bin/php/php5.6.10/bin/php

with php --ini I have this result

Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.6.10/conf
Loaded Configuration File:         /Applications/MAMP/bin/php/php5.6.10/conf/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

in /Applications/MAMP/bin/php/php5.6.10/conf/php.ini I set

date.timezone = "Europe/Rome"

I modified also php.ini from mamp with the same value

when I use phpunit

1) Tests\AppBundle\Controller\DefaultControllerTest::testIndex date_default_timezone_get(): 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 timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.

In my phpinfo() I have

Directive Local Value Master Value

date.timezone Europe/Rome Europe/Rome

monkeyUser
  • 4,301
  • 7
  • 46
  • 95

2 Answers2

1

In AppKernel you can set default_timezone like this

public function boot() {
   date_default_timezone_set('Europe/Rome');
   return parent::boot();
}
Barno
  • 3,271
  • 5
  • 28
  • 58
  • I see most answers adding `__construct` instead of `boot`, like http://stackoverflow.com/a/29152788/276648 . Any difference? – user276648 Nov 23 '16 at 03:22
1

Your phpinfo() says "Europe/Rome" is set, so I guess you already restarted the webserver?

I always set it with the date_default_timezone_set("Europe/Rome"); function in the top of a PHP file which always get's loaded.

melledijkstra
  • 361
  • 3
  • 17
  • Yes. I Restarted MAMP (webserver) even I think phpunit uses cli php. anyway I have the same issue. I don't like use `date_default_timezone_set()` in php file – monkeyUser Apr 14 '16 at 19:06
  • **EDIT: sorry didn't see that there aren't any additional conf files** Check for any additional configuration files, "conf.d" maybe? I think `phpinfo()` also gives you addition ini file locations which also get loaded – melledijkstra Apr 14 '16 at 19:15
  • thanks for your reply. In phpinfo() i can see `Additional .ini files parsed => (none)` – monkeyUser Apr 15 '16 at 08:00
  • I checked even in `Configuration File (php.ini) Path => /Applications/MAMP/bin/php/php5.6.10/conf Loaded Configuration File=> /Library/Application Support/appsolute/MAMP PRO/conf/php.ini` And I have `date.timezone = "Europe/Rome"` Everywhere – monkeyUser Apr 15 '16 at 08:03
  • 1
    Well if you are sure that the php.ini is the only configuration file, then maybe the problem lies within phpunit? Haven't used phpunit in my projects yet. Maybe Barno's solution works if you hook in on the bootstrapping/initialization of phpunit (just a guess) – melledijkstra Apr 15 '16 at 12:56