Skip to content
This repository was archived by the owner on Dec 14, 2024. It is now read-only.

Commit 063e66a

Browse files
Merge pull request #23 from alexislefebvre/21-add-behat-browser-tests
Add behat test of Controller with MinkExtension
2 parents efc5d8c + 60bcdaa commit 063e66a

File tree

5 files changed

+97
-5
lines changed

5 files changed

+97
-5
lines changed

Tests/Features/bootstrap/FeatureContext.php renamed to Tests/Features/Context/FeatureContext.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\bootstrap;
3+
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\Context;
44

55
use AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Tweet;
6-
use Behat\Behat\Context\SnippetAcceptingContext;
6+
use Behat\Behat\Context\Context;
77

8-
class FeatureContext implements SnippetAcceptingContext
8+
class FeatureContext implements Context
99
{
1010
/** @var $now \Datetime */
1111
private $now;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\Context;
4+
5+
use Behat\MinkExtension\Context\RawMinkContext;
6+
7+
/**
8+
* Class FeatureContextMink.
9+
*
10+
* @see https://github.com/jakzal/DemoBundle/blob/432e818097d9496223039eb28d79158daa216c6b/Features/Context/FeatureContext.php
11+
*/
12+
class FeatureContextMink extends RawMinkContext
13+
{
14+
/**
15+
* Initializes context.
16+
*/
17+
public function __construct()
18+
{
19+
}
20+
21+
/**
22+
* @When I visit the index page
23+
*/
24+
public function iVisitTheIndexPage()
25+
{
26+
$this->getSession()->visit($this->locatePath('/'));
27+
}
28+
29+
/**
30+
* @Then I should see a body tag
31+
*/
32+
public function iShouldSeeABodyTag()
33+
{
34+
$this->assertSession()->elementsCount(
35+
'css',
36+
'html > body',
37+
1
38+
);
39+
}
40+
41+
/**
42+
* @Then I should see the title of the page
43+
*/
44+
public function iShouldSeeTheTitleOfThePage()
45+
{
46+
$this->assertSession()->elementTextContains(
47+
'css',
48+
'html > head > title',
49+
'Home timeline'
50+
);
51+
}
52+
53+
/**
54+
* @Then I should see the Tweets container
55+
*/
56+
public function iShouldSeeTheTweetsContainer()
57+
{
58+
$this->assertSession()->elementsCount(
59+
'css',
60+
'main.container > div.tweets',
61+
1
62+
);
63+
}
64+
65+
/**
66+
* @Then I should see the pending tweets
67+
*/
68+
public function iShouldSeeThePendingTweets()
69+
{
70+
$this->assertSession()->elementTextContains(
71+
'css',
72+
'body > main.container > div.navigation.row > div.col-sm-7.col-xs-12.count.alert.alert-info',
73+
'pending tweets'
74+
);
75+
}
76+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature: Test DefaultController
2+
3+
Scenario: Index
4+
When I visit the index page
5+
Then I should see a body tag
6+
And I should see the title of the page
7+
And I should see the pending tweets

behat.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ default:
33
default:
44
paths:
55
features: Tests/Features
6-
contexts: [AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\bootstrap\FeatureContext]
6+
contexts:
7+
- 'AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\Context\FeatureContext'
8+
- 'AlexisLefebvre\Bundle\AsyncTweetsBundle\Tests\Features\Context\FeatureContextMink'
79
extensions:
810
Behat\Symfony2Extension:
911
# http://zalas.eu/run-behat-scenarios-and-functional-tests-from-symfony-bundle-in-isolation-of-project/
@@ -12,3 +14,7 @@ default:
1214
debug: true
1315
path: Tests/App/AppKernel.php
1416
bootstrap: Tests/App/bootstrap.php
17+
Behat\MinkExtension:
18+
sessions:
19+
default:
20+
symfony2: ~

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
"liip/functional-test-bundle": "~1.4",
2525
"phpunit/phpunit": "4.8.* || ~5.1",
2626
"behat/behat": "^3.2",
27-
"behat/symfony2-extension": "^2.1"
27+
"behat/symfony2-extension": "^2.1",
28+
"behat/mink": "^1.7",
29+
"behat/mink-extension": "^2.2",
30+
"behat/mink-browserkit-driver": "^1.3"
2831
},
2932
"autoload" : {
3033
"psr-4" : {

0 commit comments

Comments
 (0)