diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bfbad11..2015c21 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - php: [7.1, 7.2, 7.3, 7.4, 8.0] + php: [7.4, 8.0] steps: - name: Checkout code diff --git a/composer.json b/composer.json index 296fb54..257c179 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,9 @@ ], "minimum-stability": "RC", "require": { - "php": "^7.1 || ^8.0", + "php": "^7.4 | ^8.0", "ext-dom": "*", - "codeception/codeception": "^4.0", + "codeception/codeception": "^4.1", "codeception/lib-innerbrowser": "^1.0" }, "require-dev": { diff --git a/readme.md b/readme.md index 5092548..e0c7546 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,7 @@ A SOAP module for Codeception. ## Requirements -* `PHP 7.1` or higher. +* `PHP 7.4` or higher. ## Installation diff --git a/src/Codeception/Module/SOAP.php b/src/Codeception/Module/SOAP.php index 30cc952..df73e86 100644 --- a/src/Codeception/Module/SOAP.php +++ b/src/Codeception/Module/SOAP.php @@ -15,6 +15,7 @@ use Codeception\Util\XmlBuilder; use Codeception\Util\XmlStructure; use DOMDocument; +use DOMNode; use ErrorException; use PHPUnit\Framework\Assert; use Symfony\Component\BrowserKit\AbstractBrowser; @@ -66,10 +67,7 @@ class SOAP extends Module implements DependsOnModule */ protected $requiredFields = ['endpoint']; - /** - * @var string - */ - protected $dependencyMessage = <<client) { throw new ModuleRequireException($this, 'Connection client is not available.'); } + return $this->client; } @@ -150,6 +138,7 @@ private function getXmlResponse(): DOMDocument if (!$this->xmlResponse) { throw new ModuleException($this, "No XML response, use `\$I->sendSoapRequest` to receive it"); } + return $this->xmlResponse; } @@ -158,6 +147,7 @@ private function getXmlStructure(): XmlStructure if (!$this->xmlStructure) { $this->xmlStructure = new XmlStructure($this->getXmlResponse()); } + return $this->xmlStructure; } @@ -440,8 +430,9 @@ public function grabAttributeFrom(string $cssOrXPath, string $attribute): string $el = $this->getXmlStructure()->matchElement($cssOrXPath); $elHasAttribute = $el->hasAttribute($attribute); if (!$elHasAttribute) { - $this->fail(sprintf('Attribute not found in element matched by \'%s\'', $cssOrXPath)); + $this->fail(sprintf("Attribute not found in element matched by '%s'", $cssOrXPath)); } + return $el->getAttribute($attribute); } @@ -467,12 +458,13 @@ protected function buildRequest(): DOMDocument $xml->appendChild($root); $root->setAttribute('xmlns:ns', $this->getSchema()); $root->setAttribute('xmlns:soapenv', $soap_schema_url); - + $body = $xml->createElementNS($soap_schema_url, 'soapenv:Body'); $header = $xml->createElementNS($soap_schema_url, 'soapenv:Header'); $root->appendChild($header); - + $root->appendChild($body); + $this->xmlRequest = $xml; return $xml; } @@ -494,7 +486,7 @@ protected function processRequest(string $action, string $body): void } /** - * @return string|bool + * @return string|false */ protected function processInternalRequest(string $action, string $body) { @@ -502,13 +494,14 @@ protected function processInternalRequest(string $action, string $body) try { $this->getClient()->setServerParameter('HTTP_HOST', 'localhost'); $this->processRequest($action, $body); - } catch (ErrorException $e) { + } catch (ErrorException $exception) { // Zend_Soap outputs warning as an exception - if (strpos($e->getMessage(), 'Warning: Cannot modify header information') === false) { + if (strpos($exception->getMessage(), 'Warning: Cannot modify header information') === false) { ob_end_clean(); - throw $e; + throw $exception; } } + $response = ob_get_contents(); ob_end_clean(); return $response; diff --git a/tests/unit/Codeception/Module/SoapTest.php b/tests/unit/Codeception/Module/SoapTest.php index 5d2aeeb..57102ba 100644 --- a/tests/unit/Codeception/Module/SoapTest.php +++ b/tests/unit/Codeception/Module/SoapTest.php @@ -2,6 +2,12 @@ declare(strict_types=1); +use Codeception\Configuration; +use Codeception\Lib\Connector\Universal; +use Codeception\Lib\ModuleContainer; +use Codeception\Module\SOAP; +use Codeception\Module\UniversalFramework; +use Codeception\PHPUnit\TestCase; use Codeception\Util\Stub; use Codeception\Util\Soap as SoapUtil; @@ -9,44 +15,42 @@ * Class SoapTest * @group appveyor */ -final class SoapTest extends \Codeception\PHPUnit\TestCase +final class SoapTest extends TestCase { + protected ?SOAP $module = null; - /** - * @var \Codeception\Module\Soap - */ - protected $module = null; - - protected $layout; + protected ?string $layout = null; public function _setUp() { - $container = \Codeception\Util\Stub::make('Codeception\Lib\ModuleContainer'); - $frameworkModule = new \Codeception\Module\UniversalFramework($container); - $frameworkModule->client = Stub::makeEmpty('\Codeception\Lib\Connector\Universal'); - $this->module = new \Codeception\Module\SOAP($container); + $container = Stub::make(ModuleContainer::class); + $frameworkModule = new UniversalFramework($container); + $frameworkModule->client = Stub::makeEmpty(Universal::class); + $this->module = new SOAP($container); $this->module->_setConfig(array( 'schema' => 'http://www.w3.org/2001/xml.xsd', 'endpoint' => 'http://codeception.com/api/wsdl' )); $this->module->_inject($frameworkModule); - $this->layout = \Codeception\Configuration::dataDir().'/layout.xml'; + + $this->layout = Configuration::dataDir().'/layout.xml'; $this->module->isFunctional = true; - $this->module->_before(Stub::makeEmpty('\Codeception\Test\Test')); + $this->module->_before(Stub::makeEmpty(\Codeception\Test\Test::class)); } - + public function testXmlIsBuilt() { - $dom = new \DOMDocument(); + $dom = new DOMDocument(); $dom->load($this->layout); $this->assertXmlStringEqualsXmlString($dom->saveXML(), $this->module->xmlRequest->saveXML()); } - + public function testBuildHeaders() { $this->module->haveSoapHeader('AuthHeader', ['username' => 'davert', 'password' => '123456']); - $dom = new \DOMDocument(); + $dom = new DOMDocument(); $dom->load($this->layout); + $header = $dom->createElement('AuthHeader'); $header->appendChild($dom->createElement('username', 'davert')); $header->appendChild($dom->createElement('password', '123456')); @@ -58,11 +62,13 @@ public function testBuildRequest() { $this->module->sendSoapRequest('KillHumans', "12"); $this->assertNotNull($this->module->xmlRequest); - $dom = new \DOMDocument(); + $dom = new DOMDocument(); $dom->load($this->layout); + $body = $dom->createElement('item'); $body->appendChild($dom->createElement('id', '1')); $body->appendChild($dom->createElement('subitem', '2')); + $request = $dom->createElement('ns:KillHumans'); $request->appendChild($body); $dom->documentElement->getElementsByTagName('Body')->item(0)->appendChild($request); @@ -71,11 +77,13 @@ public function testBuildRequest() public function testBuildRequestWithDomNode() { - $dom = new \DOMDocument(); + $dom = new DOMDocument(); $dom->load($this->layout); + $body = $dom->createElement('item'); $body->appendChild($dom->createElement('id', '1')); $body->appendChild($dom->createElement('subitem', '2')); + $request = $dom->createElement('ns:KillHumans'); $request->appendChild($body); $dom->documentElement->getElementsByTagName('Body')->item(0)->appendChild($request); @@ -83,7 +91,7 @@ public function testBuildRequestWithDomNode() $this->module->sendSoapRequest('KillHumans', $body); $this->assertXmlStringEqualsXmlString($dom->saveXML(), $this->module->xmlRequest->saveXML()); } - + public function testSeeXmlIncludes() { $dom = new DOMDocument(); @@ -111,7 +119,6 @@ public function testSeeXmlNotContainsXPath() $this->module->dontSeeSoapResponseContainsXPath('//doc/a[@a2=2 and @a31]'); } - public function testSeeXmlEquals() { $dom = new DOMDocument(); @@ -133,7 +140,7 @@ public function testSeeXmlIncludesWithBuilder() ->val('123'); $this->module->seeSoapResponseIncludes($xml); } - + public function testGrabTextFrom() { $dom = new DOMDocument();