Skip to content

Commit

Permalink
Merge pull request #23 from alexislefebvre/21-add-behat-browser-tests
Browse files Browse the repository at this point in the history
Add behat test of Controller with MinkExtension
  • Loading branch information
alexislefebvre authored Oct 14, 2016
2 parents efc5d8c + 60bcdaa commit 063e66a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\bootstrap;
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\Context;

use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Tweet;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Context\Context;

class FeatureContext implements SnippetAcceptingContext
class FeatureContext implements Context
{
/** @var $now \Datetime */
private $now;
Expand Down
76 changes: 76 additions & 0 deletions Tests/Features/Context/FeatureContextMink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\Context;

use Behat\MinkExtension\Context\RawMinkContext;

/**
* Class FeatureContextMink.
*
* @see https://github.com/jakzal/DemoBundle/blob/432e818097d9496223039eb28d79158daa216c6b/Features/Context/FeatureContext.php
*/
class FeatureContextMink extends RawMinkContext
{
/**
* Initializes context.
*/
public function __construct()
{
}

/**
* @When I visit the index page
*/
public function iVisitTheIndexPage()
{
$this->getSession()->visit($this->locatePath('/'));
}

/**
* @Then I should see a body tag
*/
public function iShouldSeeABodyTag()
{
$this->assertSession()->elementsCount(
'css',
'html > body',
1
);
}

/**
* @Then I should see the title of the page
*/
public function iShouldSeeTheTitleOfThePage()
{
$this->assertSession()->elementTextContains(
'css',
'html > head > title',
'Home timeline'
);
}

/**
* @Then I should see the Tweets container
*/
public function iShouldSeeTheTweetsContainer()
{
$this->assertSession()->elementsCount(
'css',
'main.container > div.tweets',
1
);
}

/**
* @Then I should see the pending tweets
*/
public function iShouldSeeThePendingTweets()
{
$this->assertSession()->elementTextContains(
'css',
'body > main.container > div.navigation.row > div.col-sm-7.col-xs-12.count.alert.alert-info',
'pending tweets'
);
}
}
7 changes: 7 additions & 0 deletions Tests/Features/Controller/Controller.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Test DefaultController

Scenario: Index
When I visit the index page
Then I should see a body tag
And I should see the title of the page
And I should see the pending tweets
8 changes: 7 additions & 1 deletion behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ default:
default:
paths:
features: Tests/Features
contexts: [AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\bootstrap\FeatureContext]
contexts:
- 'AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\Context\FeatureContext'
- 'AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\Context\FeatureContextMink'
extensions:
Behat\Symfony2Extension:
# http://zalas.eu/run-behat-scenarios-and-functional-tests-from-symfony-bundle-in-isolation-of-project/
Expand All @@ -12,3 +14,7 @@ default:
debug: true
path: Tests/App/AppKernel.php
bootstrap: Tests/App/bootstrap.php
Behat\MinkExtension:
sessions:
default:
symfony2: ~
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"liip/functional-test-bundle": "~1.4",
"phpunit/phpunit": "4.8.* || ~5.1",
"behat/behat": "^3.2",
"behat/symfony2-extension": "^2.1"
"behat/symfony2-extension": "^2.1",
"behat/mink": "^1.7",
"behat/mink-extension": "^2.2",
"behat/mink-browserkit-driver": "^1.3"
},
"autoload" : {
"psr-4" : {
Expand Down

0 comments on commit 063e66a

Please sign in to comment.