How to Use Behat with Liip\FunctionalTestBundle in Symfony2? How to Use Behat with Liip\FunctionalTestBundle in Symfony2? symfony symfony

How to Use Behat with Liip\FunctionalTestBundle in Symfony2?


As this is a PHPUnit test case, you can't use it directly in Behat. You'll need to replicate the behaviour in a Behat context.

Have a look at the SymfonyDoctrineContext from Behat/CommonContexts. It should be a good place to start. The context is written for Behat 2 so you'll need to tweak it for Behat 3.

I'm using Liip\FunctionalTestBundle for Unit testing, it works very well.

If you're using the FunctionalTestBundle, then you're not writing unit tests. Unit tests are isolated. Functional tests are type of an integration test (not isolated). If you haven't noticed yet, this kind of testing is brittle and slow. I recommend you to learn how to focus more of your efforts on true unit testing.


solution for the problem

// ApiContext.php<?php  declare(strict_types=1);  use Behat\Behat\Context\Context;  class ApiContext extends \Liip\FunctionalTestBundle\Test\WebTestCase implements Context  {    public function __construct($kernelDir)    {      parent::__construct();      $_SERVER['KERNEL_DIR'] = $kernelDir;    }  /**   * @BeforeScenario   *   */  public function loadFixturesData(): void  {    $fixturesLocation = '@AppBundle/DataFixtures/ORM/hautelook_alice/';    $this->loadFixtureFiles([        $fixturesLocation . 'fixture1.yml',        $fixturesLocation . 'fixture2.yml',    ]);}

}

// behat.yml....  suites:    default:      contexts:        - ApiContext:            kernelDir: "app/"....