2014-02-27 78 views
0

我作曲:貝哈特+ Symfony2MockerExtension:會話客戶端容器中沒有訪問

"require-dev": { 
    "polishsymfonycommunity/symfony2-mocker-extension": "*", 
    "behat/gherkin" : "~2.2.9", 
    "behat/behat": "v2.4.6", 
    "behat/symfony2-extension": "*", 
    "behat/mink-extension": "*", 
    "behat/mink-goutte-driver": "*", 
    "behat/mink-selenium2-driver": "*", 
    "phpunit/phpunit": "3.7.29" 
}, 

我的特點:

Feature: Submitting contact request form 
    Scenario: Submitting the form 
    And CRM API is available 
    Then the contact request should be sent to the CRM 

貝哈特的錯誤:

Feature: Submitting contact request form 
    Scenario: Submitting the form 
    And CRM API is available 
     Session has no access to client container 
    Then the contact request should be sent to the CRM 

我已經添加getContainerBaseClass在mi app/AppKernel()

/** 
* @return string 
*/ 
protected function getContainerBaseClass() 
{ 
    if ('test' == $this->environment) { 
     return '\PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer'; 
    } 

    return parent::getContainerBaseClass(); 
} 

和新句子在我FeatureContext:

class GeeftyContext extends MinkContext 
    implements KernelAwareInterface, ServiceMockerAwareInterface 
{ 
    /** 
    * @var ServiceMocker $mocker 
    */ 
    private $mocker = null; 

    /** 
    * @param ServiceMocker $mocker 
    * @return null|void 
    */ 
    public function setServiceMocker(ServiceMocker $mocker) 
    { 
     $this->mocker = $mocker; 
    } 

    /** 
    * @Given /^CRM API is available$/ 
    */ 
    public function crmApiIsAvailable() 
    { 
     $this->mocker->mockService(
      'my_service', 
      'Acme\Bundle\My\ServiceClass' 
     )->shouldReceive('method')->once()->andReturn(true); 
    } 

    /** 
    * @Then /^the contact request should be sent to the CRM$/ 
    */ 
    public function theContactRequestShouldBeSentToTheCrm() 
    { 
     throw new PendingException(); 
    } 
} 

回答

0

symfony的莫克擴展只能與Symfony2的貂皮驅動程序。我猜你正在嘗試將其與其他驅動程序之一一起使用。

在技術上不可能將其與Symfony2以外的驅動程序一起使用。當使用selenium2或goutte等驅動程序時,請求將在單獨的進程中處理(而Symfony2驅動程序的處理過程與此相同)。

異常消息is a bit missleading。我鼓勵你發送一個PR到the project來改善它。

編輯:如Symfony2MockerExtension#5中所述,該擴展只能在symfony2會話中使用。您可以將其設置爲默認值,如下例所示,或者使用@mink:symfony2註釋功能/場景。

default: 
    context: 
    class: 'Acme\DemoBundle\Features\Context\FeatureContext' 
    extensions: 
    PSS\Behat\Symfony2MockerExtension\Extension: ~ 
    Behat\Symfony2Extension\Extension: 
    Behat\MinkExtension\Extension: 
     default_session: symfony2 
     show_cmd: open %s 
     base_url: 'http://my.web/site/' 
     selenium2: ~ 
     goutte: ~