eXe
eXe

Reputation: 660

Codeception SOAP Namespace

In my SoapCest.php i send a Soap Request:

$I->sendSoapRequest('authenticate', ['sUsername' => 'abc', 'sPassword' => 'xyz']);

Which results in a XML Fault:

Procedure 'ns:authenticate' not present

This is correct, couse the request should be called with soap:authenticate instead of ns:authenticate

How can i change the namespace ns: in codeception for my test calls?

Upvotes: 2

Views: 1453

Answers (3)

edmitry
edmitry

Reputation: 31

In version 2.5 you can do so:

<?php
namespace Helper;

class SoapAPI extends \Codeception\Module
{
    public function configure(): void
    {
       $this->getModule('SOAP')->_reconfigure(['schema' => 'YourNamespace']);
    }
}
<?php

class SoapTestCest
{

  public function _before(SoapAPITester $I, \Helper\SoapAPI $soapModule): void 
  {
      $soapModule->configure();
  }
}

Upvotes: 3

javigomez
javigomez

Reputation: 186

Update: previous code was valid for Codeception 2.1. Using Codeception 2.2 this is not valid anymore. Please check: https://github.com/Codeception/Codeception/issues/3168

Upvotes: 1

javigomez
javigomez

Reputation: 186

I hope I can give some ideas for your needs.

In my case I had to change the NS too. But the Codeception SOAP module is build to just have 1 wsdl. So you have two options: "fork the Module and adapt it to your needs" or "modify the behaviour of that module".

I took the second.

This is how my SOAP test starts:

Class SiteRedshopbCategory100SoapCest
{
public function _before(ApiTester $I, \Helper\SoapModule $soapModule, \Codeception\TestCase\Cest $testCase)
{
    $endpoint = 'http://mywebsite.com/index.php?webserviceClient=site&webserviceVersion=1.0.0&view=category&api=soap';
    $schema = $I->getSoapWsdlDinamically($endpoint);

    $soapModule->configure(
            $testCase,
            $endpoint,
            $schema
    );
}

public function create(ApiTester $I)
{
    $I->wantTo('POST a new category using SOAP');
    $I->amHttpAuthenticated('admin', 'admin');
    $I->sendSoapRequest('create', "<name>Category1</name>");
    $I->seeSoapResponseContainsStructure("<result></result>");
    $I->dontSeeSoapResponseIncludes("<result>false</result>");
}

In tests/_support/ApiHelper I have defined the following function:

class ApiHelper extends \Codeception\Module
{
    /**
     * Cached WSDL files
     */
    static private $schemas = [];

    /**
     * Returns the location of the Wsdl file generated dinamically
     *
     * @param   string  $endpoint  The webservice url.
     *
     * @return mixed
     */
    public function getSoapWsdlDinamically($endpoint)
    {
        // Gets cached WSDL static file from dynamic file
        if (!isset(self::$schemas[$endpoint]))
        {
            $wsdl = simplexml_load_file($endpoint . '&wsdl');
            $schema = $wsdl['targetNamespace'];
            self::$schemas[$endpoint] = $schema;
        }

        return self::$schemas[$endpoint];
    }

UPDATE: 17-feb-2016 I'm adding the Helper requested in the following comment

Needs to be created at: tests/_support/Helper/ folder (you can generate it with the command vendor/bin/codecept generate:helper SoapModule)

<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class SoapModule extends \Codeception\Module
{
    public function configure($testcase, $endpoint, $schema)
    {
        $this->getModule('SOAP')->_reconfigure(
            array(
                'endpoint' => $endpoint,
                'schema' => $schema,
            )
        );
        //$this->getModule('SOAP')->buildRequest();
        $this->getModule('SOAP')->_before($testcase);
    }
}

Upvotes: 1

Related Questions