Codeception: Warning: Cannot declare class PHPUnit_Framework_Assert, because the name is already in use.

Created on 31 Aug 2017  路  2Comments  路  Source: Codeception/Codeception

What are you trying to achieve?

Run unit tests generated by Codeception

What do you get instead?

A very annoying warning message

Provide console output if related. Use -vvv mode for more details.

Warning: Cannot declare class PHPUnit_Framework_Assert, because the name is already in use in /Users/<me>/Code/theutz/advanced-custom-enums/vendor/codeception/codeception/shim.php on line 17

Call Stack:
0.0003     373480   1. {main}() /Users/<me>/Code/theutz/advanced-custom-enums/vendor/codeception/codeception/codecept:0
0.0005     401560   2. require_once('/Users/<me>/Code/theutz/advanced-custom-enums/vendor/codeception/codeception/autoload.php') /Users/michaelutz/Code/theutz/advanced-custom-enums/vendor/codeception/codeception/codecept:7
0.0087    1765936   3. include_once('/Users/<me>/Code/theutz/advanced-custom-enums/vendor/codeception/codeception/shim.php') /Users/michaelutz/Code/theutz/advanced-custom-enums/vendor/codeception/codeception/autoload.php:45
0.0103    2021592   4. class_alias() /Users/<me>/Code/theutz/advanced-custom-enums/vendor/codeception/codeception/shim.php:17

Details

  • Codeception version: 2.3.5, PHP Unit 6.2.4
  • PHP Version: 7.0.22
  • Operating System: Mac OSX Sierra 10.12.6
  • Installation type: Composer

Most helpful comment

Are you using the latest Codeception\Verify? This hit me earlier as well, it's caused by https://github.com/Codeception/Verify/pull/31 - for now, I've set my Verify version to 0.3.3.

The problem comes from https://github.com/Codeception/Codeception/blob/2.3/shim.php#L16 - Codeception only checks if (!class_exists('PHPUnit_Framework_TestCase') && class_exists('PHPUnit\Framework\TestCase')) however, it creates aliases for all PHPUnit 6 classes used by Codeception. In Verify, an alias is defined for PHPUnit_Framework_Assert:
https://github.com/Codeception/Verify/blob/master/src/Codeception/function.php#L2

In my opinion, either all classes in the shim file should be checked before aliased, or at least the ones aliased in Verify so the two libraries work together. Apparently Verify is used without Codeception (and the PR fixed an issue in such case). Funnily, that fix breaks Codeception.

Edit: I've decided to make a PR to try to get this somewhere.

All 2 comments

Are you using the latest Codeception\Verify? This hit me earlier as well, it's caused by https://github.com/Codeception/Verify/pull/31 - for now, I've set my Verify version to 0.3.3.

The problem comes from https://github.com/Codeception/Codeception/blob/2.3/shim.php#L16 - Codeception only checks if (!class_exists('PHPUnit_Framework_TestCase') && class_exists('PHPUnit\Framework\TestCase')) however, it creates aliases for all PHPUnit 6 classes used by Codeception. In Verify, an alias is defined for PHPUnit_Framework_Assert:
https://github.com/Codeception/Verify/blob/master/src/Codeception/function.php#L2

In my opinion, either all classes in the shim file should be checked before aliased, or at least the ones aliased in Verify so the two libraries work together. Apparently Verify is used without Codeception (and the PR fixed an issue in such case). Funnily, that fix breaks Codeception.

Edit: I've decided to make a PR to try to get this somewhere.

I've actually run into the same problem. In my case the Codeception tests are included in a phing build process and this issue causes the build to fail.

Gladly the fix mentioned by @ddinchev - setting the Verify version to 0.3.3 - works fine for me. But I agree that all classes should be checked before creating an alias for them in the shim file.

Was this page helpful?
0 / 5 - 0 ratings