0

I am trying to find a way to run cleanup (DB) before running on each test. How could I do if I am using behat with mink? My current FeatureContext.php looks like this:

class FeatureContext extends MinkContext
{
    /**
     * Initializes context.
     * Every scenario gets its own context object.
     *
     * @param array $parameters context parameters (set them up through behat.yml)
     */
    public function __construct(array $parameters)
    {
        // Initialize your context here
    }
}
phuang07
  • 981
  • 1
  • 9
  • 18

1 Answers1

5

Use the hooks in your context, read docs for Behat 3 or Behat 2. Example from Behat 3:

// features/bootstrap/FeatureContext.php

use Behat\Behat\Context\Context;
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
use Behat\Behat\Hook\Scope\AfterScenarioScope;

class FeatureContext implements Context
{
    /**
     * @BeforeSuite
     */
     public static function prepare(BeforeSuiteScope $scope)
     {
         // prepare system for test suite
         // before it runs
     }

     /**
      * @AfterScenario @database
      */
     public function cleanDB(AfterScenarioScope $scope)
     {
         // clean database after scenarios,
         // tagged with @database
     }
}
Ian Bytchek
  • 8,804
  • 6
  • 46
  • 72