laravel / pennant

A simple, lightweight library for managing feature flags.
https://laravel.com/docs/pennant
MIT License
474 stars 48 forks source link

Error when parallel testing with database driver #80

Closed bradietilley closed 8 months ago

bradietilley commented 8 months ago

Pennant Version

1.5.1

Laravel Version

10.39.0

PHP Version

8.2.8

Database Driver & Version

MySQL v8.0.33 for macos 13.3 on arm64 (Homebrew)

Description

Running artisan test --parallel on any project with pennant (database driver) will fail most tests with the following error:

Error: Call to a member function prepare() on null

The database driver for pennant appears to be trying to connect to the original database parallel_testing_with_pennant instead of the tokenised databases such as parallel_testing_with_pennant_1 or parallel_testing_with_pennant_2, but I'm not sure.

Steps To Reproduce

Repo: https://github.com/bradietilley/parallel-testing-with-pennant

git clone git@github.com:bradietilley/parallel-testing-with-pennant.git
cd parallel-testing-with-pennant
composer install
cp .env.example .env
# <setup database details in .env>
artisan test --parallel

image

1) Tests\Feature\PennantTest::test_one
Error: Call to a member function prepare() on null

/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:416
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:809
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:776
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:407
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2751
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2740
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3294
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2739
/var/www/parallel-testing-with-pennant/vendor/laravel/pennant/src/Drivers/DatabaseDriver.php:105
/var/www/parallel-testing-with-pennant/vendor/laravel/pennant/src/Drivers/Decorator.php:209
/var/www/parallel-testing-with-pennant/vendor/laravel/pennant/src/Drivers/Decorator.php:232
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:746
/var/www/parallel-testing-with-pennant/vendor/laravel/pennant/src/Drivers/Decorator.php:232
/var/www/parallel-testing-with-pennant/vendor/laravel/pennant/src/PendingScopedFeatureInteraction.php:70
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:746
/var/www/parallel-testing-with-pennant/vendor/laravel/pennant/src/PendingScopedFeatureInteraction.php:70
/var/www/parallel-testing-with-pennant/vendor/laravel/pennant/src/PendingScopedFeatureInteraction.php:96
/var/www/parallel-testing-with-pennant/vendor/laravel/pennant/src/PendingScopedFeatureInteraction.php:81
/var/www/parallel-testing-with-pennant/tests/Feature/PennantTest.php:15
/var/www/parallel-testing-with-pennant/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:176
timacdonald commented 8 months ago

Thanks for raising this and also for the reproduction repository ❤️

I've opened a PR to address this issue. I'll close this and we can track the PR instead: https://github.com/laravel/pennant/pull/81