BeSimpleSoap/tests/BeSimple/Tests/SoapClient/SoapClientBuilderTest.php

97 lines
3.2 KiB
PHP
Raw Normal View History

2011-10-09 20:17:50 +02:00
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\Tests\SoapCommon\Soap;
use BeSimple\SoapClient\SoapClientBuilder;
class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase
{
private $defaultOptions = array(
'features' => 0,
2011-10-10 00:02:20 +02:00
'classmap' => array(),
'typemap' => array(),
2011-10-09 20:17:50 +02:00
);
public function testContruct()
{
$options = $this
->getSoapBuilder()
2011-10-10 00:02:20 +02:00
->getSoapOptions()
2011-10-09 20:17:50 +02:00
;
$this->assertEquals($this->mergeOptions(array()), $options);
}
public function testWithTrace()
{
$builder = $this->getSoapBuilder();
$builder->withTrace();
2011-10-10 00:02:20 +02:00
$this->assertEquals($this->mergeOptions(array('trace' => true)), $builder->getSoapOptions());
2011-10-09 20:17:50 +02:00
$builder->withTrace(false);
2011-10-10 00:02:20 +02:00
$this->assertEquals($this->mergeOptions(array('trace' => false)), $builder->getSoapOptions());
2011-10-09 20:17:50 +02:00
}
public function testWithExceptions()
{
$builder = $this->getSoapBuilder();
$builder->withExceptions();
2011-10-10 00:02:20 +02:00
$this->assertEquals($this->mergeOptions(array('exceptions' => true)), $builder->getSoapOptions());
2011-10-09 20:17:50 +02:00
$builder->withExceptions(false);
2011-10-10 00:02:20 +02:00
$this->assertEquals($this->mergeOptions(array('exceptions' => false)), $builder->getSoapOptions());
2011-10-09 20:17:50 +02:00
}
public function testWithUserAgent()
{
$builder = $this->getSoapBuilder();
$builder->withUserAgent('BeSimpleSoap Test');
2011-10-10 00:02:20 +02:00
$this->assertEquals($this->mergeOptions(array('user_agent' => 'BeSimpleSoap Test')), $builder->getSoapOptions());
2011-10-09 20:17:50 +02:00
}
2011-10-11 21:50:07 +02:00
public function testWithAuthentication()
{
$builder = $this->getSoapBuilder();
$builder->withDigestAuthentication(__DIR__.'/Fixtures/cert.pem', 'foobar');
$this->assertEquals($this->mergeOptions(array('authentication' => SOAP_AUTHENTICATION_DIGEST, 'local_cert' => __DIR__.'/Fixtures/cert.pem', 'passphrase' => 'foobar')), $builder->getSoapOptions());
$builder->withDigestAuthentication(__DIR__.'/Fixtures/cert.pem');
$this->assertEquals($this->mergeOptions(array('authentication' => SOAP_AUTHENTICATION_DIGEST, 'local_cert' => __DIR__.'/Fixtures/cert.pem')), $builder->getSoapOptions());
$builder->withBasicAuthentication('foo', 'bar');
$this->assertEquals($this->mergeOptions(array('authentication' => SOAP_AUTHENTICATION_BASIC, 'login' => 'foo', 'password' => 'bar')), $builder->getSoapOptions());
}
2011-10-09 20:17:50 +02:00
public function testCreateWithDefaults()
{
$builder = SoapClientBuilder::createWithDefaults();
$this->assertInstanceOf('BeSimple\SoapClient\SoapClientBuilder', $builder);
2011-10-10 00:02:20 +02:00
$this->assertEquals($this->mergeOptions(array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'user_agent' => 'BeSimpleSoap')), $builder->getSoapOptions());
2011-10-09 20:17:50 +02:00
}
private function getSoapBuilder()
{
return new SoapClientBuilder();
}
private function mergeOptions(array $options)
{
return array_merge($this->defaultOptions, $options);
}
}