Skip to content

Commit 0a6b18a

Browse files
authored
Merge pull request #18 from meng-tian/fix-tests
Fix unit tests
2 parents e7a0c58 + 844b0f7 commit 0a6b18a

File tree

6 files changed

+759
-42
lines changed

6 files changed

+759
-42
lines changed

.github/workflows/main.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
strategy:
8+
matrix:
9+
operating-system: [ubuntu-latest]
10+
php-versions: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
11+
12+
runs-on: ${{ matrix.operating-system }}
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: Setup PHP, with composer and extensions
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: ${{ matrix.php-versions }}
22+
23+
- name: Get composer cache directory
24+
id: composer-cache
25+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
26+
27+
- name: Cache composer dependencies
28+
uses: actions/cache@v2
29+
with:
30+
path: ${{ steps.composer-cache.outputs.dir }}
31+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
32+
restore-keys: ${{ runner.os }}-composer-
33+
34+
- name: Install Composer dependencies
35+
run: |
36+
composer install --no-progress --prefer-dist --optimize-autoloader
37+
38+
- name: Run Tests
39+
run: vendor/bin/phpunit --coverage-text

README.md

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# PHP SOAP Interpreter [![Build Status](https://travis-ci.org/meng-tian/php-soap-interpreter.svg?branch=master)](https://travis-ci.org/meng-tian/php-soap-interpreter) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/meng-tian/php-soap-interpreter/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/meng-tian/php-soap-interpreter/?branch=master) [![codecov.io](https://codecov.io/github/meng-tian/php-soap-interpreter/coverage.svg?branch=master)](https://codecov.io/github/meng-tian/php-soap-interpreter?branch=master)
1+
# PHP SOAP Interpreter [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/meng-tian/php-soap-interpreter/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/meng-tian/php-soap-interpreter/?branch=master) [![codecov.io](https://codecov.io/github/meng-tian/php-soap-interpreter/coverage.svg?branch=master)](https://codecov.io/github/meng-tian/php-soap-interpreter?branch=master)
22

33
A PHP library for interpreting `SOAP 1.1` and `SOAP 1.2` messages. It can be used in WSDL or non-WSDL mode. The implementation is built on the top of PHP's [SoapClient](http://php.net/manual/en/class.soapclient.php).
44

5-
### Requirement
5+
### Prerequisite
66
PHP 5.4 --enablelibxml --enable-soap
77

88
### Install
@@ -11,11 +11,11 @@ composer require meng-tian/php-soap-interpreter
1111
```
1212

1313
### Usage
14-
An `Interpreter` instance is capable of generating SOAP request messages and translating SOAP response messages. Constructor of `Interpreter` class is the same as `SoapClient`. The first parameter is `wsdl`, the second parameter is an array of `options`.
14+
An `Interpreter` is responsible for generating SOAP request messages and translating SOAP response messages. The constructor of `Interpreter` class is the same as `SoapClient`. The first parameter is `wsdl`, the second parameter is an array of `options`.
1515

16-
It should be noted that *not* all `options` supported by `SoapClient` are supported by `Interpreter`. The responsibility of `Interpreter` is to interpreting SOAP messages, whereas the unsupported options are related to debugging or HTTP transportation. The supported `options` by `Interpreter` are: `location`, `uri`, `style`, `use`, `soap_version`, `encoding`, `exceptions`, `classmap`, `typemap`, `cache_wsdl` and `feature`. More detailed explanations of those options can be found in [SoapClient::SoapClient](http://php.net/manual/en/soapclient.soapclient.php).
16+
It should be noted that *not* all `options` supported by `SoapClient` are supported by `Interpreter`. The supported `options` of `Interpreter` are: `location`, `uri`, `style`, `use`, `soap_version`, `encoding`, `exceptions`, `classmap`, `typemap`, `cache_wsdl` and `features`. More detailed explanations of those options can be found in [SoapClient::SoapClient](http://php.net/manual/en/soapclient.soapclient.php). The unsupported options are related to debugging or HTTP transport, which are not the intended responsibility of `Interpreter`.
1717

18-
### Examples
18+
### Basic Examples
1919
###### Generate SOAP request message in WSDL mode
2020

2121
```php
@@ -35,6 +35,36 @@ Output:
3535
</SOAP-ENV:Envelope>
3636
```
3737

38+
###### Translate SOAP response message
39+
40+
```php
41+
$interpreter = new Interpreter('http://www.webservicex.net/length.asmx?WSDL');
42+
$response = <<<EOD
43+
<?xml version="1.0" encoding="utf-8"?>
44+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
45+
<soap:Body>
46+
<ChangeLengthUnitResponse xmlns="http://www.webserviceX.NET/">
47+
<ChangeLengthUnitResult>0.025400000000000002</ChangeLengthUnitResult>
48+
</ChangeLengthUnitResponse>
49+
</soap:Body>
50+
</soap:Envelope>
51+
EOD;
52+
$response = $interpreter->response($response, 'ChangeLengthUnit');
53+
54+
print_r($response);
55+
```
56+
Output:
57+
```php
58+
/*
59+
Output:
60+
stdClass Object
61+
(
62+
[ChangeLengthUnitResult] => 0.0254
63+
)
64+
*/
65+
```
66+
67+
### Advanced Examples
3868
###### Generate SOAP request message in non-WSDL mode
3969

4070
```php
@@ -61,41 +91,36 @@ Output:
6191

6292
```
6393

64-
###### Translate SOAP response message
6594

66-
```php
67-
$interpreter = new Interpreter('http://www.webservicex.net/length.asmx?WSDL');
68-
$response = <<<EOD
69-
<?xml version="1.0" encoding="utf-8"?>
70-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
71-
<soap:Body>
72-
<ChangeLengthUnitResponse xmlns="http://www.webserviceX.NET/">
73-
<ChangeLengthUnitResult>0.025400000000000002</ChangeLengthUnitResult>
74-
</ChangeLengthUnitResponse>
75-
</soap:Body>
76-
</soap:Envelope>
77-
EOD;
78-
$response = $interpreter->response($response, 'ChangeLengthUnit');
95+
###### SOAP input headers
7996

80-
print_r($response);
81-
```
82-
Output:
8397
```php
84-
/*
98+
$interpreter = new Interpreter('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
99+
$request = $interpreter->request('ConversionRate', [['FromCurrency' => 'AFA', 'ToCurrency' => 'ALL']], null, [new SoapHeader('www.namespace.com', 'test_header', 'header_data')]);
100+
print_r($request->getSoapMessage());
101+
```
85102
Output:
86-
stdClass Object
87-
(
88-
[ChangeLengthUnitResult] => 0.0254
89-
)
90-
*/
103+
```xml
104+
<?xml version="1.0" encoding="UTF-8"?>
105+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.webserviceX.NET/" xmlns:ns2="www.namespace.com">
106+
<SOAP-ENV:Header><ns2:test_header>header_data</ns2:test_header></SOAP-ENV:Header>
107+
<SOAP-ENV:Body><ns1:ConversionRate><ns1:FromCurrency>AFA</ns1:FromCurrency><ns1:ToCurrency>ALL</ns1:ToCurrency></ns1:ConversionRate></SOAP-ENV:Body>
108+
</SOAP-ENV:Envelope>
91109
```
110+
111+
###### SOAP output headers
112+
TODO
113+
114+
###### Class map
115+
TODO
116+
117+
###### Type map
118+
TODO
119+
92120
### Relevant
93121
- [SOAP HTTP Binding](https://github.com/meng-tian/soap-http-binding): binding SOAP messages to PSR-7 HTTP messages.
94122
- [PHP Asynchronous SOAP](https://github.com/meng-tian/php-async-soap): asynchronous SOAP clients.
95123

96-
### Credits
97-
Thanks the free SOAP web serivices hosted from http://www.webservicex.net. They are used for testing this library.
98-
99124
### License
100125
This library is released under [MIT](https://github.com/meng-tian/php-soap-interpreter/blob/master/LICENSE.md) license.
101126

src/Interpreter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Interpreter
1010
/**
1111
* @param mixed $wsdl URI of the WSDL file or NULL if working in non-WSDL mode.
1212
* @param array $options Supported options: location, uri, style, use, soap_version, encoding,
13-
* exceptions, classmap, typemap, cache_wsdl and feature.
13+
* exceptions, classmap, typemap, cache_wsdl and features.
1414
*/
1515
public function __construct($wsdl, array $options = [])
1616
{

tests/InterpreterTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class InterpreterTest extends PHPUnit_Framework_TestCase
1010
*/
1111
public function requestWsdlArrayArguments()
1212
{
13-
$interpreter = new Interpreter('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
13+
$interpreter = new Interpreter(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'currency.wsdl');
1414
$request = $interpreter->request('ConversionRate', [['FromCurrency' => 'AFA', 'ToCurrency' => 'ALL']]);
1515
$this->assertEquals('http://www.webservicex.net/CurrencyConvertor.asmx', $request->getEndpoint());
1616
$this->assertEquals('http://www.webserviceX.NET/ConversionRate', $request->getSoapAction());
@@ -29,7 +29,7 @@ public function requestWsdlArrayArguments()
2929
*/
3030
public function requestWsdlObjectArguments()
3131
{
32-
$interpreter = new Interpreter('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
32+
$interpreter = new Interpreter(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'currency.wsdl');
3333
$rate = new ConversionRate;
3434
$rate->FromCurrency = 'AFA';
3535
$rate->ToCurrency = 'ALL';
@@ -51,7 +51,7 @@ public function requestWsdlObjectArguments()
5151
*/
5252
public function requestWsdlInputHeaders()
5353
{
54-
$interpreter = new Interpreter('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
54+
$interpreter = new Interpreter(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'currency.wsdl');
5555
$request = $interpreter->request(
5656
'ConversionRate',
5757
[['FromCurrency' => 'AFA', 'ToCurrency' => 'ALL']],
@@ -79,7 +79,7 @@ public function requestWsdlInputHeaders()
7979
public function requestTypeMapToXML()
8080
{
8181
$interpreter = new Interpreter(
82-
'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL',
82+
dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'currency.wsdl',
8383
[
8484
'typemap' => [
8585
[
@@ -121,7 +121,7 @@ public function responseWsdl()
121121
</soap:Body>
122122
</soap:Envelope>
123123
EOD;
124-
$interpreter = new Interpreter('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
124+
$interpreter = new Interpreter(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'currency.wsdl');
125125
$responseMessage = $interpreter->response($responseMessage, 'ConversionRate');
126126
$this->assertInstanceOf('\StdClass', $responseMessage);
127127
$this->assertEquals(['ConversionRateResult' => '-1'], (array)$responseMessage);
@@ -147,7 +147,7 @@ public function responseWsdlOutputHeaders()
147147
</soap:Body>
148148
</soap:Envelope>
149149
EOD;
150-
$interpreter = new Interpreter('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
150+
$interpreter = new Interpreter(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'currency.wsdl');
151151
$outputHeaders = [];
152152
$responseMessage = $interpreter->response($responseMessage, 'ConversionRate', $outputHeaders);
153153
$this->assertInstanceOf('\StdClass', $responseMessage);
@@ -170,7 +170,7 @@ public function responseWsdlClassMap()
170170
</soap:Body>
171171
</soap:Envelope>
172172
EOD;
173-
$interpreter = new Interpreter('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL', ['classmap' => ['ConversionRateResponse' => '\ConversionRateResponse']]);
173+
$interpreter = new Interpreter(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'currency.wsdl', ['classmap' => ['ConversionRateResponse' => '\ConversionRateResponse']]);
174174
$responseMessage = $interpreter->response($responseMessage, 'ConversionRate');
175175
$this->assertInstanceOf('\ConversionRateResponse', $responseMessage);
176176
$this->assertEquals(['ConversionRateResult' => '-1'], (array)$responseMessage);
@@ -192,7 +192,7 @@ public function responseTypeMapFromXML()
192192
</soap:Envelope>
193193
EOD;
194194
$interpreter = new Interpreter(
195-
'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL',
195+
dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'currency.wsdl',
196196
[
197197
'typemap' => [
198198
[
@@ -249,7 +249,7 @@ public function responseWsdlDisableExceptions()
249249
*/
250250
public function requestWsdlSoapV12()
251251
{
252-
$interpreter = new Interpreter('http://www.webservicex.net/airport.asmx?WSDL', ['soap_version' => SOAP_1_2]);
252+
$interpreter = new Interpreter(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'airport.wsdl', ['soap_version' => SOAP_1_2]);
253253
$request = $interpreter->request('GetAirportInformationByCountry', [['country' => 'United Kingdom']]);
254254
$this->assertEquals('http://www.webservicex.net/airport.asmx', $request->getEndpoint());
255255
$this->assertEquals('http://www.webserviceX.NET/GetAirportInformationByCountry', $request->getSoapAction());
@@ -275,7 +275,7 @@ public function responseWsdlSoapV12()
275275
</soap:Body>
276276
</soap:Envelope>
277277
EOD;
278-
$interpreter = new Interpreter('http://www.webservicex.net/airport.asmx?WSDL', ['soap_version' => SOAP_1_2]);
278+
$interpreter = new Interpreter(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wsdl' . DIRECTORY_SEPARATOR . 'airport.wsdl', ['soap_version' => SOAP_1_2]);
279279
$responseMessage = $interpreter->response($responseMessage, 'GetAirportInformationByCountry');
280280
$this->assertEquals(['GetAirportInformationByCountryResult' => '<NewDataSet />'], (array)$responseMessage);
281281
}

0 commit comments

Comments
 (0)