Phpunit: Combined use of @depends and @dataProvider is not handled correctly

Created on 2 Jun 2018  路  5Comments  路  Source: sebastianbergmann/phpunit

| Q | A
| --------------------| ---------------
| PHPUnit version | 7.1.5
| PHP version | 7.2.5
| Installation Method | Composer

composer info | sort

doctrine/instantiator              1.1.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
myclabs/deep-copy                  1.8.0 Create deep copies (clones) of your objects
phar-io/manifest                   1.0.1 Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                    1.0.1 Library for handling version information and constraints
phpdocumentor/reflection-common    1.0.1 Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock  4.3.0 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embed...
phpdocumentor/type-resolver        0.4.0
phpspec/prophecy                   1.7.6 Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage          6.0.5 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          1.4.5 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template          1.2.1 Simple template engine.
phpunit/php-timer                  2.0.0 Utility class for timing
phpunit/php-token-stream           3.0.0 Wrapper around PHP's tokenizer extension.
phpunit/phpunit                    7.1.5 The PHP Unit Testing framework.
phpunit/phpunit-mock-objects       6.1.2 Mock Object library for PHPUnit
sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or method a line of code belongs to
sebastian/comparator               3.0.0 Provides the functionality to compare PHP values for equality
sebastian/diff                     3.0.0 Diff implementation
sebastian/environment              3.1.0 Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 3.1.0 Provides the functionality to export PHP variables for visualization
sebastian/global-state             2.0.0 Snapshotting of global state
sebastian/object-enumerator        3.0.3 Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector         1.1.1 Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context        3.0.0 Provides functionality to recursively process PHP variables
sebastian/resource-operations      1.0.0 Provides a list of PHP built-in functions that operate on resources
sebastian/version                  2.0.1 Library that helps with managing the version number of Git-hosted PHP projects
theseer/tokenizer                  1.1.0 A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert                   1.3.0 Assertions to validate method input/output with nice error messages.

Description

PHP unit test was working perfectly in version 7.1.5 and since 7.2.0 it is broken.
See on my repository : https://github.com/wdes/account-manager/issues/5

Sample code

<?php
declare(strict_types = 1);

namespace Test;
use PHPUnit\Framework\TestCase;
use \stdClass;

class TestTest extends TestCase
{

    public function testConstants(): stdClass
    {
        $this->assertStringEndsWith('/', "/");
        return new stdClass();
    }

    public function dataSelectOperatorsProvider(): array
    {
        return [
            ["1"],
            ["2"]
        ];
    }

    /**
     * @depends testConstants
     * @dataProvider dataSelectOperatorsProvider
     *
     * @return void
     */
    public function testDependsRequire(string $val, stdClass $obj): void
    {
        $this->assertStringEndsWith('/', "/");
    }

}

Maybe related to : #183

typbug

Most helpful comment

Thank you, @williamdes and @epdenouden!

All 5 comments

CC @epdenouden

@sebastianbergmann thanks, already having a in look https://github.com/epdenouden/phpunit/tree/issue-3156-depends-dataprovider-broken

@williamdes Thanks for taking the time for the detailed bug report. The bug is related to #3092. I have added your sample code as a regression test to provide extra safety for the new sorter. :)

Background information from the manual

When a test receives input from both a @dataProvider method and from one or more tests it @depends on, the arguments from the data provider will come before the ones from depended-upon tests. The arguments from depended-upon tests will be the same for each data set. See Example 2.9

Thank you, @williamdes and @epdenouden!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kunjalpopat picture kunjalpopat  路  4Comments

rentalhost picture rentalhost  路  4Comments

ezzatron picture ezzatron  路  3Comments

TiMESPLiNTER picture TiMESPLiNTER  路  3Comments

joubertredrat picture joubertredrat  路  4Comments