File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Codeception \Step ;
4+
5+ use Codeception \Lib \ModuleContainer ;
6+ use Codeception \Util \Template ;
7+
8+ class AsJson extends Action implements GeneratedStep
9+ {
10+ public function run (ModuleContainer $ container = null )
11+ {
12+ $ container ->getModule ('REST ' )->haveHttpHeader ('Content-Type ' , 'application/json ' );
13+ $ resp = parent ::run ($ container );
14+ return json_decode ($ resp , true );
15+ }
16+
17+ public static function getTemplate (Template $ template )
18+ {
19+ $ action = $ template ->getVar ('action ' );
20+
21+ // should only be applied to send* methods
22+ if (strpos ($ action , 'send ' ) !== 0 ) return ;
23+
24+ $ conditionalDoc = "* JSON response will be automatically decoded \n " . $ template ->getVar ('doc ' );
25+
26+ return $ template
27+ ->place ('doc ' , $ conditionalDoc )
28+ ->place ('action ' , $ action . 'AsJson ' )
29+ ->place ('step ' , 'AsJson ' );
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments