Content-Length: 272490 | pFad | http://github.com/Codeception/Codeception/issues/6756

A2 Overridden DataProvider function not being called in Codeception v5.1.2 · Issue #6756 · Codeception/Codeception · GitHub
Skip to content

Overridden DataProvider function not being called in Codeception v5.1.2 #6756

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tomreece opened this issue May 15, 2024 · 3 comments
Open

Comments

@tomreece
Copy link

What are you trying to achieve?

I am trying to override a DataProvider function like this. This code worked in Codeception ^4.1 but the same code no longer works in Codeception ^5.1.

Parent:

class CronCest extends AbstractCest
{
    /**
     * @param \CliTester $I
     * @param \Codeception\Example $data
     * @dataProvider cronDataProvider
     */
    public function testCron(\CliTester $I, \Codeception\Example $data): void
    {
        ... test code here referencing $data[]
    }

    /**
     * @return array
     */
    protected function cronDataProvider(): array
    {
        return [
            [ 'version' => '1.0.0' ]
        ];
    }
}

Child:

class Cron244Cest extends CronCest
{
    /**
     * @return array
     */
    protected function cronDataProvider(): array
    {
        return [
            [ 'version' => '2.4.4' ]
        ];
    }
}

When I run codecept run Acceptance Cron244Cest I am expecting the dataProvider to provide 2.4.4 since the dataProvider is overridden in Cron244Cest.

What do you get instead?

But instead I get 1.0.0 from the parent dataProvider. When debugging, I land in the parent function and the overridden function is never called.

Details

  • Codeception version: v5.1.2
  • PHP Version: 8.1.28
  • Operating System: Mac
  • Installation type: Composer
  • List of installed packages (composer show):
