Framework: Call to undefined function Illuminate\Testing\Constraints\array_key_first()

Created on 15 May 2020  路  6Comments  路  Source: laravel/framework

  • Laravel Version: 7.11.0
  • PHP Version: 7.2.24
  • Database Driver & Version: mysql 5.7.19

Description:

I am writing a unit test and checking in pivot table if has some keys and throws error for undefined function. That function is for php 7.3 but laravel 7 requirement is 7.2.5+ right?
Why trait is using functions that are for 7.3 php version?
I am doing anything wrong?

Steps To Reproduce:

Create a table and add some records.
Create a test add assertion like this.

$this->assertDatabaseHas('user_role', [
            'user_id'     => $user->id,
            'role_id' => $role->id,
        ]);

Most helpful comment

This is now fixed on 6.x and 7.x.

All 6 comments

It would be helpful if you shared the exact error message you get, preferably the whole stack trace.

Hello @lupinitylabs ,
This is the strack trace

Error : Call to undefined function Illuminate\Testing\Constraints\array_key_first()
 C:\laragon\www\laravel\vendor\laravel\framework\src\Illuminate\Testing\Constraints\HasInDatabase.php:81
 C:\laragon\www\laravel\vendor\laravel\framework\src\Illuminate\Testing\Constraints\HasInDatabase.php:66
 C:\laragon\www\laravel\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase.php:46
 C:\laragon\www\laravel\tests\Http\Controllers\System\UserRoleController\DestroyTest.php:52


under further investigation, it looks that the current error occurs when the values you are looking are not in the table and the data are empty or missing the looking ids

Good find! Shows how important a good test coverage really is.

Actually this is tested, but the tests load the PHP 7.3 polyfill...

I was just going to ask that :-)Thanks for fixing!

@lupinitylabs Thanks,testing is crucial indeed

Actually this is tested, but the tests load the PHP 7.3 polyfill...

This is now fixed on 6.x and 7.x.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YannPl picture YannPl  路  3Comments

JamborJan picture JamborJan  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments

ghost picture ghost  路  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments