Codeception: Codeception/Test classes with Interface Descriptive has problem with phpunit 7 typehint from Interface PHPUnit\Framework\SelfDescribing

What are you trying to achieve?

Using codeception 2.4 with phpunit 7.1.5 and want to start the tests via console vendor/bin/codecept run

What do you get instead?

It breaks with a Fatal Error:

  Compile Error: Declaration of Codeception\Test\Test::toString() must be compatible with PHPUnit\Framework\SelfDescribing::toString(): string

Details

  • Codeception version: 2.4
  • phpunit version: 7.1.5
  • PHP Version: 7.2.6
  • Operating System: Ubuntu 16.04
  • Installation type: Composer

codeception 2.4 with phpunit < 7 (in my case phpunit 6.5.8) works as expected.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 29 (21 by maintainers)

Commits related to this issue

Most upvoted comments

I think the problem is that the phpunit-wapper only works if the PHPUnit\Framework\SelfDescribing is not loaded before Codeception\PHPUnit\Init::init() is executed.

My dependencies are:

  • “phpunit/phpunit”: “^8.2”,
  • “codeception/codeception”: “^3.0”
  • “symfony/phpunit-bridge”: “^4.3.2”
  • “php-mock/php-mock-phpunit”: “^2.4”

Tests:

If I remove all dev dependencies except codeception from my project it works. Because the !interface_exists(SelfDescribing::class, false) return true.

If I only add phpunit and codeception to the dependency it also works. Because the !interface_exists(SelfDescribing::class, false) return true.

If I install phpunit, codeception and symfony/phpunit-bridge it also works. Because the !interface_exists(SelfDescribing::class, false) return true.

But if I install php-mock/php-mock-phpunit I got the error, because php-mock-phpunit also have an autoload-file which defines some class-aliases and when it calls the interface_exists(\PHPUnit\Framework\MockObject\Matcher\Invocation::class) function the autoloader kicks in and load the interface and it’s parents interfaces in the ram. So the !interface_exists(SelfDescribing::class, false) return false and the orignal interface is loaded.

So maybe you should add php-mock/php-mock-phpunit to the conflicts section in your composer.json But this don’t fix the loading issue.

@DavertMik I’m hitting the same issue. I actually commented on #4978 about it, but since this ticket’s open, I’ll re-post my output here:

Codeception PHP Testing Framework v2.4.2
Powered by PHPUnit 7.1.5 by Sebastian Bergmann and contributors.
PHP Fatal error:  Declaration of Codeception\Test\Test::toString() must be compatible with PHPUnit\Framework\SelfDescribing::toString(): string in /vagrant/lib/vendor/codeception/codeception/src/Codeception/Test/Test.php on line 18
PHP Stack trace:
PHP   1. {main}() /vagrant/lib/vendor/codeception/codeception/codecept:0
PHP   2. Codeception\Application->run() /vagrant/lib/vendor/codeception/codeception/codecept:42
PHP   3. Codeception\Application->run() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Application.php:108
PHP   4. Codeception\Application->doRun() /vagrant/lib/vendor/symfony/console/Application.php:122
PHP   5. Codeception\Application->doRunCommand() /vagrant/lib/vendor/symfony/console/Application.php:215
PHP   6. Codeception\Command\Run->run() /vagrant/lib/vendor/symfony/console/Application.php:858
PHP   7. Codeception\Command\Run->execute() /vagrant/lib/vendor/symfony/console/Command/Command.php:240
PHP   8. Codeception\Command\Run->runSuites() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Command/Run.php:361
PHP   9. Codeception\Codecept->run() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Command/Run.php:466
PHP  10. Codeception\Codecept->runSuite() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Codecept.php:158
PHP  11. Codeception\SuiteManager->loadTests() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Codecept.php:188
PHP  12. Codeception\Test\Loader->loadTests() /vagrant/lib/vendor/codeception/codeception/src/Codeception/SuiteManager.php:95
PHP  13. Codeception\Test\Loader\Cept->loadTests() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Test/Loader.php:134
PHP  14. spl_autoload_call() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Test/Loader/Cept.php:21
PHP  15. Composer\Autoload\ClassLoader->loadClass() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Test/Loader/Cept.php:21
PHP  16. Composer\Autoload\includeFile() /vagrant/lib/vendor/composer/ClassLoader.php:322
PHP  17. include() /vagrant/lib/vendor/composer/ClassLoader.php:444
PHP  18. spl_autoload_call() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Test/Cept.php:12
PHP  19. Composer\Autoload\ClassLoader->loadClass() /vagrant/lib/vendor/codeception/codeception/src/Codeception/Test/Cept.php:12
PHP  20. Composer\Autoload\includeFile() /vagrant/lib/vendor/composer/ClassLoader.php:322
PHP  21. include() /vagrant/lib/vendor/composer/ClassLoader.php:444

Here’s a truncated output of my composer show, to prove I’m running the latest of Codeception and PHPUnit Wrapper:

...
codeception/codeception             2.4.2              BDD-style testing framework
codeception/phpunit-wrapper         7.1.3              PHPUnit classes used by Codeception
codeception/stub                    2.0.1              Flexible Stub wrapper for PHPUnit's Mock Builder
...
phpunit/dbunit                      4.0.0              PHPUnit extension for database interaction testing
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/finder-facade             1.2.2              FinderFacade is a convenience wrapper for Symfony's Finder component.
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/phpcpd                    4.0.0              Copy/Paste Detector (CPD) for PHP code.
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
...

@DavertMik why does codeception 3.0 still support PHP 5.6? Wasn’t this the perfect chance to get a rid of the dependency? Because otherwise it is not possible to use codeception with phpunit 7/8 and php >=7.1 or is there a other way?

@DavertMik Any update on this by chance? I noticed some updates around 7.2 support, so I updated codeception/codeception to 2.4.5, phpunit/phpunit to 7.2.7, and codeception/phpunit-wrapper to 7.2.0, but I’m still hitting the same error.

If you need a more detailed proof of concept, let me know, and I’ll take another look at what the most minimal repro steps are.