Unable to use `Examples` attribute

Open
#882 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
testing

Research direction

Start with the Examples attribute usage in the issue and the failure at vendor/codeception/codeception/src/Codeception/Lib/Di.php:122, then compare the expected behavior described in #867. Done means the shown Cest can receive Codeception\Example data and execute without the InjectionException.

Written by the indexing model from the issue text.

Description

I recently updated to codeception v5 - which works like a charm 😊
I just wanted to try out the new Examples Attribute. Unfortunately I get this:

use Codeception\Attribute\Examples;
use Codeception\Example;
use Symfony\Component\HttpFoundation\Response;
use Tests\Support\FunctionalTester;

final class LegacySeriesRedirectControllerCest
{
    #[Examples(url: '/de/series/index', expected: 'asdf')]
    public function foo(FunctionalTester $I, Example $example): void
    {
        $I->followRedirects(false);
        $I->amOnPage($example['url']);
        $I->seeRedirectTo($example['expected'], Response::HTTP_FOUND);
    }
}
 LegacySeriesRedirectControllerCest: Foo
 Test  tests/Functional/App/Controller/Frontend/LegacySeriesRedirectControllerCest.php:foo
                                                                                                                                                                                                                                            
  [InjectionException] Failed to inject dependencies in instance of 'Functional\App\Controller\Frontend\LegacySeriesRedirectControllerCest'. Failed to create instance of 'Codeception\Example'. Parameter 'data' must have default value.  
                                                                                                                                                                                                                                            
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Lib/Di.php:122
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Test/Cest.php:184
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Test/Cest.php:200
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Test/Cest.php:129
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Test/Test.php:168
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Suite.php:130
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/SuiteManager.php:151
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Codecept.php:260
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Codecept.php:216
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Command/Run.php:435
/path/to/project/okto/website/vendor/symfony/console/Command/Command.php:326
/path/to/project/okto/website/vendor/symfony/console/Application.php:1078
/path/to/project/okto/website/vendor/symfony/console/Application.php:324
/path/to/project/okto/website/vendor/symfony/console/Application.php:175
/path/to/project/okto/website/vendor/codeception/codeception/src/Codeception/Application.php:112
/path/to/project/okto/website/vendor/codeception/codeception/app.php:45
/path/to/project/okto/website/vendor/codeception/codeception/app.php:46
/path/to/project/okto/website/vendor/codeception/codeception/codecept:7
/path/to/project/okto/website/vendor/bin/codecept:119
$ symfony composer info codeception/*
codeception/codeception      5.1.2 BDD-style testing framework
codeception/lib-asserts      2.1.0 Assertion methods used by Codeception core and Asserts module
codeception/lib-innerbrowser 4.0.5 Parent library for all Codeception framework modules and PhpBrowser
codeception/lib-web          1.0.6 Library containing files used by module-webdriver and lib-innerbrowser or module-phpbrowser
codeception/lib-xml          1.0.3 Files used by module-rest and module-soap
codeception/module-asserts   3.0.0 Codeception module containing various assertions
codeception/module-doctrine  3.1.0 Doctrine module for Codeception
codeception/module-rest      3.4.0 REST module for Codeception
codeception/module-symfony   3.5.0 Codeception module for Symfony framework
codeception/module-webdriver 4.0.2 WebDriver module for Codeception
codeception/stub             4.1.3 Flexible Stub wrapper for PHPUnit's Mock Builder

According to #867 this should work. What am I doing wrong?

Dominant language
HTML
Stars
24
Forks
131
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Codeception/codeception.github.com

All issues in Codeception/codeception.github.com

Similar issues

More Testing & QA issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.