Phpunit: createPartialMock called with method(s) from that do not exist can be valid use case

Created on 24 May 2020  路  9Comments  路  Source: sebastianbergmann/phpunit

| Q | A
| --------------------| ---------------
| PHPUnit version | 8.5.4
| PHP version | 7.3.11
| Installation Method | Composer

Summary

When I tried to mock an object Dibi/Fluent method from, the PhpUnit return the following message:
createPartialMock called with method(s) from that do not exist in Dibi\Fluent. This will not be allowed in future versions of PHPUnit.

Unfortunately the method select is valid callable method based on the magic __call.

Current behavior

When I create a mock with method that is valid and callable via __call but not exactly defined, the PhpUnit generate a warning.

How to reproduce

    public function testFoo(): void
    {
        $fluent = $this->createFluentMock(['from']);
        // ...
    }

    /**
     * Fluent mock factory
     *
     * @param string[] $methods [OPTIONAL] List of mocked method names
     * @return \Dibi\Fluent|MockObject
     */
    protected function createFluentMock(array $methods = []): MockObject
    {
        $mock = $this->createPartialMock(Fluent::class, $methods);
        return $mock;
    }

Expected behavior

Don't generate this warning, when the class contain __call magic.

featurtest-doubles typbug

Most helpful comment

Hi, was there an outcome to satisfy the issue described here?

All 9 comments

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

Hello @sebastianbergmann, thanks for your fast reply.
I hope that this code helps you to understand better: https://github.com/zeleznypa/phpunit-4240/blob/master/tests/DibiTest.php

This is the typical usage of the Dibi/Fluent class: https://phpfashion.com/dibifluent-tekute-sql-prikazy

Sorry, but that is not self-contained.

@sebastianbergmann I'm sorry, but I don't know what does the self-contained mean.

The repository https://github.com/zeleznypa/phpunit-4240 contain everything to reproduce the bug.

Can you please send me an example of bug-report with self-contained example?

"self-contained" means no dependencies.

@sebastianbergmann Thanks for the patience.

The dependency on Dibi was replaced with minimal code example.

Hope that this is what you want :)

Hi, was there an outcome to satisfy the issue described here?

+1 ? Running into this issue while testing post method from the GuzzleHttp\Client class

Instead of configuring methods that do not exist, configure the method that does exist: __call().

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicklevett picture nicklevett  路  4Comments

kunjalpopat picture kunjalpopat  路  4Comments

TiMESPLiNTER picture TiMESPLiNTER  路  3Comments

stephen-leavitt-sonyatv-com picture stephen-leavitt-sonyatv-com  路  4Comments

AnmSaiful picture AnmSaiful  路  4Comments