Error with PHPUnit in Symfony2

I have a bug with PHPUnit using Symfony2

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 it to execute:

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

Any help?

Thanks in advance.

+6
source share
2 answers

This is because to run a test case with the CLI you need to provide

  • boostrap file /app/bootstrap.php.cache
  • configuration file app/phpunit.xml.dist

So, the command will look like this:

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

Bootstrap can be provided in phpunit.xml.dist, as well as in the <phpunit> .

Another option, assuming that you have a good phpunit.xml.dist file, you need to go to the application directory and run the tests.

You can customize the paths to your needs.

+2
source

Make sure you extend the dbTest class:

 <?php namespace Company\WebBundle\Tests; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class dbTest extends WebTestCase { ... } 
+1
source

Source: https://habr.com/ru/post/949819/


All Articles