PHPUnit类“Error”不扩展PHPUnit_Framework_TestCase

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHPUnit类“Error”不扩展PHPUnit_Framework_TestCase相关的知识,希望对你有一定的参考价值。

我正在使用带有php 5.6的Laravel 4.2。我做了一个作曲家更新,现在当我运行我的单元测试时,我得到错误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.
答案

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

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

扩展 PHPUnit_Framework_TestCase 的不可测试基类

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

PhpStorm:未找到类'PhpUnit Framework TestCase'(composer / autoload)

PHPUnit - 开发后创建测试

为啥通过 PhpUnit 运行测试时找不到我的自定义 TestCase 类?

PHPUnit:找不到我的包类