-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
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
Using @testWith
annotation may generate PHP Warning: Uninitialized string offset 0
#5795
Comments
will look into it |
Please note that bugs in PHPUnit 9 are no longer fixed. And while I agree that we should fix this for supported versions, please also note that annotations are deprecated and that you should use attributes instead sooner rather than later. |
@fredericgboutin-yapla I tried reproducing the issue but on my machine the code sample does not emit warnings. see #5802 (also doesnt reproduce on CI). are you sure he warnings are emitted by a plain phpunit setup and not because of some other thing? do you have a backtrace of the warning? |
Hum, that's surprising. I'm running PHP from the official Docker image using php.ini-development configuration. > php vendor/bin/phpunit tests/ExampleTest.php
PHP Warning: Uninitialized string offset 0 in /var/www/html/vendor/phpunit/phpunit/src/Metadata/Api/DataProvider.php on line 259
Warning: Uninitialized string offset 0 in /var/www/html/vendor/phpunit/phpunit/src/Metadata/Api/DataProvider.php on line 259
PHPUnit 10.5.17 by Sebastian Bergmann and contributors.
Runtime: PHP 8.2.14
Configuration: /var/www/html/phpunit.xml
... 3 / 3 (100%)
Time: 00:00.017, Memory: 6.00 MB
Example
✔ This test should NOT make phpunit spit a PHP Warning anymore... with data set 0
✔ This test should NOT make phpunit spit a PHP Warning anymore... with data set 1
✔ This test should NOT make phpunit spit a PHP Warning anymore... with data set 2
OK (3 tests, 3 assertions) <?php
class ExampleTest extends PHPUnit\Framework\TestCase
{
/**
* @testWith [1]
* [2]
* [3]
*
* @testdox This test should NOT make phpunit spit a PHP Warning anymore...
*/
public function testExample($arg): void
{
$this->assertIsInt($arg);
}
} But sure, here is the backtrace JSON encoded for readability [
{
"file": "\/var\/www\/html\/vendor\/bin\/phpunit",
"line": 122,
"args": [
"\/var\/www\/html\/vendor\/phpunit\/phpunit\/phpunit"
],
"function": "include"
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/phpunit",
"line": 104,
"function": "run",
"class": "PHPUnit\\TextUI\\Application",
"object": {},
"type": "->",
"args": [
[
"vendor\/bin\/phpunit",
"tests\/ExampleTest.php"
]
]
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/TextUI\/Application.php",
"line": 108,
"function": "buildTestSuite",
"class": "PHPUnit\\TextUI\\Application",
"object": {},
"type": "->",
"args": [
{}
]
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/TextUI\/Application.php",
"line": 349,
"function": "build",
"class": "PHPUnit\\TextUI\\Configuration\\TestSuiteBuilder",
"object": {},
"type": "->",
"args": [
{}
]
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/TextUI\/Configuration\/TestSuiteBuilder.php",
"line": 55,
"function": "testSuiteFromPath",
"class": "PHPUnit\\TextUI\\Configuration\\TestSuiteBuilder",
"object": {},
"type": "->",
"args": [
"\/var\/www\/html\/tests\/ExampleTest.php",
[
"Test.php",
".phpt"
]
]
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/TextUI\/Configuration\/TestSuiteBuilder.php",
"line": 119,
"function": "fromClassReflector",
"class": "PHPUnit\\Framework\\TestSuite",
"type": "::",
"args": [
{
"name": "ExampleTest"
}
]
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/Framework\/TestSuite.php",
"line": 134,
"function": "addTestMethod",
"class": "PHPUnit\\Framework\\TestSuite",
"object": {},
"type": "->",
"args": [
{
"name": "ExampleTest"
},
{
"name": "testExample",
"class": "ExampleTest"
}
]
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/Framework\/TestSuite.php",
"line": 486,
"function": "build",
"class": "PHPUnit\\Framework\\TestBuilder",
"object": {},
"type": "->",
"args": [
{
"name": "ExampleTest"
},
"testExample"
]
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/Framework\/TestBuilder.php",
"line": 38,
"function": "providedData",
"class": "PHPUnit\\Metadata\\Api\\DataProvider",
"object": {},
"type": "->",
"args": [
"ExampleTest",
"testExample"
]
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/Metadata\/Api\/DataProvider.php",
"line": 61,
"function": "dataProvidedByTestWithAnnotation",
"class": "PHPUnit\\Metadata\\Api\\DataProvider",
"object": {},
"type": "->",
"args": [
"ExampleTest",
"testExample"
]
},
{
"file": "\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/Metadata\/Api\/DataProvider.php",
"line": 259,
"function": "throwError",
"args": [
2,
"Uninitialized string offset 0",
"\/var\/www\/html\/vendor\/phpunit\/phpunit\/src\/Metadata\/Api\/DataProvider.php",
259
]
}
] |
@testWith
annotation may generate PHP Warning: Uninitialized string offset 0
Summary
Using
@testWith
might generatePHP Warning: Uninitialized string offset: 0
Current behavior
You launch phpunit and before you see the header you see 2 Warnings
How to reproduce
This is quite easy. You have to use
@testwith
in a way that it is followed with a blank line. For example,This is probably related to the
explode("\n", ...)
that includes empty lines in between annotationsphpunit/src/Metadata/Api/DataProvider.php
Line 252 in cd49a71
Expected behavior
No PHP warning.
Workaround
You can move the
@testWith
statement at the end of the comment section.The text was updated successfully, but these errors were encountered: