Skip to content

Using @testWith annotation may generate PHP Warning: Uninitialized string offset 0 #5795

@fredericgboutin-yapla

Description

@fredericgboutin-yapla
Q A
PHPUnit version 10.5.16 (also in 9.x)
PHP version 8.2.14
Installation Method Composer

Summary

Using @testWith might generate PHP 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,

/**
 * @testWith		 [1]
 * 			 [2]
 * 			 [3]
 * 
 * @testdox This test should make phpunit spit a PHP Warning !
 */
public function testExample($arg): void
{
	$this->assertIsInt($arg);
}	

This is probably related to the explode("\n", ...) that includes empty lines in between annotations

foreach (explode("\n", $annotationContent) as $candidateRow) {

Expected behavior

No PHP warning.

Workaround

You can move the @testWith statement at the end of the comment section.

/**
 * @testdox This test should NOT make phpunit spit a PHP Warning anymore...
 * 
 * @testWith		 [1]
 * 			 [2]
 * 			 [3]
 */
public function testExample($arg): void
{
	$this->assertIsInt($arg);
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions