diff --git a/src/main/edu/wisc/services/cbs/api/SoapService.php b/src/main/edu/wisc/services/cbs/api/SoapService.php index a95788173000251abb9f85364123b2bcaeb153bb..026f5fc1b01802256ab82fa0a46a0fa1b4fea93c 100644 --- a/src/main/edu/wisc/services/cbs/api/SoapService.php +++ b/src/main/edu/wisc/services/cbs/api/SoapService.php @@ -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); } diff --git a/src/main/edu/wisc/services/cbs/order/header/SoapOrderHeaderService.php b/src/main/edu/wisc/services/cbs/order/header/SoapOrderHeaderService.php index c340902ddc5517d63181a79cb2c205570c4c2169..43430848ecddaf7d7332133ecc526e23c26b0b6c 100644 --- a/src/main/edu/wisc/services/cbs/order/header/SoapOrderHeaderService.php +++ b/src/main/edu/wisc/services/cbs/order/header/SoapOrderHeaderService.php @@ -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( [], diff --git a/src/main/edu/wisc/services/cbs/order/interfacing/SoapOrderInterfacingService.php b/src/main/edu/wisc/services/cbs/order/interfacing/SoapOrderInterfacingService.php index 176ad2f679b21312e157d6437e6b161629d77cac..45d736c238bb5fcd68793d801f9c7e970c612ddb 100644 --- a/src/main/edu/wisc/services/cbs/order/interfacing/SoapOrderInterfacingService.php +++ b/src/main/edu/wisc/services/cbs/order/interfacing/SoapOrderInterfacingService.php @@ -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) diff --git a/src/main/edu/wisc/services/cbs/order/line/SoapOrderLineService.php b/src/main/edu/wisc/services/cbs/order/line/SoapOrderLineService.php index 528aaf4b0eff4e869fe52c8235e7736245ecc7e4..d36789550666d7c84d9004b666a3a8a3976b9956 100644 --- a/src/main/edu/wisc/services/cbs/order/line/SoapOrderLineService.php +++ b/src/main/edu/wisc/services/cbs/order/line/SoapOrderLineService.php @@ -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( [], diff --git a/src/main/edu/wisc/services/cbs/order/payment/SoapOrderPaymentService.php b/src/main/edu/wisc/services/cbs/order/payment/SoapOrderPaymentService.php index dce73ae2de4f4cd103449f7a0174afea3bee80ff..09564d3ae1cd3f3e4b31c247d8edc26b117462cf 100644 --- a/src/main/edu/wisc/services/cbs/order/payment/SoapOrderPaymentService.php +++ b/src/main/edu/wisc/services/cbs/order/payment/SoapOrderPaymentService.php @@ -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)); } /** diff --git a/src/main/edu/wisc/services/cbs/price/SoapPriceService.php b/src/main/edu/wisc/services/cbs/price/SoapPriceService.php index c980072b37b8f1499c39928c9ff3f8c3e75b6a3e..c78e519596bff12cbda6be85682be286e1c3dec2 100644 --- a/src/main/edu/wisc/services/cbs/price/SoapPriceService.php +++ b/src/main/edu/wisc/services/cbs/price/SoapPriceService.php @@ -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)); } /** diff --git a/src/main/edu/wisc/services/cbs/product/SoapProductService.php b/src/main/edu/wisc/services/cbs/product/SoapProductService.php index 95cf698f0e6c1e3460fc3a91d3f13643dde4956f..6896569a9d57e31deb7490096509663fbaeae833 100755 --- a/src/main/edu/wisc/services/cbs/product/SoapProductService.php +++ b/src/main/edu/wisc/services/cbs/product/SoapProductService.php @@ -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' diff --git a/src/test/edu/wisc/services/cbs/order/header/SoapOrderHeaderServiceIT.php b/src/test/edu/wisc/services/cbs/order/header/SoapOrderHeaderServiceIT.php new file mode 100644 index 0000000000000000000000000000000000000000..a0b428ec1ead8a70e5f0ef406a468e7fc7c8d9ae --- /dev/null +++ b/src/test/edu/wisc/services/cbs/order/header/SoapOrderHeaderServiceIT.php @@ -0,0 +1,43 @@ +<?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 diff --git a/src/test/edu/wisc/services/cbs/order/interfacing/SoapOrderInterfacingServiceTest.php b/src/test/edu/wisc/services/cbs/order/interfacing/SoapOrderInterfacingServiceTest.php index 54a30eeeff639b227c943cc83a893afadc23ad04..0747c0907dc704436a3a6932ee2af104d1c682f7 100644 --- a/src/test/edu/wisc/services/cbs/order/interfacing/SoapOrderInterfacingServiceTest.php +++ b/src/test/edu/wisc/services/cbs/order/interfacing/SoapOrderInterfacingServiceTest.php @@ -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 */