Allow single #[Examples] attribute by W0rma · Pull Request #6812 · Codeception/Codeception · GitHub
Skip to content

Allow single #[Examples] attribute#6812

Open
W0rma wants to merge 4 commits into
Codeception:mainfrom
W0rma:single-examples-attribute
Open

Allow single #[Examples] attribute#6812
W0rma wants to merge 4 commits into
Codeception:mainfrom
W0rma:single-examples-attribute

Conversation

@W0rma

@W0rma W0rma commented Dec 5, 2024

Copy link
Copy Markdown
Contributor

Fixes #6726

The current implementation of the #[Examples] attribute differs from what is documented at https://codeception.com/docs/AdvancedUsage#Examples-Attribute (reported in Codeception/codeception.github.com#870).

Futhermore, it is currently not possible to use a single #[Examples] attribute in a test.

This PR is based on #6752 which was closed automatically a few months ago and fixed the behavior.

This PR replaces #6789 which is about the same issue.

Comment on lines +42 to +43

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As already mentioned in #6752 (comment) this is a slight BC break introduced by this PR.

However, the behavior doesn't seem to be documented and from DX perspective I would prefer the new behavior.

Any thoughts about this are welcome.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first syntax allows for dereferencing from arrays using .... also what about generators? They can't use the 2nd Syntax

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first syntax allows for dereferencing from arrays using ....

Shouldn't this still be possible by just passing an array as example, f.e. #[Examples(['foo' => 'bar'])]? Please correct me if I misunderstood the problem.

what about generators? They can't use the 2nd Syntax

Do you mean that the new syntax breaks generators? Can you provide an example?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamMousa Any news about this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont remember exactly.
But I'll say this: to me having a different behaviour depending on the type of argument given to the attribute is bad design, both from a code quality as well as a DX perspective.

I don't remember this PR (it's been a while, so feel free to ignore this comment and merge if you like it.

Comment thread tests/data/SimpleWithExamplesCest.php
@W0rma W0rma force-pushed the single-examples-attribute branch from 4ecaaad to c2a260f Compare April 29, 2025 08:31
@TavoNiievez

TavoNiievez commented May 2, 2025

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Providing null data with Examples annotation fails

4 participants