You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For more information see the the :doc:`installation section of this documentation </guide/installation>`.
25
25
@@ -28,20 +28,20 @@ Setup the Behat configuration
28
28
29
29
You need to enable the extension in the Behat configuration and configure your Behat Suite to use the Magento 2 Service Container. Your ``behat.yml`` should look like this:
In order to verify that the extension is configured correctly you will need a test feature. For example create a ``features/my_feature.feature`` file like this:
57
57
58
-
.. code-block:: gherkin
58
+
.. code-block:: gherkin
59
59
60
-
Feature: Magento and Behat DI connected
61
-
As a developer
62
-
In order to write Behat tests easily
63
-
I should be able to inject services from the Magento DI into Behat Contexts
60
+
Feature: Magento and Behat DI connected
61
+
As a developer
62
+
In order to write Behat tests easily
63
+
I should be able to inject services from the Magento DI into Behat Contexts
64
64
65
-
Scenario: Injecting service from Magento DI to Behat Context as argument for Behat Context constructor
66
-
Given A service has been successfully injected through the Context constructor
67
-
When I work with Behat
68
-
Then I am happy
65
+
Scenario: Injecting service from Magento DI to Behat Context as argument for Behat Context constructor
66
+
Given A service has been successfully injected through the Context constructor
67
+
When I work with Behat
68
+
Then I am happy
69
69
70
70
Also to implement the above feature you need to add the following step definitions to your ``features/bootstrap/FeatureContext.php`` Behat Context:
71
71
72
-
.. code-block:: php
72
+
.. code-block:: php
73
73
74
-
<?php
74
+
<?php
75
75
76
-
use Behat\Behat\Context\Context;
77
-
use Exception;
78
-
use Magento\Sales\Api\OrderRepositoryInterface;
76
+
use Behat\Behat\Context\Context;
77
+
use Exception;
78
+
use Magento\Sales\Api\OrderRepositoryInterface;
79
79
80
-
class FeatureContext implements Context
81
-
{
82
-
/** @var OrderRepositoryInterface */
83
-
private $orderRepository;
80
+
class FeatureContext implements Context
81
+
{
82
+
/** @var OrderRepositoryInterface */
83
+
private $orderRepository;
84
84
85
-
public function __construct(OrderRepositoryInterface $orderRepository)
86
-
{
87
-
$this->orderRepository = $orderRepository;
88
-
}
85
+
public function __construct(OrderRepositoryInterface $orderRepository)
86
+
{
87
+
$this->orderRepository = $orderRepository;
88
+
}
89
89
90
-
/**
91
-
* @Given A service has been successfully injected through the Context constructor
92
-
*/
93
-
public function aServiceHasBeenSuccessfullyInjectedThroughTheContextConstructor()
94
-
{
95
-
if (!$this->orderRepository instanceof OrderRepositoryInterface) {
96
-
throw new Exception('Something went wrong :(');
97
-
}
90
+
/**
91
+
* @Given A service has been successfully injected through the Context constructor
92
+
*/
93
+
public function aServiceHasBeenSuccessfullyInjectedThroughTheContextConstructor()
94
+
{
95
+
if (!$this->orderRepository instanceof OrderRepositoryInterface) {
96
+
throw new Exception('Something went wrong :(');
98
97
}
98
+
}
99
99
100
-
/**
101
-
* @When I work with Behat
102
-
*/
103
-
public function iWorkWithBehat()
104
-
{
105
-
// no-op
106
-
}
100
+
/**
101
+
* @When I work with Behat
102
+
*/
103
+
public function iWorkWithBehat()
104
+
{
105
+
// no-op
106
+
}
107
107
108
-
/**
109
-
* @Then I am happy
110
-
*/
111
-
public function iAmHappy()
112
-
{
113
-
// no-op :)
114
-
}
108
+
/**
109
+
* @Then I am happy
110
+
*/
111
+
public function iAmHappy()
112
+
{
113
+
// no-op :)
115
114
}
115
+
}
116
116
117
117
Note that here we inject the Order Repository Magento service through the Context constructor, but it is also possible to inject it through the Behat Step definition as well. For more information see the :doc:`usage section of this documentation </guide/usage>`.
0 commit comments