Fix incorrect Annotation::fetchAll() return structure for single Examples attribute#6752
Fix incorrect Annotation::fetchAll() return structure for single Examples attribute#6752xEdelweiss wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
This change broke tests\cli\RunCest.php:runWithExamples
Please fix it.
There was a problem hiding this comment.
I've missed this test, but it is the one that highlights the issue and conflicts with the changes I propose in this PR.
It is confusing that a single #[Example] attribute is treated not in the same way as multiple ones.
This also forces you to update attribute arguments when you move from single #[Example] to multiple and vice versa.
Like in this flow:
// write simple test - works
#[Examples([1, 1])]
public function example1(AttrsTester $I, Example $e)
{
$I->assertEquals($e[1], $e[0]);
}
// duplicate line, update data - fails
#[Examples([1, 1])]
#[Examples([2, 2])]
public function example2(AttrsTester $I, Example $e)
{
$I->assertEquals($e[1], $e[0]);
}
// unwrap arrays to make it work - works
#[Examples(1, 1)]
#[Examples(2, 2)]
public function example3(AttrsTester $I, Example $e)
{
$I->assertEquals($e[1], $e[0]);
}
// same in the opposite directionI see how this change can introduce backward incompatibility for those who have used a single #[Example]. But since the documentation does not describe the specific behavior of a single #[Example], I don't think it's a big issue compared to the improved developer experience.
So I propose to update the tests\cli\RunCest.php:runWithExamples.
I'd appreciate your thoughts on this.
| Annotation::forMethod($class, 'multipleAttributes')->fetchAll('example')); | ||
|
|
||
| $this->assertSame( | ||
| [['example 1/1']], |
There was a problem hiding this comment.
phpcs doesn't like style of this file
There was a problem hiding this comment.
Sorry, my bad. Missed PHPCS checks. Fixed.
|
This PR was auto closed because I deleted the 5.1 branch. |

I had an issue similar to #6726, caused by how
Annotation::fetchAll()handles the single#[Examples]attribute.Here are comparison of
fetchAll()return structures:This PR includes a fix and unit-tests update for this issue. It also has a test for the
#[Given]attribute to show that the changes do not break it.