exxecc exxecc - 2 years ago 248
PHP Question

Codeception SOAP Namespace

In my

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
instead of

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

Answer Source

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);


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

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)

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)
                'endpoint' => $endpoint,
                'schema' => $schema,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download