Completed
Push — master ( 2bee4f...6ae4b6 )
by Meng
02:05
created

SoapClientTest::webServicesProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 41
rs 8.8571
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
3
use GuzzleHttp\Client;
4
use Meng\AsyncSoap\Guzzle\Factory;
5
use Meng\Soap\HttpBinding\RequestBuilder;
6
7
//todo try other options, e.g. classmap; try non-wsdl mode; try other web services.
8
class SoapClientTest extends PHPUnit_Framework_TestCase
9
{
10
    /** @var  Factory */
11
    private $factory;
12
13
    protected function setUp()
14
    {
15
        $this->factory = new Factory();
16
    }
17
18
    /**
19
     * @test
20
     */
21
    public function call()
22
    {
23
        $client = $this->factory->create(
24
            new Client(),
25
            new RequestBuilder(),
26
            'http://www.webservicex.net/Statistics.asmx?WSDL'
27
        );
28
        $response = $client->call('GetStatistics', [['X' => [1,2,3]]]);
29
        $this->assertNotEmpty($response);
30
    }
31
32
    /**
33
     * @test
34
     * @dataProvider webServicesProvider
35
     */
36
    public function callAsync($wsdl, $options, $function, $args, $contains)
37
    {
38
        $client = $this->factory->create(
39
            new Client(),
40
            new RequestBuilder(),
41
            $wsdl,
42
            $options
43
        );
44
        $response = null;
45
        $promise = $client->callAsync($function, $args)->then(
46
            function ($result) use (&$response) {
47
                $response = $result;
48
            }
49
        );
50
        $promise->wait();
51
        $this->assertNotEmpty($response);
52
        foreach ($contains as $contain) {
53
            $this->assertArrayHasKey($contain, (array)$response);
54
        }
55
    }
56
57
    public function webServicesProvider()
58
    {
59
        return [
60
            [
61
                'wsdl' => 'http://www.webservicex.net/Statistics.asmx?WSDL',
62
                'options' => [],
63
                'function' => 'GetStatistics',
64
                'args' => [['X' => [1,2,3]]],
65
                'contains' => [
66
                    'Sums', 'Average', 'StandardDeviation', 'skewness', 'Kurtosis'
67
                ]
68
            ],
69
            [
70
                'wsdl' => 'http://www.webservicex.net/Statistics.asmx?WSDL',
71
                'options' => ['soap_version' => SOAP_1_2],
72
                'function' => 'GetStatistics',
73
                'args' => [['X' => [1,2,3]]],
74
                'contains' => [
75
                    'Sums', 'Average', 'StandardDeviation', 'skewness', 'Kurtosis'
76
                ]
77
            ],
78
            [
79
                'wsdl' => 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL',
80
                'options' => [],
81
                'function' => 'ConversionRate',
82
                'args' => [['FromCurrency' => 'GBP', 'ToCurrency' => 'USD']],
83
                'contains' => [
84
                    'ConversionRateResult'
85
                ]
86
            ],
87
            [
88
                'wsdl' => 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL',
89
                'options' => ['soap_version' => SOAP_1_2],
90
                'function' => 'ConversionRate',
91
                'args' => [['FromCurrency' => 'GBP', 'ToCurrency' => 'USD']],
92
                'contains' => [
93
                    'ConversionRateResult'
94
                ]
95
            ],
96
        ];
97
    }
98
}