2

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?

3 Answers 3

3

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();
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

thanks for your post! Could you explain where do you get your \Helper\SoapModule $soapModule from and which content is there? Right now i get the following error: [InjectionException] Failed to inject dependencies in instance of 'tests\api\SoapCest'. Class tests\api\Codeception\Module\SOAP does not exist - or similiar if i change the classname.
Oh! right, you need to create the SoapModule helper at: tests/_support/Helper See the post again, I have updated it.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.