From aaca80a262fe9dd0240be7ca88fddd26bf9b73cc Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 4 Sep 2011 00:36:24 +0200 Subject: [PATCH] Used BeSimple\SoapCommon\Cache to define the cache strategy --- .gitignore | 1 + src/BeSimple/SoapClient/Soap/SoapClient.php | 12 ++++-- .../Tests/SoapClient/Soap/SoapClientTest.php | 10 +++-- tests/bootstrap.php | 7 ++++ vendors.php | 41 +++++++++++++++++++ 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100755 vendors.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..22d0d82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor diff --git a/src/BeSimple/SoapClient/Soap/SoapClient.php b/src/BeSimple/SoapClient/Soap/SoapClient.php index 61273b1..8b5b187 100644 --- a/src/BeSimple/SoapClient/Soap/SoapClient.php +++ b/src/BeSimple/SoapClient/Soap/SoapClient.php @@ -12,6 +12,8 @@ namespace BeSimple\SoapClient\Soap; +use BeSimple\SoapCommon\Cache; + /** * @author Francis Besset */ @@ -33,8 +35,8 @@ class SoapClient public function setOptions(array $options) { $this->options = array( - 'cache_dir' => null, - 'debug' => false, + 'debug' => false, + 'cache_wsdl' => null, ); // check option names and live merge, if errors are encountered Exception will be thrown @@ -135,7 +137,11 @@ class SoapClient { $options = array(); - $options['cache_wsdl'] = $this->options['debug'] ? WSDL_CACHE_NONE : WSDL_CACHE_DISK; + if (null === $this->options['cache_wsdl']) { + $this->options['cache_wsdl'] = Cache::getType(); + } + + $options['cache_wsdl'] = $this->options['cache_wsdl']; $options['trace'] = $this->options['debug']; return $options; diff --git a/tests/BeSimple/Tests/SoapClient/Soap/SoapClientTest.php b/tests/BeSimple/Tests/SoapClient/Soap/SoapClientTest.php index e82ca30..bb6d03a 100644 --- a/tests/BeSimple/Tests/SoapClient/Soap/SoapClientTest.php +++ b/tests/BeSimple/Tests/SoapClient/Soap/SoapClientTest.php @@ -12,6 +12,7 @@ namespace BeSimple\Tests\SoapClient\Soap; +use BeSimple\SoapCommon\Cache; use BeSimple\SoapClient\Soap\SoapClient; class SoapClientTest extends \PHPUnit_Framework_TestCase @@ -20,8 +21,8 @@ class SoapClientTest extends \PHPUnit_Framework_TestCase { $soapClient = new SoapClient('foo.wsdl'); $options = array( - 'cache_dir' => '/tmp', - 'debug' => true, + 'cache_wsdl' => Cache::TYPE_DISK_MEMORY, + 'debug' => true, ); $soapClient->setOptions($options); @@ -62,9 +63,12 @@ class SoapClientTest extends \PHPUnit_Framework_TestCase public function testGetSoapOptions() { + Cache::setType(Cache::TYPE_MEMORY); $soapClient = new SoapClient('foo.wsdl', array('debug' => true)); + $this->assertEquals(array('cache_wsdl' => Cache::getType(), 'trace' => true), $soapClient->getSoapOptions()); - $this->assertEquals(array('cache_wsdl' => WSDL_CACHE_NONE, 'trace' => true), $soapClient->getSoapOptions()); + $soapClient = new SoapClient('foo.wsdl', array('debug' => false, 'cache_wsdl' => Cache::TYPE_NONE)); + $this->assertEquals(array('cache_wsdl' => Cache::TYPE_NONE, 'trace' => false), $soapClient->getSoapOptions()); } public function testGetNativeSoapClient() diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 80850f4..fdc4599 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -16,6 +16,13 @@ spl_autoload_register(function($class) { if (file_exists($path) && is_readable($path)) { require_once $path; + return true; + } + } else if (0 === strpos($class, 'BeSimple\SoapCommon\\')) { + $path = __DIR__.'/../vendor/besimple-soapcommon/src/'.($class = strtr($class, '\\', '/')).'.php'; + if (file_exists($path) && is_readable($path)) { + require_once $path; + return true; } } diff --git a/vendors.php b/vendors.php new file mode 100755 index 0000000..cf763ae --- /dev/null +++ b/vendors.php @@ -0,0 +1,41 @@ +#!/usr/bin/env php + + * (c) Francis Besset + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/* + +CAUTION: This file installs the dependencies needed to run the BeSimpleSoapClient test suite. + +https://github.com/BeSimple/BeSimpleSoapClient + +*/ + +if (!is_dir($vendorDir = dirname(__FILE__).'/vendor')) { + mkdir($vendorDir, 0777, true); +} + +$deps = array( + array('besimple-soapcommon', 'http://github.com/BeSimple/BeSimpleSoapCommon.git', 'origin/HEAD'), +); + +foreach ($deps as $dep) { + list($name, $url, $rev) = $dep; + + echo "> Installing/Updating $name\n"; + + $installDir = $vendorDir.'/'.$name; + if (!is_dir($installDir)) { + system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($installDir))); + } + + system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev))); +}