2017-09-01 73 views
2

我一直有這樣的錯誤上執行測試PHP致命錯誤與Symfony的PHPUnit的3.3.8

PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found in /vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php on line 24

我可以

abstract class KernelTestCase extends \PHPUnit_Framework_TestCase 

這種變化

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

解決是一個錯誤還是我錯過了Symfony 3.3.8版的一些配置?

謝謝

P.S.不同的Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...? 錯誤不是致命錯誤:類'PHPUnit_Framework_TestCase'找不到...

+2

您可能缺少供應商文件夾中的PHPUnit依賴項。檢查你的composer.json文件是否存在。如果它位於'require-dev'列表中,請使用'composer update --dev'安裝它。 – rickdenhaan

+0

如何從Symfony根文件夾運行測試?什麼是「確切」命令? –

回答

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 <[email protected]> 
* 
* 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 /共享/ PHP/PHPUnit的/自動加載。 php

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

謝謝。

+0

你應該接受你的答案來解決問題。 – chalasr