Skip to content

Commit 2b80d83

Browse files
authored
Update codebase to PHP 7.4 (#12)
1 parent 40f2c5e commit 2b80d83

File tree

5 files changed

+57
-57
lines changed

5 files changed

+57
-57
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [7.1, 7.2, 7.3, 7.4, 8.0]
11+
php: [7.4, 8.0]
1212

1313
steps:
1414
- name: Checkout code

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
],
1313
"minimum-stability": "RC",
1414
"require": {
15-
"php": "^7.1 || ^8.0",
15+
"php": "^7.4 | ^8.0",
1616
"ext-dom": "*",
17-
"codeception/codeception": "^4.0",
17+
"codeception/codeception": "^4.1",
1818
"codeception/lib-innerbrowser": "^1.0"
1919
},
2020
"require-dev": {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A SOAP module for Codeception.
99

1010
## Requirements
1111

12-
* `PHP 7.1` or higher.
12+
* `PHP 7.4` or higher.
1313

1414
## Installation
1515

src/Codeception/Module/SOAP.php

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Codeception\Util\XmlBuilder;
1616
use Codeception\Util\XmlStructure;
1717
use DOMDocument;
18+
use DOMNode;
1819
use ErrorException;
1920
use PHPUnit\Framework\Assert;
2021
use Symfony\Component\BrowserKit\AbstractBrowser;
@@ -66,10 +67,7 @@ class SOAP extends Module implements DependsOnModule
6667
*/
6768
protected $requiredFields = ['endpoint'];
6869

69-
/**
70-
* @var string
71-
*/
72-
protected $dependencyMessage = <<<EOF
70+
protected string $dependencyMessage = <<<EOF
7371
Example using PhpBrowser as backend for SOAP module.
7472
--
7573
modules:
@@ -80,34 +78,23 @@ class SOAP extends Module implements DependsOnModule
8078
Framework modules can be used as well for functional testing of SOAP API.
8179
EOF;
8280

83-
/**
84-
* @var AbstractBrowser
85-
*/
86-
public $client;
81+
public AbstractBrowser $client;
8782

88-
/**
89-
* @var bool
90-
*/
91-
public $isFunctional = false;
83+
public bool $isFunctional = false;
9284

9385
/**
94-
* @var DOMDocument
95-
*/
96-
public $xmlRequest;
97-
/**
98-
* @var DOMDocument
86+
* @var DOMNode|DOMDocument|null
9987
*/
100-
public $xmlResponse;
88+
public $xmlRequest = null;
10189

10290
/**
103-
* @var XmlStructure
91+
* @var DOMNode|DOMDocument|null
10492
*/
105-
protected $xmlStructure;
93+
public $xmlResponse = null;
10694

107-
/**
108-
* @var InnerBrowser
109-
*/
110-
protected $connectionModule;
95+
protected ?XmlStructure $xmlStructure = null;
96+
97+
protected ?InnerBrowser $connectionModule = null;
11198

11299
public function _before(TestInterface $test): void
113100
{
@@ -142,6 +129,7 @@ private function getClient(): AbstractBrowser
142129
if (!$this->client) {
143130
throw new ModuleRequireException($this, 'Connection client is not available.');
144131
}
132+
145133
return $this->client;
146134
}
147135

@@ -150,6 +138,7 @@ private function getXmlResponse(): DOMDocument
150138
if (!$this->xmlResponse) {
151139
throw new ModuleException($this, "No XML response, use `\$I->sendSoapRequest` to receive it");
152140
}
141+
153142
return $this->xmlResponse;
154143
}
155144

@@ -158,6 +147,7 @@ private function getXmlStructure(): XmlStructure
158147
if (!$this->xmlStructure) {
159148
$this->xmlStructure = new XmlStructure($this->getXmlResponse());
160149
}
150+
161151
return $this->xmlStructure;
162152
}
163153

@@ -440,8 +430,9 @@ public function grabAttributeFrom(string $cssOrXPath, string $attribute): string
440430
$el = $this->getXmlStructure()->matchElement($cssOrXPath);
441431
$elHasAttribute = $el->hasAttribute($attribute);
442432
if (!$elHasAttribute) {
443-
$this->fail(sprintf('Attribute not found in element matched by \'%s\'', $cssOrXPath));
433+
$this->fail(sprintf("Attribute not found in element matched by '%s'", $cssOrXPath));
444434
}
435+
445436
return $el->getAttribute($attribute);
446437
}
447438

@@ -467,12 +458,13 @@ protected function buildRequest(): DOMDocument
467458
$xml->appendChild($root);
468459
$root->setAttribute('xmlns:ns', $this->getSchema());
469460
$root->setAttribute('xmlns:soapenv', $soap_schema_url);
470-
461+
471462
$body = $xml->createElementNS($soap_schema_url, 'soapenv:Body');
472463
$header = $xml->createElementNS($soap_schema_url, 'soapenv:Header');
473464
$root->appendChild($header);
474-
465+
475466
$root->appendChild($body);
467+
476468
$this->xmlRequest = $xml;
477469
return $xml;
478470
}
@@ -494,21 +486,22 @@ protected function processRequest(string $action, string $body): void
494486
}
495487

