Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftassi/583208 to your computer and use it in GitHub Desktop.
Save ftassi/583208 to your computer and use it in GitHub Desktop.
<?php
class OrteStartWith {
public $prefix; // string
}
class OrteStartWithResponse {
public $OrteStartWithResult; // string
}
class GetPrefixedEntries {
public $prefix; // string
}
class GetPrefixedEntriesResponse {
public $GetPrefixedEntriesResult; // string
}
/**
* OrteLookup class
*
* A WebService retreiving the names of German cities starting with a specific string.
*
* @author {author}
* @copyright {copyright}
* @package {package}
*/
class OrteLookupClient extends SoapClient {
private static $classmap = array(
'OrteStartWith' => 'OrteStartWith',
'OrteStartWithResponse' => 'OrteStartWithResponse',
'GetPrefixedEntries' => 'GetPrefixedEntries',
'GetPrefixedEntriesResponse' => 'GetPrefixedEntriesResponse',
);
public function OrteLookupClient($wsdl = "http://mathertel.de/AJAXEngine/S02_AJAXCoreSamples/OrteLookup.asmx?WSDL", $options = array()) {
foreach(self::$classmap as $key => $value) {
if(!isset($options['classmap'][$key])) {
$options['classmap'][$key] = $value;
}
}
parent::__construct($wsdl, $options);
}
/**
*
*
* @param OrteStartWith $parameters
* @return OrteStartWithResponse
*/
public function OrteStartWith(OrteStartWith $parameters) {
return $this->__soapCall('OrteStartWith', array($parameters), array(
'uri' => 'http://www.mathertel.de/OrteLookup/',
'soapaction' => ''
)
);
}
/**
* Return Lookup entries that start with the given prefix.
*
* @param GetPrefixedEntries $parameters
* @return GetPrefixedEntriesResponse
*/
public function GetPrefixedEntries(GetPrefixedEntries $parameters) {
return $this->__soapCall('GetPrefixedEntries', array($parameters), array(
'uri' => 'http://www.mathertel.de/OrteLookup/',
'soapaction' => ''
)
);
}
}
?>
/**
*
*
* @param OrteStartWith $parameters
* @return OrteStartWithResponse
*/
public function OrteStartWith(OrteStartWith $parameters) {
return $this->__soapCall('OrteStartWith', array($parameters), array(
'uri' => 'http://www.mathertel.de/OrteLookup/',
'soapaction' => ''
)
);
}
class OrteLookupService
{
/**
* SoapClient
*
* @var OrteLookupClient
*/
protected $client;
/**
* Costruttore
*
* @param OrteLookupClient $client
*/
public function __construct(OrteLookupClient $client)
{
$this->client = $client;
}
/**
* startWith
*
* Ritorna un array di città tedesce che iniziano
* con $string
*
* @param array $start
*/
public function startWith($prefix)
{
$request = new OrteStartWith();
$request->prefix = $prefix;
$response = $this->client->OrteStartWith($request);
$response = explode(';', $response->OrteStartWithResult);
return $response;
}
}
class OrteLookupServiceTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->wsdl = 'http://mathertel.de/AJAXEngine/S02_AJAXCoreSamples/OrteLookup.asmx?WSDL';
}
public function testStartWith()
{
$start = 'foo';
$cities = array('fooCity1', 'fooCity2');
$client = $this->getMockSoapClient($start, $cities);
$service = new OrteLookupService($client);
$this->assertType('array', $service->startWith($start));
$this->assertEquals($cities, $service->startWith($start));
}
/**
* Stub per OrteLookupClient
*
* Configura un oggetto OrteLookupClient che simuli una chiamata
* al metodo startWith.
*
*
* @param string $input
* @param array $result
*/
protected function getMockSoapClient($input, $result)
{
$orteStartWith = new OrteStartWith();
$orteStartWith->prefix = $input;
$orteStartWithResponse = new OrteStartWithResponse();
$orteStartWithResponse->OrteStartWithResult = implode(';', $result);
$client = $this->getMock('OrteLookupClient');
$client->expects($this->any())
->method('OrteStartWith')
->with($this->equalTo($orteStartWith))
->will($this->returnValue($orteStartWithResponse));
return $client;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment