Search code examples
symfonylocalestofdoctrineextensionsnelmio-alice

How to choose locale for STOF translatable with NelmioAliceBundle Fixture in Symfony


Hy,

For some time know I have an issue with my test scenario. I use behat/mink ~2.0 and Nelmio/Alice ^2.x in my Symfony project. On some of my project I use the doctrine extension translatable to manage i18n on my buisness entity.

When alice persist my fixture he seems to ignore my default_locale parameter and will always create them with en as locale value.

In order to test my locale switcher I need a way to choose my locale for the project in test environnement or/and persist fixture with different locale.

My fixture are wright as follow

AcmmeBundle\CoreBundle\Entity\Universe:

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

Load in my test like this

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

@alice(Page)
@alice(HomePage)

@reset-schema
@javascript

Feature: I test api GET /api/someEntity

And my 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]

Solution

  • Well actually the answer was realy simple. Just by using fixture for Translation class

     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