-1
我尝试对执行原则的控制器进行功能测试。当我执行我的测试时,它失败。但是当我在我的控制器中评论此行时:“$ 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()
);
}
}