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