0
votes

In Lumen 5.4, I want to override the default storage path, and since the use of useStoragePath() as possible with Laravel seems unavailable in Lumen, I went for another solution by defining the storage_path() function before it gets defined by the framework.

This requires a modification to the bootstrap/app.php file, which works perfectly fine in normal operation:

// App helpers
require_once __DIR__ . '/../app/helpers.php';

// Composer autoloader
require_once __DIR__ . '/../vendor/autoload.php';

However, when running tests using Codeception, it loads the vendor/autoload.php before bootstrap/app.php gets loaded, which results in this obvious fatal error:

PHP Fatal error: Cannot redeclare storage_path() (previously declared in vendor\laravel\lumen-framework\src\helpers.php:308) in app\helpers.php

I tried extending the shipped Lumen module in Codeception, overwriting the registerAutoloaders() method, without luck (which makes sense, as Codeception also needs to include the Composer autoloader):

class App extends \Codeception\Module\Lumen
{
    protected function registerAutoloaders()
    {
        // Don't include autoload file here, as it will be required in the apps bootstrap file
    }
}

The default storage_path() in Lumen has no entry points for extensions afaik:

public function storagePath($path = '')
{
    return $this->basePath().'/storage'.($path ? '/'.$path : $path);
}

How can I change the default storage path in Lumen which also plays nice when running tests in Codeception?

1
An obvious solution would be to just use the default storage_path() implementation when running tests. I would still be curious however for a possible workaround using a modified storage path in tests.Joram van den Boezem

1 Answers

0
votes

Try adding your helpers.php to the composer.json's autoload section so that it will be auto loaded.

"autoload": {
    "psr-4": {
        "App\\": "app"
    },
    "files": [
        "app/helpers.php"
    ]
},