【问题标题】:PHP fatal error with phpunit on Symfony 3.3.8 [duplicate]Symfony 3.3.8 上 phpunit 的 PHP 致命错误 [重复]
【发布时间】:2018-02-10 15:43:38
【问题描述】:

我在执行测试时遇到了这个错误

PHP 致命错误:在中找不到类 'PHPUnit\Framework\TestCase' /vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php 第 24 行

我可以用这个改变来解决

use PHPUnit\Framework\TestCase;
...
abstract class KernelTestCase extends TestCase

通过

abstract class KernelTestCase extends \PHPUnit_Framework_TestCase

是错误还是我错过了 Symfony 3.3.8 版本的一些配置?

谢谢

附: Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...? 的不同 该错误不是致命错误:在...中找不到类'PHPUnit_Framework_TestCase'

【问题讨论】:

  • 您可能缺少供应商文件夹中的 PHPUnit 依赖项。检查您的 composer.json 文件是否存在。如果它在require-dev 列表中,请使用composer update --dev 安装它
  • 你是如何从 Symfony 根文件夹运行测试的? exact 命令是什么?

标签: php symfony phpunit


【解决方案1】:

我可以解决这个问题。 使用 PHPUnit 5.4.6 测试工作正常,但使用 PHPUnit 5.1.3 则不行。

解决办法是

update phpci

或

将/usr/share/php/PHPUnit/ForwardCompatibility/TestCase.php 添加到“有问题的”服务器

<?php
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the     LICENSE
 * file that was distributed with this source code.
 */

namespace PHPUnit\Framework;

use PHPUnit_Framework_TestCase;

class TestCase extends PHPUnit_Framework_TestCase
{
}

并将这个类添加到/usr/share/php/PHPUnit/Autoload.php

    ...
$classes = array(
    'phpunit\\framework\\testcase' => '/ForwardCompatibility/TestCase.php',
...

谢谢。

【讨论】:

  • 您应该接受您的回答以解决问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
  • 2013-09-27
  • 1970-01-01
  • 2018-09-07
  • 1970-01-01
相关资源
最近更新 更多