Я пытаюсь выполнить функциональный тест на контроллере, который выполняет доктрину. Когда я выполняю свой тест, он терпит неудачу. но когда я прокомментировал в своем контроллере эту строку: «$ products = $ em-> getRepository (« Couture \ FrontBundle \ Entity \ Produit ») -> findAll()". мой тест - успех.PB Функциональный тест Контроллер symfony2
это мой контроллер:
class ProductController extends Controller {
/**
* Get products
* @Route("/products")
* @Method("GET")
*/
public function getAllAction() {
$serialize = $this->get('jms_serializer');
$em = $this->getDoctrine();
$products = $em->getRepository('Couture\FrontBundle\Entity\Produit')->findAll();
if (!$products) {
$response = new Response(json_encode(array('error' => 'Resources not found for products')));
$response->headers->set('Content-Type', 'application/json');
$response->setStatusCode('400');
return $response;
}
$response = new Response($serialize->serialize($products, 'json'));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}
это мой тестовый класс:
class ProductControllerTest extends WebTestCase {
public function testGetAll() {
$client = static::createClient();
$client->request('GET', $client->getContainer()->get('router')->generate('couture_front_product_getall'));
$this->assertEquals(
200, $client->getResponse()->getStatusCode()
);
}
}