Codeception: IDE error when creating new unit test from 2.2.11 onwards

Created on 26 May 2017  路  21Comments  路  Source: Codeception/Codeception

What are you trying to achieve?

Create a new unit test and open the file in PHPStorm, I wouldn't expect to see any errors

What do you get instead?

IDE shows an error - Class must be declared abstract or implement methods 'count', 'run'...

Oddly the test can still run but something seems to have changed between 2.2.10 where everything is OK, 2.2.11 introduces this behavior. Also does the same in the latest stable release (2.3.1?)

Details

  • Codeception version: 2.2.11 problem first occurs, 2.2.10 is OK
  • PHP Version: PHP 5.6.30-10+deb.sury.org~trusty+2
  • Operating System: PHPStorm running on Windows. VMWare running Ubuntu
  • Installation type: Composer

image

Reproduce

Most helpful comment

Any solution here how to skip? We face the same issue.

All 21 comments

Created a basic test on Ubuntu and I can't reproduce this.
Looks like PhpStorm can't find and add to index PHPUnit_Framework_TestCase file which actually implements count and run. Please check is it visible to PHPStorm

I believe that this file is visible to PHPStorm even though my vendor folder has been "excluded" in my settings. I tried removing this exclusion but this didn't help.

Does PHPStorm shows you any notice when you look into source of Codeception\Test\Unit?

The file vendor\codeception\codeception\srcCodeception\Test\Unit.php is absolutely fine (when I exclude the vendors folder) No warnings or errors.

When I remove vendor from the excluded folders I get errors in the Unit class.

_Class must be declared abstract or implement methods 'count', 'run'_

It's probably a little off topic but I'm not 100% sure of the correct way to use "exclude folders" in PHPStorm but I tend to add my vendors folder to excluded folders as they aren't editable files but can still be used by my source code.

I'll try and recreate in a fresh project

Weirdly I don't get this error when creating a new project, bootstraping and creating a new unit test with "codeception/codeception:2.2.11".

I got the same problem.
Seems that the problem comes from shim.php
class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
meanwhile in phpunit
abstract class TestCase extends PHPUnit_Framework_TestCase

Same here, commenting:
class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
in shim.php helped. But I think it's problem with PHPStorm which doesn't "understand" that this class_alias is called only under specific conditions.

I had the same issue.
I had both phpunit and codeception in my composer.json
removing the phpunit require and composer update... "must be declared abstract" error went away.

Any solution here how to skip? We face the same issue.

Facing the same problem here.

Is there any plans to drop support for old PHPUnit versions? We could simply extend new PHPUnit 6 namespaced classes to avoid this whole issue.

@AdrianSkierniewski We are still using "5.7.22", but until recently there were no issues...

In my case, I don't see this exact error but I have a problem with code completion because of shim.php namespace aliases :)

Change bellow will fix those problems.

class Unit extends \PHPUnit_Framework_TestCase

to

class Unit extends \PHPUnit\Framework\TestCase

You can try to extend PHPUnit_Framework_TestCase unless you don't find the solution

It's PhpStorm issue and we will fix it on our side. Please vote for https://youtrack.jetbrains.com/issue/WI-40295 to get notified when the fix is available.

The problem occurs indeed due to the fact that PhpStorm doesn't support conditionally created class aliases. On our side, it's unclear for now how the problem can be addressed in both efficient and performant manner. Meanwhile, you can try to use a workaround found by CodeSniffer guys (see squizlabs/PHP_CodeSniffer#1671).

Possible workaround:

  • Right click on file codeception/codeception/shim.php
  • Mark as Plain Text

Thanks @AndrewSologor, that worked, although for me I had to mark the shim.php that was in the vendor folder of PHPUnit wrapper

JFYI The problem was fixed in PhpStorm 2018.1, see WI-40295.

@artspb Yes it's fine on my mac back home, but we are in the ridiculous situation in work where they bought us licenses for storm only a month or two ago, but their insanely restrictive network and equipment policy means that we can only install from the 'pre-approved' software list. We're stuck on 2017.2.4! :-P

Was this page helpful?
0 / 5 - 0 ratings