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 (#11)
by Sergii
02:22
created

SoapContext::expectException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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