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 (#16)
by
unknown
05:35
created

SoapContext::savedValueNotEquals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * @author Alexei Gorobet, <[email protected]>
4
 */
5
namespace Behat\SoapExtension\Context;
6
7
use Symfony\Component\Yaml\Yaml;
8
use PHPUnit_Framework_Assert as Assertions;
9
// Argument processors.
10
use Behat\Gherkin\Node\TableNode;
11
use Behat\Gherkin\Node\PyStringNode;
12
// Utils.
13
use Behat\SoapExtension\Utils\SoapFaultProcessor;
14
// Scopes.
15
use Behat\Behat\Hook\Scope\BeforeStepScope;
16
17
/**
18
 * Class SoapContext.
19
 *
20
 * @package Behat\SoapExtension\Context
21
 *
22
 * @todo Rename methods.
23
 * @todo Document methods.
24
 * @todo Make steps more flexible with regex.
25
 */
26
class SoapContext extends RawSoapContext
27
{
28
    /**
29
     * @var mixed
30
     */
31
    private $value;
32
    private $fault;
33
34
    /**
35
     * Sets the WSDL for the next SOAP request.
36
     *
37
     * @param string $wsdl
38
     *   Publicly accessible URL to wsdl
39
     *
40
     * @Given I am working with SOAP service WSDL :wsdl
41
     */
42
    public function iAmWorkingWithSoapServiceWSDL($wsdl)
43
    {
44
        $this->setWSDL($wsdl);
45
    }
46
47
    /**
48
     * Sets the WSDL for the next SOAP request to NULL.
49
     *
50
     * @Given I am working with SOAP service in non-WSDL mode
51
     */
52
    public function iAmWorkingWithSoapServiceNoWSDL()
53
    {
54
        $this->setWSDL(null);
55
    }
56
57
    /**
58
     * @Given I am working with SOAP service with options list:
59
     */
60
    public function iAmWorkingWithSoapServiceWithOptions(TableNode $options)
61
    {
62
        foreach ($options->getRowsHash() as $option => $value) {
63
            $this->setOption($option, $value);
64
        }
65
    }
66
67
    /**
68
     * @Given I am working with SOAP service with options as YAML:
69
     */
70
    public function iAmWorkingWithSoapServiceWithOptionsYaml(PyStringNode $options)
71
    {
72
        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...
73
            $this->setOption($option, $value);
74
        }
75
    }
76
77
    /**
78
     * Send SOAP request with params list.
79
     *
80
     * @Given I call SOAP function :function with params list:
81
     */
82
    public function iSendRequestWithParams($function, TableNode $params)
83
    {
84
        $this->sendRequest($function, [$params->getRowsHash()]);
85
    }
86
    
87
    /**
88
     * Send SOAP request with params as nested array.
89
     *
90
     * @Given I call SOAP function :function with params as json:
91
     */
92
    public function iSendRequestWithNestedParamsArray($function, PyStringNode $json)
93
    {
94
        $this->sendRequest($function, [json_decode('{' . $json . '}', 'true')]);
95
    }
96
97
    /**
98
     * Send SOAP request with raw body.
99
     *
100
     * @Given I call SOAP with raw body:
101
     */
102
    public function iSendRequestBody(PyStringNode $body)
103
    {
104
        // Tell SOAP we want to send the body as XML, if not otherwise specified.
105
        $this->setOption('use', SOAP_LITERAL);
106
        $this->setOption('style', SOAP_DOCUMENT);
107
        $this->sendRequest('MethodNameIsIgnored', [new \SoapVar($body->getRaw(), XSD_ANYXML)]);
108
    }
109
110
    /**
111
     * Send SOAP request with function arguments array as YAML.
112
     *
113
     * @Given I call SOAP function :function with arguments array as YAML:
114
     */
115
    public function iSendRequestYAML($function, PyStringNode $arguments)
116
    {
117
        $arguments = Yaml::parse($arguments->getRaw());
118
        $this->sendRequest($function, $arguments);
119
    }
120
121
    /**
122
     * @Given I register the following XPATH namespaces:
123
     */
124
    public function iRegisterXpathNamespaces(TableNode $namespaces)
125
    {
126
        foreach ($namespaces->getRowsHash() as $prefix => $uri) {
127
            $this->setNamespace($prefix, $uri);
128
        }
129
    }
130
131
    /**
132
     * @Then /^(?:|I )expect SOAP exception(?:| with code "(\d+)")(?:|( and| or)? with message "([^"]+?)")$/
133
     */
134
    public function expectException($code = null, $condition = null, $message = null)
135
    {
136
        // Exit with an error because we're expected an exception and got nothing.
137
        if (null === $this->fault) {
138
            throw new \RuntimeException('Expected \SoapFault exception was not thrown!');
139
        }
140
141
        new SoapFaultProcessor($this->fault, $code, $message, $condition);
142
143
        // If processor didn't throw an exception, then we shouldn't too.
144
        $this->fault = null;
145
    }
146
147
    /**
148
     * @Given I should see SOAP response property :property equals to :text
149
     */
150
    public function iShouldSeeSoapResponsePropertyEquals($text, $property)
151
    {
152
        Assertions::assertEquals($text, $this->extractResponseProperty($property));
153
    }
154
155
    /**
156
     * @Given I should see SOAP response property :property is not :text
157
     */
158
    public function iShouldSeeSoapResponsePropertyNotEquals($text, $property)
159
    {
160
        Assertions::assertNotEquals($text, $this->extractResponseProperty($property));
161
    }
162
163
    /**
164
     * @Given I should see SOAP response property :property contains :text
165
     */
166
    public function iShouldSeeSoapResponsePropertyContains($text, $property)
167
    {
168
        Assertions::assertContains($text, $this->extractResponseProperty($property));
169
    }
170
171
    /**
172
     * @Given I should see SOAP response property :property doesn't contain :text
173
     */
174
    public function iShouldSeeSoapResponsePropertyNotContains($text, $property)
175
    {
176
        Assertions::assertNotContains($text, $this->extractResponseProperty($property));
177
    }
178
179
    /**
180
     * @Then I should see SOAP response property :property matching pattern :pattern
181
     */
182
    public function iShouldSeeSoapResponsePropertyMatches($pattern, $property)
183
    {
184
        Assertions::assertRegExp($pattern, $this->extractResponseProperty($property));
185
    }
186
187
    /**
188
     * @Then I should see that SOAP Response matches XPATH :xpath
189
     */
190
    public function iShouldSeeThatSOAPResponseMatchesXpath($xpath)
191
    {
192
        Assertions::assertTrue(
193
            $this->extractResponseValueMatchingXPATH($xpath) !== false,
194
            "Couldn't find node matching provided XPATH: "
195
        );
196
    }
197
198
    /**
199
     * @Given I am working with SOAP response property :property
200
     */
201
    public function iWorkWithResponseProperty($property)
202
    {
203
        $this->value = $this->extractResponseProperty($property);
204
    }
205
206
    /**
207
     * @Given I am working with SOAP element matching XPATH :xpath
208
     */
209
    public function iWorkWithElementTextMatchingXPATH($xpath)
210
    {
211
        $this->value = $this->extractResponseValueMatchingXPATH($xpath);
212
    }
213
214
    /**
215
     * @Then saved SOAP value equals to :text
216
     */
217
    public function savedValueEquals($text)
218
    {
219
        Assertions::assertEquals($text, $this->value);
220
    }
221
222
    /**
223
     * @Then saved SOAP value is not equal to :text
224
     */
225
    public function savedValueNotEquals($text)
226
    {
227
        Assertions::assertNotEquals($text, $this->value);
228
    }
229
230
    /**
231
     * @Then saved SOAP value contains :text
232
     */
233
    public function savedValueContains($text)
234
    {
235
        Assertions::assertContains($text, $this->value);
236
    }
237
238
    /**
239
     * @Then saved SOAP value doesn't contain :text
240
     */
241
    public function savedValueNotContains($text)
242
    {
243
        Assertions::assertNotContains($text, $this->value);
244
    }
245
246
    /**
247
     * @Then saved SOAP value matches :pattern
248
     */
249
    public function savedValueMatchesRegExp($pattern)
250
    {
251
        Assertions::assertRegExp($pattern, $this->value);
252
    }
253
254
    /**
255
     * @Then saved SOAP value doesn't match :pattern
256
     */
257
    public function savedValueNotMatchesRegExp($pattern)
258
    {
259
        Assertions::assertNotRegExp($pattern, $this->value);
260
    }
261
262
    /**
263
     * @BeforeStep
264
     */
265
    public function beforeStepCheckForException(BeforeStepScope $scope)
266
    {
267
        // Check for SOAP exception from previously executed step.
268
        $this->fault = $this->getException();
269
270
        // @todo Is it really a better way to do this?
271
        if (null !== $this->fault && strpos($scope->getStep()->getText(), 'SOAP exception') === false) {
272
            throw $this->fault;
273
        }
274
    }
275
}
276