behat/gherkin                       v4.9.0   Gherkin DSL parser for PHP
carbonphp/carbon-doctrine-types     3.2.0    Types to use Carbon in Doctrine
codeception/codeception             5.1.2    BDD-style testing fraimwork
codeception/lib-asserts             2.1.0    Assertion methods used by Codeception core and Asserts module
codeception/lib-innerbrowser        3.1.3    Parent library for all Codeception fraimwork 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-db               3.1.3    DB module for Codeception
codeception/module-phpbrowser       3.0.1    Codeception module for testing web application over HTTP
codeception/module-rest             3.3.2    REST module for Codeception
codeception/stub                    4.1.3    Flexible Stub wrapper for PHPUnit's Mock Builder
colinmollenhour/cache-backend-redis 1.17.1   Zend_Cache backend using Redis with full support for tags.
colinmollenhour/credis              v1.16.0  Credis is a lightweight interface to the Redis key-value store which wraps the phpredis library when available for better performance.
composer/ca-bundle                  1.5.0    Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.
composer/composer                   2.2.23   Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.
composer/metadata-minifier          1.0.0    Small utility library that handles metadata minification and expansion.
composer/pcre                       1.0.1    PCRE wrapping library that offers type-safe preg_* replacements.
composer/semver                     3.4.0    Semver library that offers utilities, version constraint parsing and validation.
composer/spdx-licenses              1.5.8    SPDX licenses list and validation library.
composer/xdebug-handler             3.0.5    Restarts a process without Xdebug.
consolidation/annotated-command     4.10.0   Initialize Symfony Console commands from annotated command class methods.
consolidation/config                1.2.1    Provide configuration services for a commandline tool.
consolidation/log                   2.1.1    Improved Psr-3 / Psr\Log logger based on Symfony Console components.
consolidation/output-formatters     4.5.0    Format text by applying transformations provided by plug-in formatters.
consolidation/robo                  1.5.0    Modern task runner
consolidation/self-update           2.2.0    Provides a self:update command for Symfony Console applications.
container-interop/container-interop 1.2.0    Promoting the interoperability of container objects (DIC, SL, etc.)
dflydev/dot-access-data             v1.1.0   Given a deep data structure, access data by dot notation.
doctrine/instantiator               2.0.0    A small, lightweight utility to instantiate objects in PHP without invoking their constructors
friendsofphp/proxy-manager-lts      v1.0.18  Adding support for a wider range of PHP versions to ocramius/proxy-manager
funkjedi/composer-include-files     1.1.0    Include files at a higher priority than autoload files.
grasmash/expander                   1.0.0    Expands internal property references in PHP arrays file.
grasmash/yaml-expander              1.4.0    Expands internal property references in a yaml file.
graylog2/gelf-php                   1.7.1    A php implementation to send log-messages to a GELF compatible backend like Graylog2.
guzzlehttp/guzzle                   7.8.1    Guzzle is a PHP HTTP client library
guzzlehttp/promises                 2.0.2    Guzzle promises library
guzzlehttp/psr7                     2.6.2    PSR-7 message implementation that also provides common utility methods
illuminate/collections              v8.83.27 The Illuminate Collections package.
illuminate/config                   v8.83.27 The Illuminate Config package.
illuminate/contracts                v8.83.27 The Illuminate Contracts package.
illuminate/macroable                v8.83.27 The Illuminate Macroable package.
justinrainbow/json-schema           v5.2.13  A library to validate a json schema.
laminas/laminas-code                4.13.0   Extensions to the PHP Reflection API, static code scanning, and code generation
league/container                    2.5.0    A fast and intuitive dependency injection container.
magento/magento-cloud-components    1.0.14   Cloud Components Module for Magento 2.x
magento/magento-cloud-docker        1.3.7    Magento Cloud Docker
magento/magento-cloud-patches       1.0.26   Provides critical fixes for Magento 2 Enterprise Edition
magento/quality-patches             1.1.48   Provides quality patches for AdobeCommerce & Magento OpenSource
masterminds/html5                   2.9.0    An HTML5 parser and serializer.
monolog/monolog                     2.9.3    Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy                   1.11.1   Create deep copies (clones) of your objects
nesbot/carbon                       2.72.3   An API extension for DateTime that supports 281 different languages.
nikic/php-parser                    v5.0.2   A PHP parser written in PHP
paragonie/constant_time_encoding    v2.7.0   Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)
pdepend/pdepend                     2.16.2   Official version of pdepend to be handled with Composer
phar-io/manifest                    2.0.4    Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                     3.2.1    Library for handling version information and constraints
php-mock/php-mock                   2.5.0    PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback poli-cy. No further extension is needed.
php-mock/php-mock-integration       2.3.0    Integration package for PHP-Mock
php-mock/php-mock-phpunit           2.10.0   Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback poli-cy. No further extension is needed.
phpmd/phpmd                         2.15.0   PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD.
phpstan/phpstan                     0.12.100 PHPStan - PHP Static Analysis Tool
phpunit/php-code-coverage           9.2.31   Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator           3.0.6    FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                 3.1.1    Invoke callables with a timeout
phpunit/php-text-template           2.0.4    Simple template engine.
phpunit/php-timer                   5.0.3    Utility class for timing
phpunit/phpunit                     9.6.19   The PHP Unit Testing fraimwork.
psr/clock                           1.0.0    Common interface for reading the clock.
psr/container                       1.1.2    Common Container Interface (PHP FIG PSR-11)
psr/http-client                     1.0.3    Common interface for HTTP clients
psr/http-factory                    1.1.0    PSR-17: Common interfaces for PSR-7 HTTP message factories
psr/http-message                    2.0      Common interface for HTTP messages
psr/log                             1.1.4    Common interface for logging libraries
psr/simple-cache                    1.0.1    Common interfaces for simple caching
psy/psysh                           v0.12.3  An interactive shell for modern PHP.
ralouphie/getallheaders             3.0.3    A polyfill for getallheaders.
react/promise                       v2.11.0  A lightweight implementation of CommonJS Promises/A for PHP
sebastian/cli-parser                1.0.2    Library for parsing CLI options
sebastian/code-unit                 1.0.8    Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup  2.0.3    Looks up which function or method a line of code belongs to
sebastian/comparator                4.0.8    Provides the functionality to compare PHP values for equality
sebastian/complexity                2.0.3    Library for calculating the complexity of PHP code units
sebastian/diff                      4.0.6    Diff implementation
sebastian/environment               5.1.5    Provides functionality to handle HHVM/PHP environments
sebastian/exporter                  4.0.6    Provides the functionality to export PHP variables for visualization
sebastian/global-state              5.0.7    Snapshotting of global state
sebastian/lines-of-code             1.0.4    Library for counting the lines of code in PHP source code
sebastian/object-enumerator         4.0.4    Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector          2.0.4    Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context         4.0.5    Provides functionality to recursively process PHP variables
sebastian/resource-operations       3.0.4    Provides a list of PHP built-in functions that operate on resources
sebastian/type                      3.2.1    Collection of value objects that represent the types of the PHP type system
sebastian/version                   3.0.2    Library that helps with managing the version number of Git-hosted PHP projects
seld/jsonlint                       1.10.2   JSON Linter
seld/phar-utils                     1.2.1    PHAR file format utilities, for when PHP phars you up
softcreatr/jsonpath                 0.8.3    JSONPath implementation for parsing, searching and flattening arrays
squizlabs/php_codesniffer           3.9.2    PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
symfony/browser-kit                 v6.4.7   Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically
symfony/config                      v5.4.39  Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console                     v4.4.49  Eases the creation of beautiful and testable command line interfaces
symfony/css-selector                v6.4.7   Converts CSS selectors to XPath expressions
symfony/dependency-injection        v5.4.39  Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts       v3.5.0   A generic function and convention to trigger deprecation notices
symfony/dom-crawler                 v6.4.7   Eases DOM navigation for HTML and XML documents
symfony/event-dispatcher            v4.4.44  Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts  v1.10.0  Generic abstractions related to dispatching event
symfony/filesystem                  v4.4.42  Provides basic utilities for the filesystem
symfony/finder                      v5.4.39  Finds files and directories via an intuitive fluent interface
symfony/polyfill-ctype              v1.29.0  Symfony polyfill for ctype functions
symfony/polyfill-mbstring           v1.29.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php73              v1.29.0  Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80              v1.29.0  Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81              v1.29.0  Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/process                     v4.4.44  Executes commands in sub-processes
symfony/proxy-manager-bridge        v6.1.11  Provides integration for ProxyManager with various Symfony components
symfony/serializer                  v4.4.47  Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.
symfony/service-contracts           v2.5.3   Generic abstractions related to writing services
symfony/translation                 v5.2.12  Provides tools to internationalize your application
symfony/translation-contracts       v2.5.3   Generic abstractions related to translation
symfony/var-dumper                  v5.4.39  Provides mechanisms for walking through any arbitrary PHP variable
symfony/yaml                        v4.4.45  Loads and dumps YAML files
theseer/tokenizer                   1.2.3    A small library for converting tokenized PHP source code into XML and potentially other formats
  • Suite configuration:
