We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to use an anonymous function as a value in a data provider crashes phpunit.
The docs should say what the limitations are on possible data provider values.
The text was updated successfully, but these errors were encountered:
It never occurred to me that one would use anonymous functions as "values" in data providers. That being said, AFAICS it seems to work:
<?php declare(strict_types=1); namespace PHPUnit\TestFixture; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; final class DataProviderAnonymousFunctionTest extends TestCase { public static function provider(): array { return [ [function () { return true; }], ]; } #[DataProvider('provider')] public function testOne(callable $a): void { $this->assertIsCallable($a); $this->assertTrue($a()); } }
Sorry, something went wrong.
I get:
Message: Serialization of 'Closure' is not allowed Location: /var/www/html/vendor/phpunit/phpunit/src/Framework/TestRunner.php:306
But that's on PHPUnit 10.5.20.
Good to know this is supported in 11.
The use case was tests that do nearly everything the same except a few additional steps of setup -- details here https://www.drupal.org/project/drupal/issues/3278083#comment-15666084
No branches or pull requests
Trying to use an anonymous function as a value in a data provider crashes phpunit.
The docs should say what the limitations are on possible data provider values.
The text was updated successfully, but these errors were encountered: