Completed
Push — master ( 621c9b...c81ada )
by Meng
8s
created

FactoryTest::wsdlMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 70
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 70
rs 9.1724
cc 1
eloc 10
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Meng\AsyncSoap\Guzzle;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Handler\MockHandler;
7
use GuzzleHttp\HandlerStack;
8
use GuzzleHttp\Psr7\Response;
9
10
class FactoryTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @test
14
     */
15
    public function nonWsdlMode()
16
    {
17
        $factory = new Factory();
18
        $client = $factory->create(new Client(), null, ['uri'=>'', 'location'=>'']);
19
        $this->assertTrue($client instanceof SoapClient);
20
    }
21
22
    /**
23
     * @test
24
     */
25
    public function wsdlMode()
26
    {
27
        // this wsdl adapted from https://www.w3.org/2001/04/wsws-proceedings/uche/wsdl.html
28
        $wsdl = <<<EOD
29
<definitions name="EndorsementSearch"
30
  targetNamespace="http://namespaces.snowboard-info.com"
31
  xmlns:es="http://www.snowboard-info.com/EndorsementSearch.wsdl"
32
  xmlns:esxsd="http://schemas.snowboard-info.com/EndorsementSearch.xsd"
33
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
34
  xmlns="http://schemas.xmlsoap.org/wsdl/"
35
>
36
37
  <!-- omitted types section with content model schema info -->
38
39
  <message name="GetEndorsingBoarderRequest">
40
    <part name="body" element="esxsd:GetEndorsingBoarder"/>
41
  </message>
42
43
  <message name="GetEndorsingBoarderResponse">
44
    <part name="body" element="esxsd:GetEndorsingBoarderResponse"/>
45
  </message>
46
47
  <portType name="GetEndorsingBoarderPortType">
48
    <operation name="GetEndorsingBoarder">
49
      <input message="es:GetEndorsingBoarderRequest"/>
50
      <output message="es:GetEndorsingBoarderResponse"/>
51
    </operation>
52
  </portType>
53
54
  <binding name="EndorsementSearchSoapBinding"
55
           type="es:GetEndorsingBoarderPortType">
56
    <soap:binding style="document"
57
                  transport="http://schemas.xmlsoap.org/soap/http"/>
58
    <operation name="GetEndorsingBoarder">
59
      <soap:operation
60
        soapAction="http://www.snowboard-info.com/EndorsementSearch"/>
61
      <input>
62
        <soap:body use="literal"
63
          namespace="http://schemas.snowboard-info.com/EndorsementSearch.xsd"/>
64
      </input>
65
      <output>
66
        <soap:body use="literal"
67
          namespace="http://schemas.snowboard-info.com/EndorsementSearch.xsd"/>
68
      </output>
69
      <fault>
70
        <soap:body use="literal"
71
          namespace="http://schemas.snowboard-info.com/EndorsementSearch.xsd"/>
72
      </fault>
73
    </operation>
74
  </binding>
75
76
  <service name="EndorsementSearchService">
77
    <documentation>snowboarding-info.com Endorsement Service</documentation>
78
    <port name="GetEndorsingBoarderPort"
79
          binding="es:EndorsementSearchSoapBinding">
80
      <soap:address location="http://www.snowboard-info.com/EndorsementSearch"/>
81
    </port>
82
  </service>
83
84
</definitions>
85
EOD;
86
87
        $factory = new Factory();
88
        $handlerMock = new MockHandler([new Response('200', [], $wsdl)]);
89
        $handler = new HandlerStack($handlerMock);
90
        $clientMock = new Client(['handler' => $handler]);
91
        $client = $factory->create($clientMock, 'wsdl');
92
        $this->assertTrue($client instanceof SoapClient);
93
94
    }
95
}
96