2015-01-12 3 views
1
Behat \ 오이 \ 노드 \의 인스턴스 여야합니다

나는이 내 다음과 같은 방법 내 FeatureContext.php :Behat 문자열 PyStringNode

/** 
* @When /^I send a ([A-Z]+) request to "([^"]*)" (with the data)$/ 
*/ 
public function iSendARequestToWithData($method, $uri, PyStringNode $string) 
{ 
    $request  = $this->client->createRequest($method, $this->base_url.$uri); 
    $this->response = $this->client->send($request); 
} 

내 기능을 실행,이 줄은 실패

When I send a POST request to "/items" with the data 
    """ 
     { 
      "category": 1 
     } 
    """ 

으로 다음 오류 :

Catchable Fatal Error: Argument 3 passed to FeatureContext::iSendARequestToWithData() must be an instance of Behat\Gherkin\Node\PyStringNode, string given in app/tests/acceptance/FeatureContext.php line 68 

나는이 정규 표현식, 특히 (with the data),하지만 난 그걸 고칠 방법을 전혀 모른다.

답변

-2

실제로 아무도 모른다는 것을 알고있는 동안 PyStringNode은 (는) 당신의 메서드가 PyStringNode 클래스의 개체를 필요로합니다.

$string = new PyStringNode(); 

을 당신이 정말 그렇게 엄격한 서명의 혜택을하지 않는 것로 iSendARequestToWithData() 기능이 합격하거나, 함수 서명을 변경하고 그것에서 PyStringNode을 제거 : 그래서 당신은 기본적으로 좋아 만들어야합니다.

public function iSendARequestToWithData($method, $uri, $string) 
0

behat는 호출해야하는 메소드의 단계를 일치시키기 위해 regular expressions을 사용합니다. 정규 표현식 하위 패턴은 메소드 인수를 일치시키는 데 사용됩니다.

서브 패턴

정규 표현식에서 각 서브 패턴은 당신의 방법에 대한 인수로 사용된다. 당신의 예에서

:

  • ([A-Z]+)$method
  • ([^"]*)로 전달 될 것이다이에, 마지막으로 전달되는 $string
  • PyStringNode$uri
  • (with the data)로 전달됩니다 대문자 소문자 네 번째 인수.

    /** 
    * @When /^I send a ([A-Z]+) request to "([^"]*)" (?:with the data)$/ 
    */ 
    public function iSendARequestToWithData($method, $uri, PyStringNode $string) 
    { 
    } 
    

    : 귀하의 예제를 해결하려면

    (?:non matching pattern) 
    

    : 인수를 캡처하지 않으려면

비의 서브 패턴을

사용 비의 서브 패턴 명명 된 하위 패턴

명명 된 하위 패턴을 사용하여 일치 패턴이 전달되어야하는 위치를 명시 적으로 말할 수도 있습니다.이러한 경우 문제가되지 않는 패턴을 통해 일치하는 인수의 순서는, Behat 이름으로 그들을 일치 :

/** 
* @When /^I send a (?P<method>[A-Z]+) request to "(?P<uri>[^"]*)" (?:with the data)$/ 
*/ 
public function iSendARequestToWithData($method, $uri, PyStringNode $string) 
{ 
} 

순무 구문은 3 Behat

내가 사용하는 것이 좋습니다 순무 구문을 사용하면 경우 정규식에 익숙하지 않습니다.

/** 
* @When I send a :method request to :uri with the data 
*/ 
public function iSendARequestToWithData($method, $uri, PyStringNode $string) 
{ 
} 
관련 문제