Skip to content

Commit

Permalink
Merge branch '0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
francisbesset committed Aug 18, 2014
2 parents 102e4cf + 50f186f commit 91e91c4
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 22 deletions.
13 changes: 10 additions & 3 deletions Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function __construct(array $options = array(), $followLocationMaxRedirect
if (isset($options['connection_timeout'])) {
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $options['connection_timeout']);
}

if (isset($options['proxy_host'])) {
if (false !== $options['proxy_host']) {
$proxyHost = $options['proxy_host'].(isset($options['proxy_port']) ? $options['proxy_port'] : 8080);
Expand All @@ -88,10 +89,16 @@ public function __construct(array $options = array(), $followLocationMaxRedirect
}

curl_setopt($this->ch, CURLOPT_PROXY, $proxyHost);

if (false !== $proxyHost && isset($options['proxy_login'])) {
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_login'].':'.$options['proxy_password']);

if (isset($options['proxy_auth'])) {
curl_setopt($this->ch, CURLOPT_PROXYAUTH, $options['proxy_auth']);
}
}
}
if (isset($options['proxy_user'])) {
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']);
}

if (isset($options['login'])) {
curl_setopt($this->ch, CURLOPT_HTTPAUTH, isset($options['extra_options']['http_auth']) ? $options['extra_options']['http_auth'] : CURLAUTH_ANY);
curl_setopt($this->ch, CURLOPT_USERPWD, $options['login'].':'.$options['password']);
Expand Down
19 changes: 14 additions & 5 deletions SoapClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,28 @@ public function withDigestAuthentication($certificate, $passphrase = null)
*
* @param string $host Host
* @param int $port Port
* @param string $username Username
* @param string $login Login
* @param string $password Password
* @param int $auth Authentication method
*
* @return \BeSimple\SoapClient\SoapClientBuilder
*/
public function withProxy($host, $port, $username = null, $password = null)
public function withProxy($host, $port, $login = null, $password = null, $auth = null)
{
$this->soapOptions['proxy_host'] = $host;
$this->soapOptions['proxy_port'] = $port;

if ($username) {
$this->soapOptions['proxy_login'] = $username;
if ($login) {
$this->soapOptions['proxy_login'] = $login;
$this->soapOptions['proxy_password'] = $password;

if ($auth) {
if (!in_array($auth, array(\CURLAUTH_BASIC, \CURLAUTH_NTLM), true)) {
throw new \InvalidArgumentException('Invalid authentication method: CURLAUTH_BASIC or CURLAUTH_NTLM constants are availables.');
}

$this->soapOptions['proxy_auth'] = $auth;
}
}

return $this;
Expand Down Expand Up @@ -236,4 +245,4 @@ protected function validateOptions()
{
$this->validateWsdl();
}
}
}
3 changes: 2 additions & 1 deletion Tests/AxisInterop/MtomAxisInteropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MtomAxisInteropTest extends TestCase
'base64Binary' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\base64Binary',
'AttachmentRequest' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\AttachmentRequest',
),
'proxy_host' => false,
);

public function testAttachment()
Expand All @@ -48,4 +49,4 @@ public function testAttachment()
// $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer));
// unlink($fileCreatedByServer);
}
}
}
3 changes: 2 additions & 1 deletion Tests/AxisInterop/SwaAxisInteropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SwaAxisInteropTest extends TestCase
'uploadFile' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFile',
'uploadFileResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\uploadFileResponse',
),
'proxy_host' => false,
);

public function testUploadDownloadText()
Expand Down Expand Up @@ -74,4 +75,4 @@ public function testUploadDownloadImage()

$this->assertEquals($upload->data, $result->data);
}
}
}
3 changes: 2 additions & 1 deletion Tests/AxisInterop/WsAddressingAxisInteropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class WsAddressingAxisInteropTest extends TestCase
private $options = array(
'soap_version' => SOAP_1_2,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
'proxy_host' => false,
);

public function testSession()
Expand All @@ -56,4 +57,4 @@ public function testSession()

$this->assertEquals($soapSessionId1, $soapSessionId2);
}
}
}
3 changes: 2 additions & 1 deletion Tests/AxisInterop/WsSecuritySigEncAxisInteropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class WsSecuritySigEncAxisInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation',
),
'proxy_host' => false,
);

public function testSigEnc()
Expand Down Expand Up @@ -103,4 +104,4 @@ public function testSigEnc()

// getBooksByType("scifi");
}
}
}
3 changes: 2 additions & 1 deletion Tests/AxisInterop/WsSecurityUserPassAxisInteropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class WsSecurityUserPassAxisInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\AxisInterop\Fixtures\BookInformation',
),
'proxy_host' => false,
);

public function testUserPassText()
Expand Down Expand Up @@ -93,4 +94,4 @@ public function testUserPassDigest()

