Skip to content
Snippets Groups Projects
Commit d5110a47 authored by Andy Summers's avatar Andy Summers
Browse files

Define contract for creating SOAP clients with WSDLs

parent 4bc3d120
No related branches found
No related tags found
1 merge request!64Define contract for creating SOAP clients with WSDLs
Showing with 131 additions and 25 deletions
......@@ -7,13 +7,21 @@ namespace edu\wisc\services\cbs\api;
interface SoapService extends Service
{
/** Paths to QA CBS WSDLs */
const QA_HEADER = __DIR__ . '/../../../../../resources/doit_soa_order_iface_h_v2.xml';
const QA_LINE = __DIR__ . '/../../../../../resources/doit_soa_order_iface_l_v2.xml';
const QA_PAYMENT = __DIR__ . '/../../../../../resources/doit_soa_payment_v2.xml';
const QA_INTERFACING = __DIR__ . '/../../../../../resources/doit_soa_order_iface_i_v2.xml';
const QA_PRICE = __DIR__ . '/../../../../resources/doit_soa_pricing_v2.xml';
/**
* A SOAP service is constructed with a username and password. If a {@link \SoapClient} is provided, the username
* and password are ignored.
*
* @param string $username username
* @param string $password password
* @param string|null $wsdlPath path to WSDL for specifying CBS environment. Defaults to QA
* @param \SoapClient|null $soapClient Overriding SOAP client (for testing purposes)
*/
public function __construct($username, $password, \SoapClient $soapClient = null);
public function __construct($username, $password, $wsdlPath = null, \SoapClient $soapClient = null);
}
......@@ -20,11 +20,17 @@ class SoapOrderHeaderService implements OrderHeaderService, SoapService
/**
* {@inheritdoc}
*/
public function __construct($username, $password, \SoapClient $headerSoapClient = null)
public function __construct($username, $password, $wsdlPath = null, \SoapClient $headerSoapClient = null)
{
if ($headerSoapClient !== null) {
$this->soapClient = $headerSoapClient;
return;
} else if ($wsdlPath !== null) {
$this->soapClient = new DOIT_SOA_ORDER_IFACE_H_V2_Service(
[],
$wsdlPath
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
} else {
$this->soapClient = new DOIT_SOA_ORDER_IFACE_H_V2_Service(
[],
......
......@@ -16,17 +16,24 @@ class SoapOrderInterfacingService implements OrderInterfacingService, SoapServic
/** @var DOIT_SOA_ORDER_IFACE_I_V2_Service */
private $soapClient;
public function __construct($username, $password, \SoapClient $priceSoapClient = null)
public function __construct($username, $password, $wsdlPath = null, \SoapClient $priceSoapClient = null)
{
if ($priceSoapClient !== null) {
$this->soapClient = $priceSoapClient;
return;
} else if ($wsdlPath !== null) {
$this->soapClient = new DOIT_SOA_ORDER_IFACE_I_V2_Service(
[],
$wsdlPath
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
} else {
$this->soapClient = new DOIT_SOA_ORDER_IFACE_I_V2_Service(
[],
__DIR__ . '/../../../../../../resources/doit_soa_order_iface_i_v2.xml'
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
}
$this->soapClient = new DOIT_SOA_ORDER_IFACE_I_V2_Service(
[],
__DIR__ . '/../../../../../../resources/doit_soa_order_iface_i_v2.xml'
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
}
public function interfaceOrder($orderNumber)
......
......@@ -16,11 +16,17 @@ class SoapOrderLineService implements SoapService, OrderLineService
/**
* {@inheritdoc}
*/
public function __construct($username, $password, \SoapClient $lineSoapClient = null)
public function __construct($username, $password, $wsdlPath = null, \SoapClient $lineSoapClient = null)
{
if ($lineSoapClient !== null) {
$this->soapClient = $lineSoapClient;
return;
} else if ($wsdlPath !== null) {
$this->soapClient = new DOIT_SOA_ORDER_IFACE_L_V2_Service(
[],
$wsdlPath
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
} else {
$this->soapClient = new DOIT_SOA_ORDER_IFACE_L_V2_Service(
[],
......
......@@ -21,17 +21,24 @@ class SoapOrderPaymentService implements OrderPaymentService, SoapService
/**
* {@inheritdoc}
*/
public function __construct($username, $password, \SoapClient $paymentSoapClient = null)
public function __construct($username, $password, $wsdlPath = null, \SoapClient $paymentSoapClient = null)
{
if ($paymentSoapClient !== null) {
$this->soapClient = $paymentSoapClient;
return;
} else if ($wsdlPath !== null) {
$this->soapClient = new DOIT_SOA_PAYMENT_V2_Service(
[],
$wsdlPath
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
} else {
$this->soapClient = new DOIT_SOA_PAYMENT_V2_Service(
[],
__DIR__ . '/../../../../../../resources/doit_soa_payment_v2.xml'
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
}
$this->soapClient = new DOIT_SOA_PAYMENT_V2_Service(
[],
__DIR__ . '/../../../../../../resources/doit_soa_payment_v2.xml'
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
}
/**
......
......@@ -20,17 +20,24 @@ class SoapPriceService implements PriceService, SoapService
/**
* @inheritdoc
*/
public function __construct($username, $password, \SoapClient $priceSoapClient = null)
public function __construct($username, $password, $wsdlPath = null, \SoapClient $priceSoapClient = null)
{
if ($priceSoapClient !== null) {
$this->soapClient = $priceSoapClient;
return;
} else if ($wsdlPath !== null) {
$this->soapClient = new DOIT_SOA_PRICING_V2_Service(
[],
$wsdlPath
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
} else {
$this->soapClient = new DOIT_SOA_PRICING_V2_Service(
[],
__DIR__ . '/../../../../../resources/doit_soa_pricing_v2.xml'
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
}
$this->soapClient = new DOIT_SOA_PRICING_V2_Service(
[],
__DIR__ . '/../../../../../resources/doit_soa_pricing_v2.xml'
);
$this->soapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
}
/**
......
......@@ -11,7 +11,7 @@ use edu\wisc\services\cbs\product\update\generated\DOIT_SOA_ITEM_UPDATE_V4_Servi
/**
* Class SoapTechstoreClient uses SOAP to create a product in the CBS database.
*/
class SoapProductService implements ProductService, SoapService
class SoapProductService implements ProductService
{
/** @var DOIT_SOA_ITEM_CREATE_V4_Service */
......@@ -21,16 +21,38 @@ class SoapProductService implements ProductService, SoapService
private $productUpdateSoapClient;
/**
* @inheritdoc
* A SOAP service is constructed with a username and password. If a {@link \SoapClient} is provided, the username
* and password are ignored.
*
* @param string $username username
* @param string $password password
* @param string|null $createWsdlPath path to WSDL for specifying CBS environment. Defaults to QA
* @param string|null $updateWsdlPath path to WSDL for specifying CBS environment. Defaults to QA
* @param \SoapClient|null $productCreateSoapClient Overriding SOAP client (for testing purposes)
* @param \SoapClient|null $productUpdateSoapClient Overriding SOAP client (for testing purposes)
*/
public function __construct(
$username,
$password,
$createWsdlPath = null,
$updateWsdlPath = null,
\SoapClient $productCreateSoapClient = null,
\SoapClient $productUpdateSoapClient = null
)
{
if ($productCreateSoapClient === null || $productUpdateSoapClient === null) {
if ($createWsdlPath !== null && $updateWsdlPath !== null) {
$this->productCreateSoapClient = new DOIT_SOA_ITEM_CREATE_V4_Service(
[],
$createWsdlPath
);
$this->productCreateSoapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken( $username, $password));
$this->productUpdateSoapClient = new DOIT_SOA_ITEM_UPDATE_V4_Service(
[],
$updateWsdlPath
);
$this->productUpdateSoapClient->__setSoapHeaders(WssSoapHeaderBuilder::buildUsernameToken($username, $password));
} else if ($productCreateSoapClient === null || $productUpdateSoapClient === null) {
$this->productCreateSoapClient = new DOIT_SOA_ITEM_CREATE_V4_Service(
[],
__DIR__ . '/../../../../../resources/doit_soa_item_create_v4.xml'
......
<?php
use \edu\wisc\services\cbs\api\SoapService;
use \edu\wisc\services\cbs\order\header\SoapOrderHeaderService;
use \edu\wisc\services\cbs\IntegrationTestCase;
/**
* Integration tests to test the various methods of instantiating a {@link SoapOrderHeaderService}.
* A {@link SoapOrderHeaderService} can be instantiated using:
*
* 1. Only username and password
* 2. Username, password and WSDL to specify a CBS environment
* 3. Username, password and instance of {@link MockOrderHeaderServiceClient}
*/
class SoapOrderHeaderServiceIT extends IntegrationTestCase
{
/**
* @test
*/
public function createsClientWithOnlyUsernameAndPassword()
{
$soapOrderHeaderService = new SoapOrderHeaderService(
static::$itData['cbs.username'],
static::$itData['cbs.password']
);
static::assertNotNull($soapOrderHeaderService);
}
/**
* @test
*/
public function createsClientWithWsdl()
{
$soapOrderHeaderService = new SoapOrderHeaderService(
static::$itData['cbs.username'],
static::$itData['cbs.password'],
SoapService::QA_HEADER
);
static::assertNotNull($soapOrderHeaderService);
}
}
\ No newline at end of file
......@@ -23,7 +23,7 @@ class SoapOrderInterfacingServiceTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->mockSoapClient = \Mockery::mock(DOIT_SOA_ORDER_IFACE_I_V2_Service::class);
$this->orderInterfacingService = new SoapOrderInterfacingService('', '', $this->mockSoapClient);
$this->orderInterfacingService = new SoapOrderInterfacingService('', '', null, $this->mockSoapClient);
}
/** Close/verify mock after each test */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment