admin管理员组

文章数量:1402315

Problem

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

Context

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();

Problem

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

Context

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();
Share Improve this question asked Mar 22 at 22:00 sergio0983sergio0983 1,2968 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Cause

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

Solution

To avoid this kind of issue in your package development environment:

  1. Update your composer.json to include:
"prefer-stable": true,
"minimum-stability": "dev"

This ensures that only stable versions of packages are selected unless absolutely necessary.

  1. Require Testbench again:
composer remove orchestra/testbench
composer require --dev orchestra/testbench

This time, Composer will install the latest stable version of Testbench

  1. Run your tests again — the error should disappear.

本文标签: laravelErrorException Undefined variable original when running a testStack Overflow