Skip to content

Generator yielding keys that are neither integer or string leads to hard-to-understand error message when used as data provider #4625

@BackEndTea

Description

@BackEndTea
Q A
PHPUnit version 9.5.3
PHP version 7.4.16
Installation Method Composer

Summary

When a non int/string key is provided from a generator dataprovider you get an error. This is to be expected. However the error does not make it obvious what went wrong.

Current behavior

vendor/bin/phpunit --debug
Warning: array_key_exists(): The first argument should be either a string or an integer in /project/vendor/phpunit/phpunit/src/Util/Annotation/DocBlock.php on line 438

How to reproduce

Create a dataprovider that has a non int/string key. and use it in a test (This is valid in PHP btw https://3v4l.org/sbeOf)

Expected behavior

I'd expect to get an error with a clear message, telling me that i'm using a non int/string key in a dataprovider, which is not supported. Prehaps with the type i am using.

Because the error mentions Util/Annotation/DocBlock.php we initially though phpunit was failing due to a wrong annotation somewhere.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions