spinupwp / spinupwp-composer-site

A WordPress site setup using Composer that is primed and ready to be hosted using SpinupWP.
https://spinupwp.com/
110 stars 21 forks source link

Update dotenv package to ^3.0 #4

Closed polevaultweb closed 4 years ago

polevaultweb commented 4 years ago

This is so it works with Codeception and WPBrowser packages.

charlesdeb commented 3 years ago

Hey folks, codeception has moved on since you guys did this, and so has phpdotenv. I have been trying to get codeception running with a spinup site and getting dotenv related errors as I think one of codeception's dependencies (illuminate?) needs a higher version of phpdotenv. It is asking for a RepositoryBuilder class which exists in phpdotenv 4.0 and above - but not in phpdotenv 3.

[php7:error] [pid 16051] [client 127.0.0.1:51236] PHP Fatal error:  Uncaught Error: Class 'Dotenv\\Repository\\RepositoryBuilder' not found in /site/vendor/illuminate/support/Env.php:55
Stack trace:
#0 /site/vendor/illuminate/support/Env.php(76): Illuminate\\Support\\Env::getRepository()
#1 /site/vendor/illuminate/support/helpers.php(132): Illuminate\\Support\\Env::get('WP_ENV', NULL)
#2 /site/config/app.php(35): env('WP_ENV')
#3 /site/public/wp-config.php(8): require_once('/media/edrive/D...')
#4 /site/public/wp/wp-load.php(42): require_once('/media/edrive/D...')
#5 /site/public/wp/wp-login.php(12): require('/media/edrive/D...')
#6 {main}
  thrown in /site/vendor/illuminate/support/Env.php on line 55

Upgrading to v4 or v5 of phpdotenv gave me grief since the create method has changed:

$dotenv = \Dotenv\Dotenv::create( $root_dir );

in config/app.phpneeds to be replaced by something like

$dotenv = \Dotenv\Dotenv::createUnsafeImmutable( $root_dir );  // for phpdotenv v4
$dotenv = \Dotenv\Dotenv::createImmutable( $root_dir );        // for phpdotenv v5

and further down in this same file, instead of

foreach( $dotenv->getEnvironmentVariableNames() as $key ) {

we need

foreach( array_keys($dotenv->load()) as $key ) {  // for phpdotenv v4 or v5

I got this from https://github.com/vlucas/phpdotenv/blob/master/UPGRADING.md.

I have not dug into their docs enough to know why this is necessary, but I am somewhat unsure about using a method called createUnsafeImmutable!

polevaultweb commented 3 years ago

@charlesdeb just upgraded the phpdotenv package here https://github.com/deliciousbrains/spinupwp-composer-site/issues/9