pestphp / pestphp/pest

[Bug]: Dataset with named parameters fails in Pest 3 if parameters count mismatch

Open
#1,232 0 comments 6 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

We use shared datasets to provide data for multiple tests. The dataset uses keys to make the data readable. Not all tests require all parameters from the datasets. So, the dataset contains more items in the array than the parameters needed by the tests.

In Pest 2, this works without any issues. In Pest 3, this setup fails.

It would be great to have the same behavior in Pest 3 as in Pest 2. I want to avoid adding unnecessary parameters to tests that are not used in the test.

In the sample repository, I provide an example.

How to Reproduce
  • Clone the sample repository
  • Run composer install
  • Run ./vendor/bin/pest
  • The tests fail with this error
   FAILED  Tests\Unit\ExampleTest > dataset with less parameters count with (1, 1, 1) #2                   Error
  Unknown named parameter $parameterC
  str_replace(): Argument #3 ($subject) must be of type array|string, null given

  at vendor/filp/whoops/src/Whoops/Exception/FrameCollection.php:43
     39▕      * @return FrameCollection
     40▕      */
     41▕     public function filter($callable)
     42▕     {
  ➜  43▕         $this->frames = array_values(array_filter($this->frames, $callable));
     44▕         return $this;
     45▕     }
     46▕
     47▕     /**
  • Change the pest version in the composer.json to ^2.0
  • Reinstall the dependencies
  • Run ./vendor/bin/pest
  • The tests pass
Sample Repository

https://github.com/lukasleitsch/pest-issue

Pest Version

3.0.4

PHP Version

8.3.11

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

Clone the linked sample repository, run composer install and ./vendor/bin/pest, then compare the result with Pest 2 by changing composer.json to ^2.0. Trace the failing named-dataset parameter handling from the reproduction; done means tests with unused dataset parameters pass under Pest 3 without requiring unnecessary test parameters.

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
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.