I am testing a class I made that uses a helper function. The function I'm testing looks like:
public function upload(UploadedFile $file)
{
$file = $file->move(base_path() . '/temp');
$file = new FileSystemPicture($file);
return $file;
}
When I run the tests and it hits the helper function it says:
PHP Fatal error: Call to a member function make() on a non-object
I have tracked the helper function down to be the following code:
function base_path($path = '')
{
return app()->make('path.base').($path ? '/'.$path : $path);
}
I know that I'm getting the error because the "app" hasn't been created because I'm only testing the my class, not the whole application. Are there other effective ways to get the root directory of my project or is there a way to force the "app" to load so it can be used in this function?
I had this problem, solved making sure that:
setUp()
method, it called parent::setUp()
app_path() and similar functions worked after that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With