Skip to content

Commit 6be7590

Browse files
committed
Simplify internal Client constructor initialization
1 parent 7d6ed98 commit 6be7590

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

src/Client.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,23 @@
2020
*/
2121
final class Client
2222
{
23-
private $wsdl;
2423
private $browser;
2524
private $encoder;
2625
private $decoder;
2726

2827
/**
29-
* [internal] Instantiate new SOAP client, see Factory instead
28+
* Instantiate new SOAP client
3029
*
31-
* @param string $wsdl
3230
* @param Browser $browser
33-
* @param ClientEncoder $encoder
34-
* @param ClientDecoder $decoder
35-
* @internal
31+
* @param string $wsdlContents
3632
*/
37-
public function __construct($wsdl, Browser $browser, ClientEncoder $encoder = null, ClientDecoder $decoder = null)
33+
public function __construct(Browser $browser, $wsdlContents)
3834
{
39-
if ($encoder === null) {
40-
$encoder = new ClientEncoder($wsdl);
41-
}
42-
43-
if ($decoder === null) {
44-
$decoder = new ClientDecoder($wsdl);
45-
}
46-
47-
$this->wsdl = $wsdl;
4835
$this->browser = $browser;
49-
$this->encoder = $encoder;
50-
$this->decoder = $decoder;
36+
$this->encoder = new ClientEncoder(
37+
'data://text/plain;base64,' . base64_encode($wsdlContents)
38+
);
39+
$this->decoder = new ClientDecoder();
5140
}
5241

5342
/**

src/Factory.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@
2727
*/
2828
final class Factory
2929
{
30-
private $loop;
3130
private $browser;
3231

3332
public function __construct(LoopInterface $loop, Browser $browser = null)
3433
{
3534
if ($browser === null) {
3635
$browser = new Browser($loop);
3736
}
38-
$this->loop = $loop;
3937
$this->browser = $browser;
4038
}
4139

@@ -53,15 +51,18 @@ public function __construct(LoopInterface $loop, Browser $browser = null)
5351
* );
5452
* ```
5553
*
56-
* @param string $wsdl
54+
* @param string $wsdlUri
5755
* @return PromiseInterface Returns a Promise<Client, Exception>
5856
*/
59-
public function createClient($wsdl)
57+
public function createClient($wsdlUri)
6058
{
61-
$that = $this;
59+
$browser = $this->browser;
6260

63-
return $this->browser->get($wsdl)->then(function (ResponseInterface $response) use ($that) {
64-
return $that->createClientFromWsdl((string)$response->getBody());
61+
return $this->browser->get($wsdlUri)->then(function (ResponseInterface $response) use ($browser) {
62+
return new Client(
63+
$browser,
64+
(string)$response->getBody()
65+
);
6566
});
6667
}
6768

@@ -76,9 +77,6 @@ public function createClient($wsdl)
7677
*/
7778
public function createClientFromWsdl($wsdlContents)
7879
{
79-
$browser = $this->browser;
80-
$url = 'data://text/plain;base64,' . base64_encode($wsdlContents);
81-
82-
return new Client($url, $browser);
80+
return new Client($this->browser, $wsdlContents);
8381
}
8482
}

tests/ClientTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use Clue\React\Soap\Client;
4+
use PHPUnit\Framework\TestCase;
5+
6+
class ClientTest extends TestCase
7+
{
8+
public function testConstructorThrowsWhenUrlIsInvalid()
9+
{
10+
if (extension_loaded('xdebug')) {
11+
$this->markTestSkipped('Invalid WSDL causes a fatal error when ext-xdebug is loaded');
12+
}
13+
14+
$browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock();
15+
$wsdl = 'invalid';
16+
17+
$client = new Client($browser, $wsdl);
18+
}
19+
}

0 commit comments

Comments
 (0)