From 28ed21530d97c2d7131fe73f4e0a0d5c2e874fb0 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 9 Oct 2011 20:17:50 +0200 Subject: [PATCH] Added SoapClientBuilder --- src/BeSimple/SoapClient/SoapClientBuilder.php | 55 +++++++++++++ .../SoapClient/SoapClientBuilderTest.php | 81 +++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 src/BeSimple/SoapClient/SoapClientBuilder.php create mode 100644 tests/BeSimple/Tests/SoapClient/SoapClientBuilderTest.php diff --git a/src/BeSimple/SoapClient/SoapClientBuilder.php b/src/BeSimple/SoapClient/SoapClientBuilder.php new file mode 100644 index 0000000..7134cf6 --- /dev/null +++ b/src/BeSimple/SoapClient/SoapClientBuilder.php @@ -0,0 +1,55 @@ + + * (c) Francis Besset + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapClient; + +use BeSimple\SoapCommon\AbstractSoapBuilder; + +/** + * @author Francis Besset + */ +class SoapClientBuilder extends AbstractSoapBuilder +{ + protected $wsdl; + protected $options; + + /** + * @return SoapClientBuilder + */ + static public function createWithDefaults() + { + return parent::createWithDefaults() + ->withUserAgent('BeSimpleSoap') + ; + } + + public function withTrace($trace = true) + { + $this->options['trace'] = $trace; + + return $this; + } + + public function withExceptions($exceptions = true) + { + $this->options['exceptions'] = $exceptions; + + return $this; + } + + public function withUserAgent($userAgent) + { + $this->options['user_agent'] = $userAgent; + + return $this; + } +} \ No newline at end of file diff --git a/tests/BeSimple/Tests/SoapClient/SoapClientBuilderTest.php b/tests/BeSimple/Tests/SoapClient/SoapClientBuilderTest.php new file mode 100644 index 0000000..cad1111 --- /dev/null +++ b/tests/BeSimple/Tests/SoapClient/SoapClientBuilderTest.php @@ -0,0 +1,81 @@ + + * (c) Francis Besset + * + * 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, + ); + + public function testContruct() + { + $options = $this + ->getSoapBuilder() + ->getOptions() + ; + + $this->assertEquals($this->mergeOptions(array()), $options); + } + + public function testWithTrace() + { + $builder = $this->getSoapBuilder(); + + $builder->withTrace(); + $this->assertEquals($this->mergeOptions(array('trace' => true)), $builder->getOptions()); + + $builder->withTrace(false); + $this->assertEquals($this->mergeOptions(array('trace' => false)), $builder->getOptions()); + } + + public function testWithExceptions() + { + $builder = $this->getSoapBuilder(); + + $builder->withExceptions(); + $this->assertEquals($this->mergeOptions(array('exceptions' => true)), $builder->getOptions()); + + $builder->withExceptions(false); + $this->assertEquals($this->mergeOptions(array('exceptions' => false)), $builder->getOptions()); + } + + public function testWithUserAgent() + { + $builder = $this->getSoapBuilder(); + + $builder->withUserAgent('BeSimpleSoap Test'); + $this->assertEquals($this->mergeOptions(array('user_agent' => 'BeSimpleSoap Test')), $builder->getOptions()); + } + + public function testCreateWithDefaults() + { + $builder = SoapClientBuilder::createWithDefaults(); + + $this->assertInstanceOf('BeSimple\SoapClient\SoapClientBuilder', $builder); + + $this->assertEquals($this->mergeOptions(array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'user_agent' => 'BeSimpleSoap')), $builder->getOptions()); + } + + private function getSoapBuilder() + { + return new SoapClientBuilder(); + } + + private function mergeOptions(array $options) + { + return array_merge($this->defaultOptions, $options); + } +} \ No newline at end of file