简体   繁体   English

Symfony2中PHPUnit出错

[英]Error with PHPUnit in Symfony2

I have a error with PHPUnit using Symfony2 我使用Symfony2在PHPUnit上出错

In my test case I import: 在我的测试用例中我导入:

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

But, when I execute it I get: 但是,当我执行它时,我得到:

PHP Fatal error:  Class 'Symfony\Bundle\FrameworkBundle\Test\WebTestCase' not found in C:\trabajo\web\Company\src\Company\WebBundle\Tests\dbTest.php on line 11

I use to execute it: 我用来执行它:

phpunit -c app/ src/Company/WebBundle/Tests/dbTest phpunit -c app / src / Company / WebBundle / Tests / dbTest

Any help? 有帮助吗?

Thanks in advance. 提前致谢。

This is because to execute the test case with CLI you need to provide 这是因为要使用CLI执行测试用例,您需要提供

  • boostrap file /app/bootstrap.php.cache boostrap文件/app/bootstrap.php.cache
  • configuration file app/phpunit.xml.dist 配置文件app/phpunit.xml.dist

So the command would be like below: 所以命令如下:

phpunit --configuration app/phpunit.xml.dist ----bootstrap /app/bootstrap.php.cache

Bootstrap can be provided in phpunit.xml.dist as well within <phpunit> tag. Bootstrap也可以在phpunit.xml.dist中以及<phpunit>标签中提供。

The other option assuming you have good phpunit.xml.dist file is to go to app directory and there execute the tests. 假设你有一个好的phpunit.xml.dist文件的另一个选择是去app目录并执行测试。

You may adjust the paths to your needs. 您可以根据需要调整路径。

Check that you extends the dbTest class: 检查是否扩展了dbTest类:

<?php

namespace Company\WebBundle\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class dbTest extends WebTestCase
{
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM