You should inject your configuration array into the ToBeTested
class either via the constructor or a setter. This will eliminate the side effect caused by getLocalSettings
(the inclusion of another file) and will allow you to mock the settings whilst testing.
Your class definition might look like this:
class ToBeTested
{
private $localSettings;
public function __construct($localSettings)
{
$this->localSettings = $localSettings;
}
}
Then, when instantiating this class via normal use, you simply provide the configuration array to the constructor (the inclusion of local.php
should be done in bootstrap code).
When you want to unit test the class, you can inject any set of settings you need to when instantiating it, and you'll have no hard dependency on the filesystem. You might choose to use the data provider functionality in PHPUnit (documentation) for this.