2014-07-05 1 views
2

Behat으로 API를 테스트하려고하지만 모든 응답에서 500 점을 얻습니다.오류 500 (FOSRestBundle 및 Behat 포함)

API는 Behat 외부에서 올바르게 작동합니다. 여기

가 번들 내 config.yml 파일의 일부입니다 내 컨트롤러에 대한

fos_rest: 
    param_fetcher_listener: true 
    body_listener: true 
    routing_loader: 
     include_format: false 
    format_listener: 
     rules: 
      - { priorities: ['json','html'], fallback_format: json } 
    view: 
     view_response_listener: true 
     failed_validation: 422 
    serializer: 
     serialize_null: true 
    disable_csrf_role : IS_AUTHENTICATED_ANONYMOUSLY 

, 나는 GET/cget/... 구문을 사용하여 FOSRestController을 연장하기로 결정했습니다. 다음은 작업의 예입니다.

<?php 

namespace RcpIndex\Bundle\CoreBundle\Controller; 

use Symfony\Component\HttpFoundation\Request; 
use FOS\RestBundle\Request\ParamFetcher; 
use FOS\RestBundle\Controller\Annotations\QueryParam; 
use FOS\RestBundle\Controller\Annotations\Route; 
use FOS\RestBundle\Controller\FOSRestController; 
use FOS\RestBundle\Routing\ClassResourceInterface; 
use Nelmio\ApiDocBundle\Annotation\ApiDoc; 

use RcpIndex\Bundle\CoreBundle\Form\RcpType; 

/** 
* @package RcpIndex\Bundle\CoreBundle\Controller 
*/ 
class RcpController extends FOSRestController implements ClassResourceInterface 
{ 
    use PaginatorTrait; 

    /** 
    * Get rcp list 
    * 
    * @param ParamFetcher $paramFetcher 
    * 
    * @return \FOS\RestBundle\View\View 
    * 
    * @QueryParam(name="page", requirements="\d+", default="1", description="Current page index") 
    * @QueryParam(name="per_page", requirements="\d+", default="50", description="Number of elements displayed per page") 
    * 
    * @ApiDoc(
    * section="Rcp", 
    * description="Get rcp list", 
    * output="RcpIndex\Bundle\CoreBundle\Entity\Rcp", 
    * statusCodes={ 
    *  200="OK", 
    *  400="Bad request" 
    * } 
    *) 
    */ 
    public function cgetAction(ParamFetcher $paramFetcher) 
    { 
     list($offset, $limit) = $this->getStartAndLimitFromParams($paramFetcher); 
     $entities = $this->get('rcpindex.manager.rcp')->findAllInRange($offset, $limit); 

     return $this->view($entities, 200); 
    } 
//... 

그런 다음 내 Behat 기능이 있습니다. Behat \ MinkExtension 및 Sanpi \ Behatch를 컨텍스트 공급자로 사용합니다.

Feature: Rcplist 
    Scenario: Get empty list 
     Given I add "CONTENT_TYPE" header equal to "application/json" 
     When I send a GET request on "/api/1.0/rcps" 
     Then the response status code should be 200 

다음 오류가 나타납니다. "현재 응답 상태 코드는 500이지만 예상 한 값은 200입니다."

디버깅을 시도했지만 코드가 잘 실행되고 $ this-> view() 메서드가 catchable 예외를 throw하지 않습니다. 조금 검색 한 후에 View :: create() 메서드가 잘 작동합니다.

"cgetAction"리턴은 좋지만 Response가 처리되는 방식 일 수 있습니다. Symfony의 응답 처리에 대한 나의 열악한 지식으로는 이것을 디버깅 할 수 없습니다.

어디서 볼 수 있습니까? (또는 어떤 솔루션이 더 좋을까요?)

+0

검사 응용 프로그램/로그/파일에서 Symfony 오류인지 확인하십시오. 컨텍스트 파일을 표시하십시오. – Gustek

답변

0

나는 같은 종류의 문제가있었습니다. showAction() 방법의 캐치 섹션에서 FOS/RestBundle 번들 vendor/friendsofsymfony/rest-bundle/FOS/RestBundle/Controller/ExceptionController.phpExceptionController에서 오류가 발생 내용을 확인하기 위해 직접 예외를 덤프하려고하면 자세한 정보를 얻을 수 있습니다 :

} catch (\Exception $e) { 
     var_dump($e); 
     die(); 
     $message = 'An Exception was thrown while handling: '; 
     $message.= $this->getExceptionMessage($exception); 
     $response = new Response($message, Codes::HTTP_INTERNAL_SERVER_ERROR, $exception->getHeaders()); 
    }