在我的SoapCest.php
我发送肥皂请求:
$I->sendSoapRequest('authenticate', ['sUsername' => 'abc', 'sPassword' => 'xyz']);
这导致XML错误:
Procedure 'ns:authenticate' not present
这是正确的,应该使用soap:authenticate
而不是ns:authenticate
调用请求
如何在我的测试调用的代码中更改名称空间ns:
?
我希望我可以根据您的需求提出一些想法。
在我的情况下,我也必须改变NS。但Codeception SOAP module的构建只有1个wsdl。因此,您有两个选择:“分叉模块并根据您的需要进行调整”或“修改该模块的行为”。
我拿了第二个。
这就是我的SOAP测试的开始:
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>");
}
在tests / _support / ApiHelper中,我定义了以下函数:
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];
}
更新:17-feb-2016我在下面的评论中添加了Helper
需要在:tests / _support / Helper /文件夹中创建(您可以使用命令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.5版中,您可以这样做:
<?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();
}
}
更新:以前的代码对Codeception 2.1有效。使用Codeception 2.2这不再有效。请检查:https://github.com/Codeception/Codeception/issues/3168