2013-12-20 2 views
2

Symfony2 프로젝트에 Behat을 설치했는데 사용자 정의 정의가로드되지 않았습니까?Behat + Symfony, 사용자 정의 정의가로드되지 않았습니다.

behat.yml

default: 
    paths: 
    features: features 
    extensions: 
    Behat\Symfony2Extension\Extension: 
     mink_driver: true 
     kernel: 
     env: test 
     debug: true 
    Behat\MinkExtension\Extension: 
     base_url: 'http://myproject.local/app_test.php/' 
     goutte: ~ 

기능/부트 스트랩/FeatureContext.php

<?php 

use Behat\Behat\Context\ClosuredContextInterface, 
    Behat\Behat\Context\TranslatedContextInterface, 
    Behat\Behat\Context\BehatContext, 
    Behat\Behat\Exception\PendingException; 
use Behat\Gherkin\Node\PyStringNode, 
    Behat\Gherkin\Node\TableNode; 

use Symfony\Component\HttpKernel\KernelInterface; 
use Behat\Symfony2Extension\Context\KernelAwareInterface; 
use Behat\MinkExtension\Context\MinkContext; 
use Behat\Behat\Context\Step; 

class FeatureContext extends MinkContext implements KernelAwareInterface 
{ 

    private $kernel; 
    private $parameters; 

    /** 
    * Initializes context. 
    * Every scenario gets its own context object. 
    * 
    * @param array $parameters context parameters (set them up through behat.yml) 
    */ 
    public function __construct(array $parameters) 
    { 
     // Initialize your context here 
     $this->parameters = $parameters; 
    } 

    /** 
    * Sets HttpKernel instance. 
    * This method will be automatically called by Symfony2Extension ContextInitializer. 
    * 
    * @param KernelInterface $kernel 
    */ 
    public function setKernel(KernelInterface $kernel) 
    { 
     $this->kernel = $kernel; 
    } 

    /** 
    * @Given /^I am logged in as "([^"]*)" with "([^"]*)" password$/ 
    */ 
    public function iAmLoggedInAsWithPassword($username, $password) 
    { 
     return array(
      new Step\Given("I am on \"/login\""), 
      new Step\When("I fill in \"Username\" with \"$username\""), 
      new Step\When("I fill in \"Password\" with \"$password\""), 
      new Step\When("I press \"Login\""), 
    ); 
    } 
} 

시나리오 :

이 하나가 괜찮 :

Scenario: Login success 
    Given I am on "/login" 
    ... 
하지만이 일이 내 정의를 구현해야 말해 :

Scenario: Logout 
    Given I am logged in as "[email protected]" with "password" password 

오류 :

Vous pouvez implémenter les définitions d'étapes pour les étapes non définies avec ces modèles : 

    /** 
    * @Given /^I am logged in as "([^"]*)" with "([^"]*)" password$/ 
    */ 
    public function iAmLoggedInAsWithPassword($arg1, $arg2) 
    { 
     throw new PendingException(); 
    } 

composer.json : 실제로

"require": { 
    "behat/behat": "v2.5.1", 
    "behat/mink": "v1.5.0", 
    "behat/symfony2-extension": "v1.1.0", 
    "behat/mink-extension": "v1.2.0", 
    "behat/mink-selenium2-driver": "v1.1.1", 
    "behat/mink-goutte-driver": "v1.0.9" 
}, 

답변

3

Symfony2 확장은 경로를 변경하고 FeatureContext의 네임 스페이스 (번들의 컨텍스트 파일을 찾습니다)도 변경합니다. 또한 컨텍스트를로드하는 작곡가의 오토로더를 구성해야 할 수 있습니다

default: 
    paths: 
    features: features 
    context: 
    class: FeatureContext 
    extensions: 
    Behat\Symfony2Extension\Extension: 
     mink_driver: true 
     kernel: 
     env: test 
     debug: true 
    Behat\MinkExtension\Extension: 
     default_session: symfony2 

: 당신이 번들 외부에서 기능을 유지하려면

, 당신은 주요 문맥 클래스 (context.class)를 지정해야 파일은 /bootstrap입니다. 당신의 composer.json의 해당 업데이트에게 자동로드 섹션을 수행하려면 :

"autoload": { 
    "psr-0": { "": ["src/", "features/bootstrap/"]} 
}, 
+0

완벽하게 감사드립니다! 내가 문서에서 찾지 못했는데, 링크가 있니? 여기 – Tib

+1

: http://docs.behat.org/guides/7.config.html#context –

0

, 내가 돈 ' 여기서 문제를 보지 마라.

bin/behat -dl을 실행하고 단계 정의가 인쇄되어 있는지 확인할 수 있습니까?

+0

을 나는 이미하지만 내 사용자 정의가 여기되지 않았다. 홈페이지에 $ /'~/^ (마지막 응답 $ /'표시하고 있지만 주어진/^ 나는 (으)로 로그인했습니다. '([^"] *)"with "([^"] *) "password $ /' – Tib

관련 문제