Skip to content

Instantly share code, notes, and snippets.

@drgomesp
Created March 27, 2014 13:19
Show Gist options
  • Save drgomesp/9807406 to your computer and use it in GitHub Desktop.
Save drgomesp/9807406 to your computer and use it in GitHub Desktop.
Improving readability of a Behat scenario with @rdohms
Given I go to "/register"
And I fill in the following:
...
When I press "Register"
Then I should be on "/register/check-email"
And I should see "__user.registration.check_email.message"
After this, i have a few Listeners that create objects around the User object, for example a Settings entry, with default values.
What would your option for testing this happened in Behat be?
And I should have an auto-generated Settings Entry # specific phrase
And 'Setting' entity was created with 'user_id' equals 'current user id' # generic entity search
And Current User has non-null response to 'getSettings' # generic test of object method
And [other?]
@drgomesp
Copy link
Author

I would have something like this:

Given I am on "/register"
When I correctly complete my registration
Then I should be a valid registered user

Here you have more descriptive contexts that will abstract the actual cases.

<?php

/**
 * @Given /^I correctly complete my registration$/
 */
public function iCorrectlyCompleteMyRegistration()
{
    // here you test all the steps for a valid registration, such
    // as filling the form, clicking the button and so on
}

/**
 * @Given /^I correctly complete my registration$/
 */
public function iShouldBeAValidRegisteredUser()
{
    // here you test all the steps for a being a valid registered
    // user – and this is where the flow is tested, as you would
    // need to test if the e-mail was confirmed and everything
    // else inside the registration flow
}

This way you have more descriptive and clean scenario steps that can also be reused for many other features, and the actual testing is done under the sheets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment