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
02:11
created

SoapContext::iShouldGetSoapErrorMatching()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 6
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
        $error = '';
123
        if ($exception = $this->getException()) {
124
            $error = $exception->getMessage();
125
        }
126
        Assertions::assertRegExp($error_pattern, $error);
127
        $this->setException(null);
128
    }
129
130
    /**
131
     * @Given I should see SOAP response property :property equals to :text
132
     */
133
    public function iShouldSeeSoapResponsePropertyEquals($text, $property)
134
    {
135
        Assertions::assertEquals($text, $this->extractResponseProperty($property));
136
    }
137
138
    /**
139
     * @Given I should see SOAP response property :property is not :text
140
     */
141
    public function iShouldSeeSoapResponsePropertyNotEquals($text, $property)
142
    {
143
        Assertions::assertNotEquals($text, $this->extractResponseProperty($property));
144
    }
145
146
    /**
147
     * @Given I should see SOAP response property :property contains :text
148
     */
149
    public function iShouldSeeSoapResponsePropertyContains($text, $property)
150
    {
151
        Assertions::assertContains($text, $this->extractResponseProperty($property));
152
    }
153
154
    /**
155
     * @Given I should see SOAP response property :property doesn't contain :text
156
     */
157
    public function iShouldSeeSoapResponsePropertyNotContains($text, $property)
158
    {
159
        Assertions::assertNotContains($text, $this->extractResponseProperty($property));
160
    }
161
162
    /**
163
     * @Then I should see SOAP response property :property matching pattern :pattern
164
     */
165
    public function iShouldSeeSoapResponsePropertyMatches($pattern, $property)
166
    {
167
        Assertions::assertRegExp($pattern, $this->extractResponseProperty($property));
168
    }
169
170
    /**
171
     * @Then I should see that SOAP Response matches XPATH :xpath
172
     */
173
    public function iShouldSeeThatSOAPResponseMatchesXpath($xpath)
174
    {
175
        Assertions::assertTrue(
176
            $this->extractResponseValueMatchingXPATH($xpath) !== false,
177
            "Couldn't find node matching provided XPATH: "
178
        );
179
    }
180
181
    /**
182
     * @Given I am working with SOAP response property :property
183
     */
184
    public function iWorkWithResponseProperty($property)
185
    {
186
        $this->value = $this->extractResponseProperty($property);
187
    }
188
189
    /**
190
     * @Given I am working with SOAP element matching XPATH :xpath
191
     */
192
    public function iWorkWithElementTextMatchingXPATH($xpath)
193
    {
194
        $this->value = $this->extractResponseValueMatchingXPATH($xpath);
195
    }
196
197
    /**
198
     * @Then saved SOAP value equals to :text
199
     */
200
    public function savedValueEquals($text)
201
    {
202
        Assertions::assertEquals($text, $this->value);
203
    }
204
205
    /**
206
     * @Then saved SOAP value is not equal to :text
207
     */
208
    public function savedValueNotEquals($text)
209
    {
210
        Assertions::assertNotEquals($text, $this->value);
211
    }
212
213
    /**
214
     * @Then saved SOAP value contains :text
215
     */
216
    public function savedValueContains($text)
217
    {
218
        Assertions::assertContains($text, $this->value);
219
    }
220
221
    /**
222
     * @Then saved SOAP value doesn't contain :text
223
     */
224
    public function savedValueNotContains($text)
225
    {
226
        Assertions::assertNotContains($text, $this->value);
227
    }
228
229
    /**
230
     * @Then saved SOAP value matches :pattern
231
     */
232
    public function savedValueMatchesRegExp($pattern)
233
    {
234
        Assertions::assertRegExp($pattern, $this->value);
235
    }
236
237
    /**
238
     * @Then saved SOAP value doesn't match :pattern
239
     */
240
    public function savedValueNotMatchesRegExp($pattern)
241
    {
242
        Assertions::assertNotRegExp($pattern, $this->value);
243
    }
244
}
245