使用 Sylius / Behat 测试多个通道 - UnexpectedPageException

Testing multiple channels with Sylius / Behat - UnexpectedPageException

使用多个通道时测试失败,当我使用单个通道时 @When I visit homepage 步骤工作正常..

行为特征:

  Background:
    Given the store operates on a single channel
    And the store operates on another channel named "ChannelA"
    And the store operates on another channel named "ChannelB"

  @ui
  Scenario: Navigating to some channel when clicking on the shop block
    When I visit the homepage

失败于:

/**
 * @When I visit the homepage
 */
public function iVisitTheHomePage()
{
    try {
        $this->homePage->open();
    } catch (UnexpectedPageException $e) {
        dump($e);
        die();
    }
}

测试数据库中可用的频道:

注意到测试数据库中通道的'HOST'在测试单个通道时保持为NULL,但在使用多个通道时也是如此..所以看起来是不是问题..

1809    NULL    NULL    DEFAULT     Default     NULL    NULL    1   NULL    2016-10-31 10:20:45 2016-10-31 10:20:45 NULL    NULL    order_items_based
1810    NULL    NULL    CHANNELA    ChannelA    NULL    NULL    1   NULL    2016-10-31 10:20:45 2016-10-31 10:20:45 NULL    NULL    order_items_based
1811    NULL    NULL    CHANNELB    ChannelB    NULL    NULL    1   NULL    2016-10-31 10:20:45 2016-10-31 10:20:45 NULL    NULL    order_items_based

意外页面异常:

Sylius\Behat\Page\UnexpectedPageException {#9766
  #message: "Could not open the page: "http://localhost:8080/". Received an error status code: 500"
  #code: 0
  #file: "/var/www/html/vendor/sylius/sylius/src/Sylius/Behat/Page/Page.php"
  #line: 117
  -trace: {
    35. Sylius\Behat\Page\Page->verifyStatusCode() ==> new Sylius\Behat\Page\UnexpectedPageException(): {
      src: {
        /var/www/html/vendor/sylius/sylius/src/Sylius/Behat/Page/Page.php:117: """
          \n
              throw new UnexpectedPageException($message);\n
          }\n
          """
      }
    }
    34. Sylius\Behat\Page\Page->verify() ==> Sylius\Behat\Page\Page->verifyStatusCode(): {
      src: {
        /var/www/html/vendor/sylius/sylius/src/Sylius/Behat/Page/Page.php:74: """
          {\n
              $this->verifyStatusCode();\n
              $this->verifyUrl($urlParameters);\n
          """
      }
      args: []
    }
    33. Sylius\Behat\Page\Page->open() ==> Sylius\Behat\Page\Page->verify(): {
      src: {
        /var/www/html/vendor/sylius/sylius/src/Sylius/Behat/Page/Page.php:58: """
              $this->tryToOpen($urlParameters);\n
              $this->verify($urlParameters);\n
          }\n
          """
      }
      args: array:1 [
        0 => []
      ]
    }
    32. MyProject\Behat\Context\Ui\HomePageContext->iVisitTheHomePage() ==> Sylius\Behat\Page\Page->open(): {
      src: {
        /var/www/html/src/MyProject/Behat/Context/Ui/HomePageContext.php:34: """
          try {\n
              $this->homePage->open();\n
          } catch (UnexpectedPageException $e) {\n
          """
      }
      args: []
    }
    31. call_user_func_array() ==> MyProject\Behat\Context\Ui\HomePageContext->iVisitTheHomePage(): {
      args: []
    }
    30. Behat\Testwork\Call\Handler\RuntimeCallHandler->executeCall() ==> call_user_func_array(): {
      src: {
        /var/www/html/vendor/behat/behat/src/Behat/Testwork/Call/Handler/RuntimeCallHandler.php:104: """
          try {\n
              $return = call_user_func_array($callable, $arguments);\n
          } catch (Exception $caught) {\n
          """
      }
      args: array:2 [
        0 => array:2 [
          0 => MyProject\Behat\Context\Ui\HomePageContext {#4099
            -homePage: MyProject\Behat\Page\Shop\HomePage {#4100
              #router: Symfony\Cmf\Component\Routing\ChainRouter {#4145
                -context: Symfony\Component\Routing\RequestContext {#4140
                  -baseUrl: ""
                  -pathInfo: "/"
                  -method: "GET"
                  -host: "localhost"
                  -scheme: "http"
                  -httpPort: 80
                  -httpsPort: 443
                  -queryString: ""
                  -parameters: []
                }
                -routers: array:3 [
                  100 => array:1 [
                    0 => Symfony\Bundle\FrameworkBundle\Routing\Router {#4128
                      -container: appTestDebugProjectContainer {#5073 …12}
                      #matcher: null
                      #generator: appTestUrlGenerator {#4287
                        #routes: null
                        #context: Symfony\Component\Routing\RequestContext {#4140}
                        #strictRequirements: true
                        #logger: null
                        #decodedChars: array:10 [ …10]
                      }
                      #context: Symfony\Component\Routing\RequestContext {#4140}
                      #loader: null
                      #collection: null
                      #resource: "/var/www/html/app/config/routing.yml"
                      #options: array:12 [
                        "cache_dir" => "/var/www/html/app/cache/test"
                        "debug" => true

使用 Sylius CurrentChannelContext 中的以下步骤定义修复了它:

/**
 * @Given /^I am browsing (channel "([^"]*)")$/
 */
public function iAmBrowsingChannel(ChannelInterface $channel)
{
    $this->channelContextSetter->setChannel($channel);
}

 Background:
    Given the store operates on a single channel
    And the store operates on another channel named "ChannelA"
    And the store operates on another channel named "ChannelB"

  @ui
  Scenario: Navigating to some channel when clicking on the shop block
    Given I am browsing channel "Default"
    When I visit the homepage