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

Already on GitHub? Sign in to your account

Function getMetadata() may not exist, results in fatal error #4913

Closed
marcovtwout opened this issue Apr 3, 2018 · 7 comments
Closed

Function getMetadata() may not exist, results in fatal error #4913

marcovtwout opened this issue Apr 3, 2018 · 7 comments

Comments

@marcovtwout
Copy link
Contributor

@marcovtwout marcovtwout commented Apr 3, 2018

What are you trying to achieve?

Running test suite with html report.

What do you get instead?

PS S:\www\test\tests> ../vendor/bin/codecept run unit --html -vvv
Codeception PHP Testing Framework v2.4.1
Powered by PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

Unit Tests (17) -----------------------------------------------------------------------------------------------------------------------------------
Modules: Asserts, \Helper\Unit
---------------------------------------------------------------------------------------------------------------------------------------------------

  Printing HTML report into report.html

In CDbTestCase.php line 78:

  [Exception]
  Unknown method 'getMetadata' for class 'UserIdentityTest'.


Exception trace:
 CDbTestCase->__call() at S:\www\test\vendor\codeception\codeception\src\Codeception\Test\Descriptor.php:38
 Codeception\Test\Descriptor::getTestSignatureUnique() at S:\www\test\vendor\codeception\phpunit-wrapper\src\ResultPrinter\HTML.php:263
 Codeception\PHPUnit\ResultPrinter\HTML->startTest() at S:\www\test\vendor\phpunit\phpunit\src\Framework\TestResult.php:386
 PHPUnit_Framework_TestResult->startTest() at S:\www\test\vendor\phpunit\phpunit\src\Framework\TestResult.php:628
 PHPUnit_Framework_TestResult->run() at S:\www\test\vendor\phpunit\phpunit\src\Framework\TestCase.php:868
 PHPUnit_Framework_TestCase->run() at S:\www\test\vendor\phpunit\phpunit\src\Framework\TestSuite.php:733
 PHPUnit_Framework_TestSuite->run() at S:\www\test\vendor\codeception\phpunit-wrapper\src\Runner.php:106
 Codeception\PHPUnit\Runner->doEnhancedRun() at S:\www\test\vendor\codeception\codeception\src\Codeception\SuiteManager.php:157
 Codeception\SuiteManager->run() at S:\www\test\vendor\codeception\codeception\src\Codeception\Codecept.php:189
 Codeception\Codecept->runSuite() at S:\www\test\vendor\codeception\codeception\src\Codeception\Codecept.php:158
 Codeception\Codecept->run() at S:\www\test\vendor\codeception\codeception\src\Codeception\Command\Run.php:466
 Codeception\Command\Run->runSuites() at S:\www\test\vendor\codeception\codeception\src\Codeception\Command\Run.php:361
 Codeception\Command\Run->execute() at S:\www\test\vendor\symfony\console\Command\Command.php:252
 Symfony\Component\Console\Command\Command->run() at S:\www\test\vendor\symfony\console\Application.php:865
 Symfony\Component\Console\Application->doRunCommand() at S:\www\test\vendor\symfony\console\Application.php:241
 Symfony\Component\Console\Application->doRun() at S:\www\test\vendor\symfony\console\Application.php:143
 Symfony\Component\Console\Application->run() at S:\www\test\vendor\codeception\codeception\src\Codeception\Application.php:108
 Codeception\Application->run() at S:\www\test\vendor\codeception\codeception\codecept:42

Typical Yii 1 test class:

class UserIdentityTest extends CDbTestCase
{
    protected $fixtures = [
        'User'
    ];

    public function testUnknownUser()
    {
        $identity = new UserIdentity('unknown', 'test1234');

        $this->assertFalse($identity->authenticate());
    }
}

Details

  • Codeception version: latest master
  • PHP Version: 7.1
  • Operating System: any
  • Installation type: Composer

Solution

Cause: this check for is_callable() is incorrect:

if (is_callable([$testCase, 'getMetadata'])

It always returns true when a test class implements __call() (see: http://php.net/manual/en/function.is-callable.php#118623)

@marcovtwout
Copy link
Contributor Author

@marcovtwout marcovtwout commented Jul 19, 2018

I think this should be fixed by using $testCase instanceof TestInterface instead of is_callable()

@Tenzian
Copy link
Contributor

@Tenzian Tenzian commented Jul 23, 2018

@marcovtwout could you see if changing line 37 to if (method_exists($testCase, 'getMetadata') fixes your case.

@marcovtwout
Copy link
Contributor Author

@marcovtwout marcovtwout commented Jul 23, 2018

@Tenzian That works! But maybe the solution in #5086 is more appropiate?

@Tenzian
Copy link
Contributor

@Tenzian Tenzian commented Jul 23, 2018

@marcovtwout #5806 causes the problem in #4672 to come back.

@marcovtwout
Copy link
Contributor Author

@marcovtwout marcovtwout commented Jul 23, 2018

@Tenzian It seems the Cests don't implement TestInterface, so if that is the case #5086 is probably incorrect. I don't have enough deep knowledge about CodeCeption to verify the best solution, but your suggestion at least fixes this issue.

@Tenzian
Copy link
Contributor

@Tenzian Tenzian commented Jul 23, 2018

@marcovtwout #5806 also breaks Codeception/phpunit-wrapper#4 again 😞
using method_exists() seems to fix both of our issues.

@Tenzian
Copy link
Contributor

@Tenzian Tenzian commented Jul 23, 2018

@marcovtwout would you like to amend #5806, or would you prefer to close it and I'll add a new pull request from my branch?

Thanks for spotting this one. I'm going to go check my other projects for use of is_callable() that could be generating false positives. 😁

marcovtwout added a commit to marcovtwout/Codeception that referenced this issue Jul 23, 2018
Switch to solution Codeception#4913 (comment)
@DavertMik DavertMik closed this in 23a1f92 Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.