My PHPUnit tests keep failing when trying to tests any .php files in my (legacy code) application that begin with the short open tag (<?
instead of <?php
).
But in my php.ini
file, the short_open_tag
is set to On
.
The application runs fine. Why is PHPUnit getting upset over the short open tag? I've looked for other php.ini
files, and could only find the one at /etc/php.ini
. My .htaccess
file doesn't affect this setting either. What else could be causing this?
So, I got it to work and the solution is frustrating: My application is on a VM and the php.ini
file within the VM had the correct setting. However, PHPUnit was using the php.ini
file on my local machine, which had short_open_tag
set to Off
. Changing that setting fixed my problem.
(I'm still unsure of why PHPUnit uses the other php.ini
, but I think that's outside the scope of this question.)
General solution
1) Check which php.ini file is loaded (command line: php --ini
)
2a) Set in that php ini file: short_open_tag = on
2b) Set in .htaccess file: php_value short_open_tag 1
3) Restart the server (command line: service httpd restart
)
PHPUnit uses PHP-cli module of PHP. And PHP-cli has another .ini
file for its configuration. I am using ubuntu 14.04, in my case
/etc/php5/apache2/php.ini
//used for web compiler
/etc/php5/cli/php.ini
// Used for PHP-cli, you need to setshort_open_tag=On
here