pestphp / pestphp/pest

[Bug]: 2 unkeyed (Model::class) datasets fail

Open
#1,847 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
11.7k
Forks
538
Avg merge
4d 11h
Merged PRs (30d)
8

Description

What Happened

When I run:

use App\Models\Project;
use App\Models\User;

describe('audit logging', function () {
    it('created: event for observed model: ', function (string $modelClass) {
        /* expectations omitted, the test does not run with or without */
    })->with([
        Project::class,
        User::class,
    ]);

it should return:

✓ audit logging → it created: event for observed model: with ('App\Models\Project')
✓ audit logging → it created: event for observed model: with ('App\Models\User')
How to Reproduce

run a test with the dataset of only two model::class, you get the error below.

  ⨯ audit logging → it created: event for observed model:                                                                0.41s
  ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   FAILED  Tests\Feature\AuditTest > `audit logging` → it created: event for observed model:                            Error
  Call to a member function connection() on null

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2233
    2229▕      * @return \Illuminate\Database\Connection
    2230▕      */
    2231▕     public static function resolveConnection($connection = null)
    2232▕     {
  ➜ 2233▕         return static::$resolver->connection($connection);
    2234▕     }
    2235▕
    2236▕     /**
    2237▕      * Get the connection resolver instance.

If trim it to one, it succeeds,
If you add more than to it succeeds.
If you key any it will succeed, and;
If use arrays, viz ->with([[model::class], [model::class]]) it succeeds.

Sample Repository

No response

Pest Version

5.1

PHP Version

8.5.9

Operation System

macOS

Notes

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with a dataset containing exactly two unkeyed Model::class values, then compare it with one value, more than two, keyed values, and nested arrays. The fix is complete when both model datasets run as separate examples without the connection() on null error and produce the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.