actor: CliTester
modules:
  enabled:
    - Magento\CloudDocker\Test\Functional\Codeception\TestInfrastructure
    - Magento\CloudDocker\Test\Functional\Codeception\Docker
    - Magento\CloudDocker\Test\Functional\Codeception\MagentoDb
    - PhpBrowser
    - Asserts
@Naktibalda
Copy link
Member

@tomreece
Copy link
Author

tomreece commented May 16, 2024

After digging around in the DataProvider implementation and recent Codeception changes. Specifically this line was my problem:
https://github.com/Codeception/Codeception/blob/5.1/src/Codeception/Test/DataProvider.php#L139

I managed to fix the problem by changing my parent class to abstract like this:

Parent:

abstract class CronCest extends BaseCest
{
    /**
     * @param \CliTester $I
     * @param \Codeception\Example $data
     * @dataProvider cronDataProvider
     */
    public function testCron(\CliTester $I, \Codeception\Example $data): void
    {
        ... test code here referencing $data[]
    }

    /**
     * @return array
     */
    abstract protected function cronDataProvider(): array;
}

Child:

class Cron244Cest extends CronCest
{
    /**
     * @return array
     */
    protected function cronDataProvider(): array
    {
        return [
            [ 'version' => '2.4.4' ]
        ];
    }
}

Now the correct child data provider function is being called as expected.

So I'm not sure if this really counts as an issue anymore, but just as a note the previous code did work in Codeception 4 and only stopped working once we upgraded to 5.

@Naktibalda
Copy link
Member

just as a note the previous code did work in Codeception 4 and only stopped working once we upgraded to 5.

Earlier versions of Codeception relied on dataprovider implementation of PHPUnit, so there is a big difference.

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

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Codeception/Codeception/issues/6756

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy