While running tests using PHPUnit and Orchestra Testbench, I encountered the following error:
ErrorException: Undefined variable $original at
/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3362
I was developing a Laravel package, and that error appeared when tried to run a test that started by running migrations:
$this->artisan('migrate')->run();
The root of the problem is a bug that only exists in the development branch of Laravel 13.x (dev-master or 13.x-dev), which is not yet released at the time of writing.
The reason why Laravel 13 was installed is because:
Testbench 11.x-dev requires laravel/framework:^13.0
My composer.json had "minimum-stability": "dev" without "prefer-stable": true
So when I ran composer require --dev orchestra/testbench, Composer pulled in the latest dev versions of both Testbench and Laravel
To avoid this kind of issue in your package development environment:
"prefer-stable": true,
"minimum-stability": "dev"
This ensures that only stable versions of packages are selected unless absolutely necessary.
composer remove orchestra/testbench
composer require --dev orchestra/testbench
This time, Composer will install the latest stable version of Testbench