496488
/**
497-
* @return string|bool
489+
* @return string|false
498490
*/
499491
protected function processInternalRequest(string $action, string $body)
500492
{
501493
ob_start();
502494
try {
503495
$this->getClient()->setServerParameter('HTTP_HOST', 'localhost');
504496
$this->processRequest($action, $body);
505-
} catch (ErrorException $e) {
497+
} catch (ErrorException $exception) {
506498
// Zend_Soap outputs warning as an exception
507-
if (strpos($e->getMessage(), 'Warning: Cannot modify header information') === false) {
499+
if (strpos($exception->getMessage(), 'Warning: Cannot modify header information') === false) {
508500
ob_end_clean();
509-
throw $e;
501+
throw $exception;
510502
}
511503
}
504+
512505
$response = ob_get_contents();
513506
ob_end_clean();
514507
return $response;

tests/unit/Codeception/Module/SoapTest.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,55 @@
22

33
declare(strict_types=1);
44

5+
use Codeception\Configuration;
6+
use Codeception\Lib\Connector\Universal;
7+
use Codeception\Lib\ModuleContainer;
8+
use Codeception\Module\SOAP;
9+
use Codeception\Module\UniversalFramework;
10+
use Codeception\PHPUnit\TestCase;
511
use Codeception\Util\Stub;
612
use Codeception\Util\Soap as SoapUtil;
713

814
/**
915
* Class SoapTest
1016
* @group appveyor
1117
*/
12-
final class SoapTest extends \Codeception\PHPUnit\TestCase
18+
final class SoapTest extends TestCase
1319
{
20+
protected ?SOAP $module = null;
1421

15-
/**
16-
* @var \Codeception\Module\Soap
17-
*/
18-
protected $module = null;
19-
20-
protected $layout;
22+
protected ?string $layout = null;
2123

2224
public function _setUp()
2325
{
24-
$container = \Codeception\Util\Stub::make('Codeception\Lib\ModuleContainer');
25-
$frameworkModule = new \Codeception\Module\UniversalFramework($container);
26-
$frameworkModule->client = Stub::makeEmpty('\Codeception\Lib\Connector\Universal');
27-
$this->module = new \Codeception\Module\SOAP($container);
26+
$container = Stub::make(ModuleContainer::class);
27+
$frameworkModule = new UniversalFramework($container);
28+
$frameworkModule->client = Stub::makeEmpty(Universal::class);
29+
$this->module = new SOAP($container);
2830
$this->module->_setConfig(array(
2931
'schema' => 'http://www.w3.org/2001/xml.xsd',
3032
'endpoint' => 'http://codeception.com/api/wsdl'
3133
));
3234
$this->module->_inject($frameworkModule);
33-
$this->layout = \Codeception\Configuration::dataDir().'/layout.xml';
35+
36+
$this->layout = Configuration::dataDir().'/layout.xml';
3437
$this->module->isFunctional = true;
35-
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
38+
$this->module->_before(Stub::makeEmpty(\Codeception\Test\Test::class));
3639
}
37-
40+
3841
public function testXmlIsBuilt()
3942
{
40-
$dom = new \DOMDocument();
43+
$dom = new DOMDocument();
4144
$dom->load($this->layout);
4245
$this->assertXmlStringEqualsXmlString($dom->saveXML(), $this->module->xmlRequest->saveXML());
4346
}
44-
47+
4548
public function testBuildHeaders()
4649
{
4750
$this->module->haveSoapHeader('AuthHeader', ['username' => 'davert', 'password' => '123456']);
48-
$dom = new \DOMDocument();
51+
$dom = new DOMDocument();
4952
$dom->load($this->layout);
53+
5054
$header = $dom->createElement('AuthHeader');
5155
$header->appendChild($dom->createElement('username', 'davert'));
5256
$header->appendChild($dom->createElement('password', '123456'));
@@ -58,11 +62,13 @@ public function testBuildRequest()
5862
{
5963
$this->module->sendSoapRequest('KillHumans', "<item><id>1</id><subitem>2</subitem></item>");
6064
$this->assertNotNull($this->module->xmlRequest);
61-
$dom = new \DOMDocument();
65+
$dom = new DOMDocument();
6266
$dom->load($this->layout);
67+
6368
$body = $dom->createElement('item');
6469
$body->appendChild($dom->createElement('id', '1'));
6570
$body->appendChild($dom->createElement('subitem', '2'));
71+
6672
$request = $dom->createElement('ns:KillHumans');
6773
$request->appendChild($body);
6874
$dom->documentElement->getElementsByTagName('Body')->item(0)->appendChild($request);
@@ -71,19 +77,21 @@ public function testBuildRequest()
7177

7278
public function testBuildRequestWithDomNode()
7379
{
74-
$dom = new \DOMDocument();
80+
$dom = new DOMDocument();
7581
$dom->load($this->layout);
82+
7683
$body = $dom->createElement('item');
7784
$body->appendChild($dom->createElement('id', '1'));
7885
$body->appendChild($dom->createElement('subitem', '2'));
86+
7987
$request = $dom->createElement('ns:KillHumans');
8088
$request->appendChild($body);
8189
$dom->documentElement->getElementsByTagName('Body')->item(0)->appendChild($request);
8290

8391
$this->module->sendSoapRequest('KillHumans', $body);
8492
$this->assertXmlStringEqualsXmlString($dom->saveXML(), $this->module->xmlRequest->saveXML());
8593
}
86-
94+
8795
public function testSeeXmlIncludes()
8896
{
8997
$dom = new DOMDocument();
@@ -111,7 +119,6 @@ public function testSeeXmlNotContainsXPath()
111119
$this->module->dontSeeSoapResponseContainsXPath('//doc/a[@a2=2 and @a31]');
112120
}
113121

114-
115122
public function testSeeXmlEquals()
116123
{
117124
$dom = new DOMDocument();
@@ -133,7 +140,7 @@ public function testSeeXmlIncludesWithBuilder()
133140
->val('123');
134141
$this->module->seeSoapResponseIncludes($xml);
135142
}
136-
143+
137144
public function testGrabTextFrom()
138145
{
139146
$dom = new DOMDocument();

0 commit comments

Comments
 (0)