Completed
Push — master ( 59e50d...c35625 )
by Meng
02:00
created

SoapClientTest::webServicesProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 23
rs 9.0856
cc 1
eloc 14
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/CurrencyConvertor.asmx?WSDL',
71
                'options' => [],
72
                'function' => 'ConversionRate',
73
                'args' => [['FromCurrency' => 'GBP', 'ToCurrency' => 'USD']],
74
                'contains' => [
75
                    'ConversionRateResult'
76
                ]
77
            ],
78
        ];
79
    }
80
}