englund
englund

Reputation: 160

PHPUnit configuration file and auto_prepend_file

I'm trying to use the phpunit configuration file to set a specific php-ini setting. When I try to set the auto_prepend_file to a file that exist, having tested both relative path and absolute path, it doesn't work.

I does however work if I set it in the php-ini file. php.ini

[...]
auto_prepend_file=/path/to/project/config.php
[...]

What I'm trying to do is to load this config.php file before loading my testcase, because I have some functions and config variables I need access to. Maybe I can do it some other way than using auto_prepend_file!? Or do somebody know how to make it work this way!?

phpunit config file:

<phpunit>
  [...]
  <php>
    <ini name="auto_prepend_file" value="/path/to/project/config.php" />
  </php>
  [...]
</phpunit>

Thanks in advance!

Upvotes: 3

Views: 1703

Answers (1)

edorian
edorian

Reputation: 38971

You can only use the <ini> tags to set values that can be set from within PHP using ini_set().

So only ini values that are PHP_INI_ALL. The auto_prepent_file directive is PHP_INI_PERDIR (see the docs) meaning it can't be set when php process is already running.


For including a file before the tests are run you have two options:

Ether use the --bootstrap file_to_run_before_tests_run.php option

or use php -d auto_prepend_file=yourfile.php /path/to/phpunit to run phpunit.

Both ways will ensure the file contents are executed before any tests are executed with --bootstrap being the more common way to do that.

Upvotes: 3

Related Questions