GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#8)
by Alexei
06:32 queued 04:24
created

SoapContext::afterStepThrowExceptions()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 3
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * @author Alexei Gorobet, <[email protected]>
4
 */
5
namespace Behat\SoapExtension\Context;
6
7
use Behat\Behat\Hook\Scope\AfterStepScope;
8
use Symfony\Component\Yaml\Yaml;
9
use Behat\Gherkin\Node\TableNode;
10
use Behat\Gherkin\Node\PyStringNode;
11
use PHPUnit_Framework_Assert as Assertions;
12
13
/**
14
 * Class SoapContext.
15
 *
16
 * @package Behat\SoapExtension\Context
17
 *
18
 * @todo Rename methods.
19
 * @todo Document methods.
20
 * @todo Make steps more flexible with regex.
21
 */
22
class SoapContext extends RawSoapContext
23
{
24
    /**
25
     * @var mixed
26
     */
27
    private $value;
28
29
    /**
30
     * Sets the WSDL for the next SOAP request.
31
     *
32
     * @param string $wsdl
33
     *   Publicly accessible URL to wsdl
34
     *
35
     * @Given I am working with SOAP service WSDL :wsdl
36
     */
37
    public function iAmWorkingWithSoapServiceWSDL($wsdl)
38
    {
39
        $this->setWSDL($wsdl);
40
    }
41
42
    /**
43
     * Sets the WSDL for the next SOAP request to NULL.
44
     *
45
     * @Given I am working with SOAP service in non-WSDL mode
46
     */
47
    public function iAmWorkingWithSoapServiceNoWSDL()
48
    {
49
        $this->setWSDL(null);
50
    }
51
52
    /**
53
     * @Given I am working with SOAP service with options list:
54
     */
55
    public function iAmWorkingWithSoapServiceWithOptions(TableNode $options)
56
    {
57
        foreach ($options->getRowsHash() as $option => $value) {
58
            $this->setOption($option, $value);
59
        }
60
    }
61
62
    /**
63
     * @Given I am working with SOAP service with options as YAML:
64
     */
65
    public function iAmWorkingWithSoapServiceWithOptionsYaml(PyStringNode $options)
66
    {
67
        foreach (Yaml::parse($options->getRaw()) as $option => $value) {
0 ignored issues
show
Bug introduced by
The expression \Symfony\Component\Yaml\...rse($options->getRaw()) of type array|string|object<stdClass> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
68
            $this->setOption($option, $value);
69
        }
70
    }
71
72
    /**
73
     * Send SOAP request with params list.
74
     *
75
     * @Given I call SOAP function :function with params list:
76
     */
77
    public function iSendRequestWithParams($function, TableNode $params)
78
    {
79
        $this->sendRequest($function, [$params->getRowsHash()]);
80
    }
81
82
    /**
83
     * Send SOAP request with raw body.
84
     *
85
     * @Given I call SOAP with raw body:
86
     */
87
    public function iSendRequestBody(PyStringNode $body)
88
    {
89
        // Tell SOAP we want to send the body as XML, if not otherwise specified.
90
        $this->setOption('use', SOAP_LITERAL);
91
        $this->setOption('style', SOAP_DOCUMENT);
92
        $this->sendRequest('MethodNameIsIgnored', [new \SoapVar($body->getRaw(), XSD_ANYXML)]);
93
    }
94
95
    /**
96
     * Throw exceptions in case there were any we didn't expect and SoapContext
97
     * has an exception saved.
98
     *
99
     * @AfterStep */
100
    public function afterStepThrowExceptions(AfterStepScope $scope)
101
    {
102
        if (!preg_match('/^I call SOAP/', $scope->getStep()->getText())
103
          && $e = $this->getException()) {
104
            throw $e;
105
        }
106
    }
107
108
    /**
109
     * @Given I register the following XPATH namespaces:
110
     */
111
    public function iRegisterXpathNamespaces(TableNode $namespaces)
112
    {
113
        foreach ($namespaces->getRowsHash() as $prefix => $uri) {
114
            $this->setNamespace($prefix, $uri);
115
        }
116
    }
117
118
    /**
119
     * @Then /^I should get SOAP error matching "(.*)"$/
120
     */
121
    public function iShouldGetSoapErrorMatching($error_pattern)
122
    {
123
        $error = '';
124
        if ($exception = $this->getException()) {
125
            $error = $exception->getMessage();
126
        }
127
        Assertions::assertRegExp($error_pattern, $error);
128
        $this->setException(null);
129
    }
130
131
    /**
132
     * @Given I should see SOAP response property :property equals to :text
133
     */
134
    public function iShouldSeeSoapResponsePropertyEquals($text, $property)
135
    {
136
        Assertions::assertEquals($text, $this->extractResponseProperty($property));
137
    }
138
139
    /**
140
     * @Given I should see SOAP response property :property is not :text
141
     */
142
    public function iShouldSeeSoapResponsePropertyNotEquals($text, $property)
143
    {
144
        Assertions::assertNotEquals($text, $this->extractResponseProperty($property));
145
    }
146
147
    /**
148
     * @Given I should see SOAP response property :property contains :text
149
     */
150
    public function iShouldSeeSoapResponsePropertyContains($text, $property)
151
    {
152
        Assertions::assertContains($text, $this->extractResponseProperty($property));
153
    }
154
155
    /**
156
     * @Given I should see SOAP response property :property doesn't contain :text
157
     */
158
    public function iShouldSeeSoapResponsePropertyNotContains($text, $property)
159
    {
160
        Assertions::assertNotContains($text, $this->extractResponseProperty($property));
161
    }
162
163
    /**
164
     * @Then I should see SOAP response property :property matching pattern :pattern
165
     */
166
    public function iShouldSeeSoapResponsePropertyMatches($pattern, $property)
167
    {
168
        Assertions::assertRegExp($pattern, $this->extractResponseProperty($property));
169
    }
170
171
    /**
172
     * @Then I should see that SOAP Response matches XPATH :xpath
173
     */
174
    public function iShouldSeeThatSOAPResponseMatchesXpath($xpath)
175
    {
176
        Assertions::assertTrue(
177
            $this->extractResponseValueMatchingXPATH($xpath) !== false,
178
            "Couldn't find node matching provided XPATH: "
179
        );
180
    }
181
182
    /**
183
     * @Given I am working with SOAP response property :property
184
     */
185
    public function iWorkWithResponseProperty($property)
186
    {
187
        $this->value = $this->extractResponseProperty($property);
188
    }
189
190
    /**
191
     * @Given I am working with SOAP element matching XPATH :xpath
192
     */
193
    public function iWorkWithElementTextMatchingXPATH($xpath)
194
    {
195
        $this->value = $this->extractResponseValueMatchingXPATH($xpath);
196
    }
197
198
    /**
199
     * @Then saved SOAP value equals to :text
200
     */
201
    public function savedValueEquals($text)
202
    {
203
        Assertions::assertEquals($text, $this->value);
204
    }
205
206
    /**
207
     * @Then saved SOAP value is not equal to :text
208
     */
209
    public function savedValueNotEquals($text)
210
    {
211
        Assertions::assertNotEquals($text, $this->value);
212
    }
213
214
    /**
215
     * @Then saved SOAP value contains :text
216
     */
217
    public function savedValueContains($text)
218
    {
219
        Assertions::assertContains($text, $this->value);
220
    }
221
222
    /**
223
     * @Then saved SOAP value doesn't contain :text
224
     */
225
    public function savedValueNotContains($text)
226
    {
227
        Assertions::assertNotContains($text, $this->value);
228
    }
229
230
    /**
231
     * @Then saved SOAP value matches :pattern
232
     */
233
    public function savedValueMatchesRegExp($pattern)
234
    {
235
        Assertions::assertRegExp($pattern, $this->value);
236
    }
237
238
    /**
239
     * @Then saved SOAP value doesn't match :pattern
240
     */
241
    public function savedValueNotMatchesRegExp($pattern)
242
    {
243
        Assertions::assertNotRegExp($pattern, $this->value);
244
    }
245
}
246