16/01/2015 - BEHAT
I'm not going to go into to much details by writing what does what but you can study the code below. Also make sure you visit the links below for more info.
default:
formatter:
name: pretty
parameters:
output_styles:
comment: [ magenta ]
context:
class: Application\BackendBundle\Features\Context\FeatureContext
parameters:
base_url: 'http://football.local/app_test.php/backend/'
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://football.local/app_test.php/backend/'
javascript_session: symfony2
goutte: ~
selenium2: ~
paths:
bootstrap: %behat.paths.features%/Context
features: %behat.paths.base%/src/Application/BackendBundle/Features
Feature: Test feature
Scenario: I can handle dynamic response content
Given I am on "/"
Then the response status code should be 200
And I should see "Welcome to Application backend!"
Then I send a "GET" request to "user"
And the response status code should be 200
And the response type should be "application/json"
And the response should contain "Hello"
You should print_r(get_class_methods($client));
and print_r(get_class_methods($this->getSession()));
to see what's available for you to use.
namespace Application\BackendBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
use Exception;
class FeatureContext extends MinkContext
{
private $baseUrl;
private $response;
public function __construct(array $parameters)
{
$this->baseUrl = $parameters['base_url'];
}
/**
* @When /^I send a "([^"]*)" request to "([^"]*)"$/
*
* @param $method
* @param $uri
*/
public function iSendARequestTo($method, $uri)
{
$client = $this->getSession()->getDriver()->getClient();
$this->response = $client->request($method, $this->baseUrl.$uri);
}
/**
* @Then /^the response type should be "([^"]*)"$/
*
* @param $type
* @throws Exception
*/
public function theResponseTypeShouldBeJson($type)
{
$headers = $this->getSession()->getResponseHeaders();
if ($headers['Content-Type'][0] != $type) {
throw new Exception('Invalid response type');
}
}
}
For more examples, you can check links below.