// getBooksByType("scifi");
}
}
}
16 changes: 12 additions & 4 deletions Tests/CurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,19 @@ public function testGetResponse()

public function testGetResponseBody()
{
$curl = new Curl();
$curl = new Curl(array(
'proxy_host' => false,
));

$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertEquals('This is a testfile for cURL.', $curl->getResponseBody());
}

public function testGetResponseContentType()
{
$curl = new Curl();
$curl = new Curl(array(
'proxy_host' => false,
));

$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertEquals('text/plain; charset=UTF-8', $curl->getResponseContentType());
Expand All @@ -93,7 +97,9 @@ public function testGetResponseContentType()

public function testGetResponseHeaders()
{
$curl = new Curl();
$curl = new Curl(array(
'proxy_host' => false,
));

$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertEquals(117 + self::$websererPortLength, strlen($curl->getResponseHeaders()));
Expand All @@ -104,7 +110,9 @@ public function testGetResponseHeaders()

public function testGetResponseStatusCode()
{
$curl = new Curl();
$curl = new Curl(array(
'proxy_host' => false,
));

$curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT));
$this->assertEquals(200, $curl->getResponseStatusCode());
Expand Down
3 changes: 2 additions & 1 deletion Tests/ServerInterop/MtomServerInteropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MtomServerInteropTest extends TestCase
'base64Binary' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\base64Binary',
'AttachmentRequest' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\AttachmentRequest',
),
'proxy_host' => false,
);

public function testAttachment()
Expand All @@ -40,4 +41,4 @@ public function testAttachment()
$this->assertEquals($b64->_, file_get_contents($fileCreatedByServer));
unlink($fileCreatedByServer);
}
}
}
1 change: 1 addition & 0 deletions Tests/ServerInterop/SwaServerInteropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SwaServerInteropTest extends TestCase
'uploadFile' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFile',
'uploadFileResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFileResponse',
),
'proxy_host' => false,
);

public function testUploadDownloadText()
Expand Down
3 changes: 2 additions & 1 deletion Tests/ServerInterop/WsSecuritySigEncServerInteropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class WsSecuritySigEncServerInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation',
),
'proxy_host' => false,
);

public function testSigEnc()
Expand Down Expand Up @@ -69,4 +70,4 @@ public function testSigEnc()

// getBooksByType("scifi");
}
}
}
3 changes: 2 additions & 1 deletion Tests/ServerInterop/WsSecurityUserPassServerInteropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class WsSecurityUserPassServerInteropTest extends TestCase
'addBookResponse' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse',
'BookInformation' => 'BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation',
),
'proxy_host' => false,
);

public function testUserPassText()
Expand Down Expand Up @@ -82,4 +83,4 @@ public function testUserPassDigest()

// getBooksByType("scifi");
}
}
}
14 changes: 14 additions & 0 deletions Tests/SoapClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ public function testWithProxy()

$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar');
$this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar')), $builder->getSoapOptions());

$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', \CURLAUTH_BASIC);
$this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar', 'proxy_auth' => \CURLAUTH_BASIC)), $builder->getSoapOptions());

$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', \CURLAUTH_NTLM);
$this->assertEquals($this->mergeOptions(array('proxy_host' => '127.0.0.1', 'proxy_port' => 8585, 'proxy_login' => 'foo', 'proxy_password' => 'bar', 'proxy_auth' => \CURLAUTH_NTLM)), $builder->getSoapOptions());

try {
$builder->withProxy('127.0.0.1', 8585, 'foo', 'bar', -100);

$this->fail('An expected exception has not been raised.');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e);
}
}

public function testCreateWithDefaults()
Expand Down
8 changes: 6 additions & 2 deletions Tests/WsdlDownloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public function testResolveWsdlIncludes($source, $cacheFile, $remoteParentUrl, $
Cache::setDirectory($wsdlCacheUrl);
$cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#');

$wsdlDownloader = new WsdlDownloader(new Curl());
$wsdlDownloader = new WsdlDownloader(new Curl(array(
'proxy_host' => false,
)));
$r = new \ReflectionClass($wsdlDownloader);
$m = $r->getMethod('resolveRemoteIncludes');
$m->setAccessible(true);
Expand Down Expand Up @@ -178,7 +180,9 @@ public function testResolveXsdIncludes($source, $cacheFile, $remoteParentUrl, $r
Cache::setDirectory($wsdlCacheUrl);
$cacheDirForRegExp = preg_quote($wsdlCacheUrl, '#');

$wsdlDownloader = new WsdlDownloader(new Curl());
$wsdlDownloader = new WsdlDownloader(new Curl(array(
'proxy_host' => false,
)));
$r = new \ReflectionClass($wsdlDownloader);
$m = $r->getMethod('resolveRemoteIncludes');
$m->setAccessible(true);
Expand Down

0 comments on commit 91e91c4

Please sign in to comment.