3
3
namespace Jeckel \Gherkin ;
4
4
5
5
use Behat \Gherkin \Node \TableNode ;
6
+ use Codeception \Configuration ;
6
7
use Codeception \Lib \Interfaces \DependsOnModule ;
8
+ use Codeception \Lib \ModuleContainer ;
7
9
use Codeception \Module \REST ;
8
10
use Codeception \Util \Fixtures ;
9
11
use Exception ;
12
+ use Jeckel \Gherkin \FilePath \FileHelper ;
13
+ use Jeckel \Gherkin \FilePath \FileHelperAwareInterface ;
14
+ use Jeckel \Gherkin \FilePath \FileHelperAwareTrait ;
10
15
11
16
/**
12
17
* Class RestHelper
13
18
* @package Jeckel\Gherkin
14
19
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
15
20
*/
16
- class RestContext extends ContextAbstract implements DependsOnModule
21
+ class RestContext extends ContextAbstract implements DependsOnModule, FileHelperAwareInterface
17
22
{
23
+ use FileHelperAwareTrait;
24
+
18
25
/**
19
26
* Allows to explicitly set what methods have this class.
20
27
*
@@ -28,7 +35,6 @@ class RestContext extends ContextAbstract implements DependsOnModule
28
35
protected $ rest ;
29
36
30
37
// phpcs:disable
31
-
32
38
/**
33
39
* @return array
34
40
*/
@@ -148,12 +154,43 @@ public function iShouldSeeResponseJsonMatchesJsonPath(string $path)
148
154
}
149
155
150
156
/**
151
- * @Then the JSON should be equal to :json
152
- * @param string $json
157
+ * @Then I should see response contains json :arg1
158
+ * @param string $arg1
159
+ */
160
+ public function iShouldSeeResponseContainsJson (string $ arg1 )
161
+ {
162
+ $ this ->checkResponseContainsJson ($ arg1 );
163
+ }
164
+
165
+ /**
166
+ * @Then I should see response contains json from file :filepath
167
+ * @param string $filepath
168
+ */
169
+ public function iShouldSeeResponseContainsJSONFromFile (string $ filepath )
170
+ {
171
+ $ fileContent = file_get_contents (
172
+ $ this ->getFileHelper ()->getAbsolutePathTo ($ filepath , FileHelper::PATH_TO_DATA )
173
+ );
174
+ if (! $ fileContent ) {
175
+ throw new \InvalidArgumentException (sprintf ('Enable to open file %s ' , $ filepath ));
176
+ }
177
+ $ this ->checkResponseContainsJson ($ fileContent );
178
+ }
179
+
180
+ /**
181
+ * @param string $jsonString
153
182
*/
154
- public function theJSONShouldBeEqualTo (string $ json )
183
+ protected function checkResponseContainsJson (string $ jsonString )
155
184
{
156
- $ this ->rest ->seeResponseEquals ($ json );
185
+ var_dump ($ jsonString );
186
+ $ json = json_decode ($ jsonString , true );
187
+
188
+ if (null === $ json && json_last_error () != JSON_ERROR_NONE ) {
189
+ throw new \InvalidArgumentException (
190
+ sprintf ('Argument provided is not valid JSON: %s ' , json_last_error_msg ())
191
+ );
192
+ }
193
+ $ this ->rest ->seeResponseContainsJson ($ json );
157
194
}
158
195
159
196
/**
0 commit comments