user2599114
user2599114

Reputation: 69

Error with PHPUnit in Symfony2

I have a error 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 to execute it:

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

Any help?

Thanks in advance.

Upvotes: 6

Views: 3461

Answers (2)

Robert
Robert

Reputation: 20286

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

  • boostrap file /app/bootstrap.php.cache
  • configuration file 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.

The other option assuming you have good phpunit.xml.dist file is to go to app directory and there execute the tests.

You may adjust the paths to your needs.

Upvotes: 2

Nothing
Nothing

Reputation: 187

Check that you extends the dbTest class:

<?php

namespace Company\WebBundle\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class dbTest extends WebTestCase
{
    ...
}

Upvotes: 1

Related Questions