Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing null data with Examples annotation fails #6726

Open
codedge opened this issue Jan 17, 2024 · 3 comments
Open

Providing null data with Examples annotation fails #6726

codedge opened this issue Jan 17, 2024 · 3 comments

Comments

@codedge
Copy link

codedge commented Jan 17, 2024

Hey 馃憢

I use the Examples annotation to provide test data to my test case. I want to use null as values.

#[Examples('BILL', null, null, null, null)]
public function canMapValidMessages(FunctionalTester $I, Example $example): void
{
  $data = [
  	'key1' => $example[0],
  	'key2' => $example[1],
  	'key3' => $example[2],
  	'key4' => $example[3],
  ];

  // custom logic

  $I->assertNull($data['key2']);
}

Unfortunately Codeception fails with

 Codeception\Util\Annotation::arrayValue(): Argument #1 ($annotation) must be of type string, null given, called in /var/www/html/vendor/codeception/codeception/src/Codeception/Test/Data/Provider.php on line 35
  • Codeception version: 5.0.13
  • PHP Version: 8.3
  • Operating System: Alpine
@codedge codedge changed the title Providing null data with Exmaples annotation fails Providing null data with Examples annotation fails Jan 17, 2024
@Naktibalda
Copy link
Member

Does adding second Examples attribute solves this problem?

@hosseinsalemi
Copy link

It fixed when I added second Examples attribute. I need to have only one Examples attribute for some steps.

@xEdelweiss
Copy link

xEdelweiss commented Apr 12, 2024

Hi! It seems that Util/Annotation::fetchAll() handles the Example attribute incorrectly and returns an array of arrays for multiple attributes and an array of values for a single attribute.

Return structure comparison

Multiple Example annotations:

array (
  0 => '["example 1"]',
  1 => '["example 2"]',
)

Single Example annotation:

array (
  0 => '["example 1"]',
)

Multiple Example attributes:

array (
  0 => array (
    0 => 'example 1',
  ),
  1 => array (
    0 => 'example 2',
  ),
)

Actual Single Example attribute:

array (
  0 => 'example 1', 
)

Expected Single Example attribute:

array (
  0 => array (
    0 => 'example 1',
  ),
)

UPD:
@Naktibalda, I have added a PR for this.

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

No branches or pull requests

4 participants