BDD in PHP, Testing search in Wikipedia with Behat and Mink (Selenium2 Driver) I am trying to learn BDD in PHP with Behat and Mink and I am using Selenium2 driver for the same.

The scenario is given on this page and is as follows: 




Feature: Search
    In order to see a word definition
    As a website user
    I need to be able to search for a word

    Scenario: Searching for a page that does exist
        Given I am on "/wiki/Main_Page"
        When I fill in "search" with "Behavior Driven Development"
        And I press "searchButton"
        Then I should see "Behavior-driven development"

    Scenario: Searching for a page that does NOT exist
        Given I am on "/wiki/Main_Page"
        When I fill in "search" with "Glory Driven Development"
        And I press "searchButton"
        Then I should see "Search results"



The file behat.yml is as follows:



default:
    extensions:
        Behat\MinkExtension:
            base_url: http://en.wikipedia.org/
            goutte: ~
            selenium2: ~


I have written the below code for FeatureContext.php that I am sure needs improvements. Can anyone suggest me the points for the same?

&lt;?php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context, SnippetAcceptingContext
{
    /**
    * Initializes context.
    *
    * Every scenario gets its own context instance.
    * You can also pass arbitrary arguments to the
    * context constructor through behat.yml.
    */
    public function __construct()
    {

        $this-&gt;driver = new \Behat\Mink\Driver\Selenium2Driver('firefox');
        $this-&gt;session = new \Behat\Mink\Session($this-&gt;driver);        
        $this-&gt;session-&gt;start();
    }


    /**
    * @Given I am on :url
    */
    public function iAmOn($url)
    {
        $this-&gt;session-&gt;visit('http://en.wikipedia.org'.$url);
    }

    /**
    * @When I fill in :field with :text
    */
    public function iFillInWith($field, $text)
    {
        $this
            -&gt;session
            -&gt;getPage()
            -&gt;find('css', '[type=' . $field . ']')
            -&gt;setValue($text);
    }

    /**
    * @When I press :button
    */
    public function iPress($button)
    {
        $this
            -&gt;session
            -&gt;getPage()
            -&gt;find('css', '[id=' . $button . ']')
            -&gt;press();
    }

    /**
    * @Then I should see :text
    */
    public function iShouldSee($text)
    {
        $title = $this
            -&gt;session
            -&gt;getPage()
            -&gt;find('css', 'h1')
            -&gt;getText();

        if ($title !== $text) {
            new Exception('Invalid page');
        }
    }

    /**
    * @AfterScenario
    */
    public function tearDown()
    {
        $this-&gt;session-&gt;stop();
    }
}
There is one major point that we can do here. In the FeatureContext.php, if class FeatureContext extends MinkContext, then you do not need to write any of the function definitions at all!

Applying what I just said, will result to have FeatureContext.php to be as:

&lt;?php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext; //This line is add

class FeatureContext extends MinkContext // This line is changed
    implements Context, SnippetAcceptingContext
{
    public function __construct()
    {
    }
}


Note: To make the point more clear, I have removed the comments that are generated by behat.