I am working on testing using the Symfony2 application (2.7.3), and the page controller does not load the class only when the request is sent from PHPUnit (4.8.6).
The test is as follows:
<?php
namespace AppBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PagesAvailableTest extends WebTestCase
{
public function testpages()
{
$client = static::createClient();
$client->request('GET', '/contact');
}
}
and throws this error when starting with $ phpunit -c app/:
PHP Fatal error: Class 'AppBundle \ Entity \ ContactMessage' not found in SymfonyRoot /src/AppBundle/Controller/ContactController.php on line 28
When called through a browser, the page loads as expected. When called with $ curl -I http://localhost/contact, page statusHTTP/1.1 200 OK
, , Symfony docs , :
- bootstrap.php.cache( app/phpunit.xml.dist).
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="bootstrap.php.cache"
>
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
<directory>../src/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*Bundle/Resources</directory>
<directory>../src/*Bundle/Tests</directory>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
PHPUnit?