1

嗨,

有一段时间知道我的测试场景有问题。我在我的 Symfony 项目中使用 behat/mink ~2.0 和 Nelmio/Alice ^2.x。在我的一些项目中,我使用可翻译的学说扩展来管理我的业务实体上的 i18n。

当爱丽丝坚持我的固定装置时,他似乎忽略了我的 default_locale 参数,并将始终使用 en 作为语言环境值来创建它们。

为了测试我的语言环境切换器,我需要一种方法来为测试环境中的项目选择我的语言环境或/并保持具有不同语言环境的固定装置。

我的灯具如下所示

AcmmeBundle\CoreBundle\Entity\Universe:

universe1:
    title: <word()>
    templates: [@template1]
    collections: [@collection1, @collection2]
    categories: [@category1, @category2]

像这样加载我的测试

@alice(User)
@alice(Category)
@alice(Collection)
@alice(Universe)

@alice(Page)
@alice(HomePage)

@reset-schema
@javascript

Feature: I test api GET /api/someEntity

还有我的 behat.yml.dist

default:
autoload:
     '': features/bootstrap
suites:
     default:
         contexts:
             - Victoire\Tests\Features\Context\FeatureContext
             - Victoire\Tests\Features\Context\JavascriptContext
             - Victoire\Tests\Features\Context\VictoireContext
             - Knp\FriendlyContexts\Context\MinkContext
             - Knp\FriendlyContexts\Context\AliceContext
             - Knp\FriendlyContexts\Context\EntityContext
             - Knp\FriendlyContexts\Context\TableContext
             - FeatureContext
             - PageContext
             - ApiContext
formatters:
     html:
         output_path: %paths.base%/web/build/html/behat
     pretty:
         output_path:
extensions:
    emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension:
        name: html
        renderer: Twig,Behat2
        file_name: Index
        print_args: true
        print_outp: true
        loop_break: true
    jarnaiz\JUnitFormatter\JUnitFormatterExtension:
        filename: report.xml
        outputDir: %paths.base%/test-reports/
    Behat\Symfony2Extension:
        kernel:
            path: app/AppKernel.php
            debug: true
    Behat\MinkExtension\ServiceContainer\MinkExtension:
        base_url: 'http://127.0.0.1/app_test.php'
        selenium2:
           wd_host: 127.0.0.1:4444/wd/hub
           capabilities: { "browser": "firefox"}
        goutte: ~
        symfony2: ~
        default_session:    symfony2
        browser_name: firefox
    Knp\FriendlyContexts\Extension:
        entities:
            namespaces:
                - Acme
                - Victoire
        smartTag: smartStep
        alice:
            locale: fr_FR
            fixtures:
                Media:          features/fixtures/media.yml
                Template:       features/fixtures/template.yml
                User:           features/fixtures/user.yml
                Survey:         features/fixtures/survey.yml
                Tag:            features/fixtures/tag.yml
                Collection:     features/fixtures/collection.yml
                Category:       features/fixtures/category.yml
                Universe:       features/fixtures/universe.yml
                Page:           features/fixtures/Victoire/page.yml
                HomePage:       features/fixtures/Victoire/Pages/home.yml
            dependencies:
                Template:   [Media]
                User:       [Template]
                Survey:     [Tag]
                HomePage:   [Page]
4

2 回答 2

0

根据http://docs.behat.org/en/v2.5/guides/7.config.html使用

export BEHAT_PARAMS="formatter[name]=progress&context[parameters][base_url]=http://localhost"

并覆盖路由中的“_locale”参数

于 2016-12-01T21:35:32.923 回答
0

其实答案很简单。只需将夹具用于翻译类

 universeTranslation1:
    title: <word()>
    locale: fr
    translatable: @universe1

universeTranslation2:
    title: <word()>
    locale: en
    translatable: @universe1

universeTranslation3:
    title: <word()>
    locale: fr
    translatable: @universe2

universeTranslation4:
    title: <word()>
    locale: en
    translatable: @universe2
于 2016-12-02T10:18:38.757 回答