Completed
Pull Request — master (#3)
by Meng
02:06
created

SoapClientTest::callAsync()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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