在Symfony 3.3.8上使用phpunit的PHP致命错误

时间:2017-09-01 14:33:27

标签: php symfony phpunit

我在执行测试时遇到此错误

  

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的一些配置?

由于

P.S。与Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...?不同 错误不是致命错误:在'...中找不到类'PHPUnit_Framework_TestCase'

1 个答案:

答案 0 :(得分: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',
...

感谢。