@@ -22,6 +22,16 @@ Feature: BrowserKit integration
22
22
When I visit the page "/hello-world"
23
23
Then I should see "Hello world!" on the page
24
24
"""
25
+
26
+ Scenario : Injecting KernelBrowser manually
27
+ Given a YAML services file containing:
28
+ """
29
+ services:
30
+ App\Tests\SomeContext:
31
+ public: true
32
+ arguments:
33
+ - '@test.client'
34
+ """
25
35
And a context file "tests/SomeContext.php" containing:
26
36
"""
27
37
<?php
@@ -31,14 +41,13 @@ Feature: BrowserKit integration
31
41
use Behat\Behat\Context\Context;
32
42
use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters;
33
43
use Psr\Container\ContainerInterface;
34
- use Symfony\Component\BrowserKit\AbstractBrowser;
35
- use Symfony\Component\BrowserKit\Client;
44
+ use Symfony\Bundle\FrameworkBundle\KernelBrowser;
36
45
37
46
final class SomeContext implements Context {
38
- /** @var Client|AbstractBrowser */
47
+ /** @var KernelBrowser */
39
48
private $client;
40
49
41
- public function __construct($client)
50
+ public function __construct(KernelBrowser $client)
42
51
{
43
52
$this->client = $client;
44
53
}
@@ -56,31 +65,97 @@ Feature: BrowserKit integration
56
65
}
57
66
}
58
67
"""
68
+ When I run Behat
69
+ Then it should pass
59
70
60
- Scenario : Injecting BrowserKit client
71
+ Scenario : Autowiring and autoconfiguring KernelBrowser client
61
72
Given a YAML services file containing:
62
73
"""
63
74
services:
64
- App\Tests\SomeContext:
65
- public: true
66
- arguments:
67
- - '@test.client'
75
+ _defaults:
76
+ autowire: true
77
+ autoconfigure: true
78
+
79
+ App\Tests\SomeContext: ~
68
80
"""
81
+ And a context file "tests/SomeContext.php" containing:
82
+ """
83
+ <?php
84
+
85
+ namespace App\Tests;
86
+
87
+ use Behat\Behat\Context\Context;
88
+ use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters;
89
+ use Psr\Container\ContainerInterface;
90
+ use Symfony\Bundle\FrameworkBundle\KernelBrowser;
91
+
92
+ final class SomeContext implements Context {
93
+ /** @var KernelBrowser */
94
+ private $client;
95
+
96
+ public function __construct(KernelBrowser $client)
97
+ {
98
+ $this->client = $client;
99
+ }
100
+
101
+ /** @When I visit the page :page */
102
+ public function visitPage(string $page): void
103
+ {
104
+ $this->client->request('GET', $page);
105
+ }
106
+
107
+ /** @Then I should see :content on the page */
108
+ public function shouldSeeContentOnPage(string $content): void
109
+ {
110
+ assert(false !== strpos($this->client->getResponse()->getContent(), $content));
111
+ }
112
+ }
113
+ """
69
114
When I run Behat
70
115
Then it should pass
71
116
72
- Scenario : Autowiring and autoconfiguring BrowserKit client
117
+ Scenario : Autowiring and autoconfiguring HttpKernelBrowser client
73
118
Given a YAML services file containing:
74
119
"""
75
120
services:
76
121
_defaults:
77
122
autowire: true
78
123
autoconfigure: true
79
124
80
- bind:
81
- $client: "@test.client"
82
-
83
125
App\Tests\SomeContext: ~
84
126
"""
127
+ And a context file "tests/SomeContext.php" containing:
128
+ """
129
+ <?php
130
+
131
+ namespace App\Tests;
132
+
133
+ use Behat\Behat\Context\Context;
134
+ use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters;
135
+ use Psr\Container\ContainerInterface;
136
+ use Symfony\Component\HttpKernel\HttpKernelBrowser;
137
+
138
+ final class SomeContext implements Context {
139
+ /** @var HttpKernelBrowser */
140
+ private $client;
141
+
142
+ public function __construct(HttpKernelBrowser $client)
143
+ {
144
+ $this->client = $client;
145
+ }
146
+
147
+ /** @When I visit the page :page */
148
+ public function visitPage(string $page): void
149
+ {
150
+ $this->client->request('GET', $page);
151
+ }
152
+
153
+ /** @Then I should see :content on the page */
154
+ public function shouldSeeContentOnPage(string $content): void
155
+ {
156
+ assert(false !== strpos($this->client->getResponse()->getContent(), $content));
157
+ }
158
+ }
159
+ """
85
160
When I run Behat
86
161
Then it should pass
0 commit comments