Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ByteSolution's avatar

PHPUnit Test fails with error message: undefined array key -1

Hi all,

after I did a composer update, all my tests are failing. The error message I get is as follows:

• Tests\Feature\ProtocolTest > index can be rendered
   ErrorException 

  Undefined array key -1

  at vendor/doctrine/dbal/src/Schema/SqliteSchemaManager.php:605
    601▕         $foreignKeyCount   = count($foreignKeyDetails);
    602▕ 
    603▕         foreach ($columns as $i => $column) {
    604▕             // SQLite identifies foreign keys in reverse order of appearance in SQL
  ➜ 605▕             $columns[$i] = array_merge($column, $foreignKeyDetails[$foreignKeyCount - $column['id'] - 1]);
    606▕         }
    607▕ 
    608▕         return $columns;
    609▕     }

      +12 vendor frames 
  13  database/migrations/2021_09_07_105757_update_models_with_status_id_and_priority_id.php:19
      Illuminate\Support\Facades\Facade::__callStatic("table")

      +23 vendor frames 
  37  tests/TestCase.php:38
      Illuminate\Foundation\Testing\TestCase::setUp()

It seems like something is wrong with my migration file, but the weird thing is, that it used to work without any problems before I ran composer update. Any ideas about that issue?

Here is the migration file:


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class UpdateModelsWithStatusIdAndPriorityId extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('protocols', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('activity_reports', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('custom_templates', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('data_processing_agreements', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('data_protection_impact_assessments', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('external_impacts', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('general_templates', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('processing_activities', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('regulations', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('tasks', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });

        Schema::table('technical_organisational_measures', function (Blueprint $table) {
            $table->unsignedBigInteger('status_id')->default(1)->change();
            $table->unsignedBigInteger('priority_id')->default(1)->change();
        });
    }

David

0 likes
2 replies
nielsnl's avatar

Thanks for posting. Ran into the same issue just now. That commit fixes it.

1 like

Please or to participate in this conversation.