PHPUnit 类“错误”不扩展 PHPUnit_Framework_TestCase

Posted

技术标签:

【中文标题】PHPUnit 类“错误”不扩展 PHPUnit_Framework_TestCase【英文标题】:PHPUnit Class "Error" does not extend PHPUnit_Framework_TestCase 【发布时间】:2018-06-05 08:37:45 【问题描述】:

我正在使用 Laravel 4.2 和 php 5.6。我做了一个作曲家更新,现在当我运行我的单元测试时,我得到了错误Uncaught PHPUnit_Framework_Exception: Class "Error" does not extend PHPUnit_Framework_TestCase。我不确定,但我相信我的 laravel 版本从 4.2.19 到 4.2.22

如何让我的单元测试发挥作用?

PHP 5.6.30 (cli) (built: Jan 18 2017 19:47:36)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

PHPUnit 5.7.26 by Sebastian Bergmann and contributors.

PHP Fatal error:  Uncaught PHPUnit_Framework_Exception: Class "Error" does not extend PHPUnit_Framework_TestCase.
  thrown in phar://C:/bin/phpunit-5.7.26.phar/phpunit/Framework/TestSuite.php on line 147
Fatal error: Uncaught PHPUnit_Framework_Exception: Class "Error" does not extend PHPUnit_Framework_TestCase.
  thrown in phar://C:/bin/phpunit-5.7.26.phar/phpunit/Framework/TestSuite.php on line 147

composer.json


    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": 
        "laravel/framework": "4.2.*",
        "tecnickcom/tcpdf": "6.0.*",
        "bugsnag/bugsnag-laravel": "1.*",
        "aws/aws-sdk-php": "2.*",
        "pda/pheanstalk": "2.*",
        "mockery/mockery": "0.*"
    ,
    "autoload": 
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ],
        "psr-0": 
            "idweb": "app"
        
    ,
    "scripts": 
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    ,
    "config": 
        "preferred-install": "dist"
    ,
    "minimum-stability": "stable"

作曲家表演-i

aws/aws-sdk-php               2.8.31  AWS SDK for PHP - Use Amazon Web Services in your PHP project
bugsnag/bugsnag               v2.9.2  Official Bugsnag notifier for PHP applications.
bugsnag/bugsnag-laravel       v1.7.0  Official Bugsnag notifier for Laravel applications.
classpreloader/classpreloader 1.0.2   Helps class loading performance by generating a single PHP file containing...
d11wtq/boris                  v1.0.8 
filp/whoops                   1.1.10  php error handling for cool kids
guzzle/guzzle                 v3.9.3  PHP HTTP client. This library is deprecated in favor of https://packagist....
hamcrest/hamcrest-php         v1.2.2  This is the PHP port of Hamcrest Matchers
ircmaxell/password-compat     v1.0.4  A compatibility library for the proposed simplified password hashing algor...
jeremeamia/SuperClosure       1.0.2   Doing interesting things with closures like serialization.
laravel/framework             v4.2.22 The Laravel Framework.
mockery/mockery               0.9.9   Mockery is a simple yet flexible PHP mock object framework for use in unit...
monolog/monolog               1.23.0  Sends your logs to files, sockets, inboxes, databases and various web serv...
nesbot/carbon                 1.22.1  A simple API extension for DateTime.
nikic/php-parser              v0.9.5  A PHP parser written in PHP
paragonie/random_compat       v1.4.2  PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
patchwork/utf8                v1.3.1  Portable and performant UTF-8, Unicode and Grapheme Clusters for PHP
pda/pheanstalk                v2.1.1  PHP client for beanstalkd queue
phpseclib/phpseclib           0.3.10  PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, ...
predis/predis                 v0.8.7  Flexible and feature-complete PHP client library for Redis
psr/log                       1.0.2   Common interface for logging libraries
stack/builder                 v1.0.5  Builder for stack middlewares based on HttpKernelInterface.
swiftmailer/swiftmailer       v5.4.8  Swiftmailer, free feature-rich PHP mailer
symfony/browser-kit           v2.7.39 Symfony BrowserKit Component
symfony/console               v2.7.39 Symfony Console Component
symfony/css-selector          v2.7.39 Symfony CssSelector Component
symfony/debug                 v2.7.39 Symfony Debug Component
symfony/dom-crawler           v2.7.39 Symfony DomCrawler Component
symfony/event-dispatcher      v2.8.32 Symfony EventDispatcher Component
symfony/filesystem            v2.8.32 Symfony Filesystem Component
symfony/finder                v2.7.39 Symfony Finder Component
symfony/http-foundation       v2.7.39 Symfony HttpFoundation Component
symfony/http-kernel           v2.7.39 Symfony HttpKernel Component
symfony/polyfill-mbstring     v1.6.0  Symfony polyfill for the Mbstring extension
symfony/process               v2.7.39 Symfony Process Component
symfony/routing               v2.7.39 Symfony Routing Component
symfony/security-core         v2.7.39 Symfony Security Component - Core Library
symfony/translation           v2.7.39 Symfony Translation Component
tecnickcom/tcpdf              6.0.099 TCPDF is a PHP class for generating PDF documents and barcodes.

【问题讨论】:

验证您是否有 Error 类以及它是否从 PHPUnit_Framework_TestCase 扩展 尝试对您的 php 单元进行分级。您可能使用的是旧版本 【参考方案1】:

尝试更新 phpunit 包并扩展类 Tests\TestCase 在 phpunit 最新版本的 TestCase 类中而不是 PHPUnit_Framework_TestCase..

【讨论】:

你会推荐哪个版本?我正在使用的版本是可用的最高版本,不需要 PHP7,这不是一个选项。 如果您使用的是最新版本,则将 PHPUnit_Framework_TestCase 替换为仅 TestCase

以上是关于PHPUnit 类“错误”不扩展 PHPUnit_Framework_TestCase的主要内容,如果未能解决你的问题,请参考以下文章

PHPunit - 错误

为 PHPUnit 创建一个基本测试类并将其扩展为常见功能会导致类未找到错误

扩展 PHPUnit_Framework_TestCase 的不可测试基类

PHPUnit测试类不能扩展另一个类

PHP 致命错误:找不到类 - PHPUnit

Phpunit 错误“此 PHPDBG 版本不支持代码覆盖率”