diff options
Diffstat (limited to 'tests/unit/Soap')
-rw-r--r-- | tests/unit/Soap/ContactManager.php | 155 | ||||
-rw-r--r-- | tests/unit/Soap/SoapTest.php | 93 | ||||
-rw-r--r-- | tests/unit/Soap/mockapp/application.xml | 9 | ||||
-rw-r--r-- | tests/unit/Soap/mockapp/pages/.gitignore | 0 | ||||
-rwxr-xr-x | tests/unit/Soap/mockapp/runtime/.gitignore | 2 | ||||
-rw-r--r-- | tests/unit/Soap/mockapp/ws.php | 7 |
6 files changed, 266 insertions, 0 deletions
diff --git a/tests/unit/Soap/ContactManager.php b/tests/unit/Soap/ContactManager.php new file mode 100644 index 00000000..2fbeec48 --- /dev/null +++ b/tests/unit/Soap/ContactManager.php @@ -0,0 +1,155 @@ +<?php + +/** + * Keeps track of the people in our Contact list. + * + * Starts with a standard Contact list and can add + * new people to our list or change existing Contacts. + * This class is for example purposes only, just to + * show how to create a webservice + */ +class ContactManager{ + + /** + * Gets the current Contact list. + * @return Contact[] + * @soapmethod + */ + public function getContacts() { + $Contact = new Contact(); + $Contact->address = new Address(); + $Contact->address->city ="sesamcity"; + $Contact->address->street ="sesamstreet"; + $Contact->email = "me@you.com"; + $Contact->id = 1; + $Contact->name ="me"; + + $ret[] = $Contact; + //debugObject("Contacten: ",$ret); + return $ret; + } + + /** + * Gets the Contact with the given id. + * @param int $id The id + * @return Contact + * @soapmethod + */ + public function getContact($id) { + //get Contact from db + //might wanna throw an exception when it does not exists + throw new Exception("Contact '$id' not found"); + } + /** + * Generates an new, empty Contact template + * @return Contact + * @soapmethod + */ + public function newContact() { + return new Contact(); + } + + /** + * Saves a given Contact + * @param Contact $Contact + * @return boolean + * @soapmethod + */ + public function saveContact(Contact $Contact) { + //error_log(var_export($Contact,true)); + //$Contact->save(); + return true; + } + + /** + * @return mixed + * @soapmethod + */ + public function getList() + { + return array(array(1,2), array("12", 1.2)); + } + + /** + * @return array + * @soapmethod + */ + public function getEmptyArray() + { + return array(); + } + +} + + +/** + * The Contact details for a person + * + * Stores the person's name, address and e-mail + * This class is for example purposes only, just to + * show how to create a webservice + * + */ +class Contact{ + + /** + * @var int $id + * @soapproperty + */ + public $id; + + /** + * @var string $name + * @soapproperty + */ + public $name; + + /** @var Address $address + * @soapproperty + */ + public $address; + + /** @var string $email + * @soapproperty + */ + public $email; + + /** + * saves a Contact + * + * @return void + */ + public function save() { + //save Contact 2 db + } +} + +/** + * Stores an address + * + * An address consists of a street, number, zipcode and city. + * This class is for example purposes only, just to + * show how to create a webservice + * + */ +class Address{ + /** @var string $street + * @soapproperty + */ + public $street; + + /** @var string $nr + * @soapproperty + */ + public $nr; + + /** @var string $zipcode + * @soapproperty + */ + public $zipcode; + + /** @var string $city + * @soapproperty + */ + public $city; +} diff --git a/tests/unit/Soap/SoapTest.php b/tests/unit/Soap/SoapTest.php new file mode 100644 index 00000000..6d4505d6 --- /dev/null +++ b/tests/unit/Soap/SoapTest.php @@ -0,0 +1,93 @@ +<?php + +ini_set("soap.wsdl_cache_enabled",0); + +require_once(dirname(__FILE__).'/ContactManager.php'); + +/** + * @package System.Soap + */ +class SoapTestCase extends PHPUnit_Framework_TestCase +{ + function getWsdlUri() + { + $script = str_replace('unit.php', 'ws.php',$_SERVER['SCRIPT_NAME']); + return "http://".$_SERVER['HTTP_HOST'].$script.'?soap=contacts.wsdl'; + } + + function getClient() + { + return new SoapClient($this->getWsdlUri()); + } + + function testContactArray() + { + $result = $this->getClient()->getContacts(); + $this->assertEqual(count($result), 1); + $obj = $result->Contact; + $this->assertEqual($obj->name, "me"); + $this->assertEqual($obj->id, 1); + $this->assertEqual($obj->address->street, "sesamstreet"); + $this->assertNull($obj->address->nr); + $this->assertNull($obj->address->zipcode); + $this->assertEqual($obj->address->city, "sesamcity"); + $this->assertEqual($obj->email, "me@you.com"); + } + + function testGetContactThrowsException() + { + try + { + $result = $this->getClient()->getContact(1); + $this->fail(); + } + catch (SoapFault $f) + { + $this->pass(); + } + } + + function testGetNewContact() + { + $obj = $this->getClient()->newContact(); + $this->assertNull($obj->name); + $this->assertNull($obj->id); + $this->assertNull($obj->address); + $this->assertNull($obj->email); + } + + function testSaveContactReturnsTrue() + { + $c = new Contact; + $result = $this->getClient()->saveContact($c); + $this->assertTrue($result); + } + + function getMixedArray() + { + $result = $this->getClient()>getList(); + $expected = array(array(1,2), array("12", 1.2)); + $this->assertEqual($result, $expected); + } + + function testEmptyArray() + { + $result = $this->getClient()->getEmptyArray(); + $this->assertTrue(is_array($result)); + $this->assertEqual(count($result), 0); + } + + function testUnknownFunctionThrowsException() + { + try + { + $this->getClient()->test(); + $this->fail(); + } + catch (SoapFault $f) + { + $this->pass(); + } + } +} + diff --git a/tests/unit/Soap/mockapp/application.xml b/tests/unit/Soap/mockapp/application.xml new file mode 100644 index 00000000..69961b84 --- /dev/null +++ b/tests/unit/Soap/mockapp/application.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> + +<application id="simple_unit" mode="Debug"> + <services> + <service id="soap" class="System.Web.Services.TSoapService"> + <soap id="contacts" provider="Application.Soap.ContactManager" ClassMaps="Contact, Address"/> + </service> + </services> +</application>
\ No newline at end of file diff --git a/tests/unit/Soap/mockapp/pages/.gitignore b/tests/unit/Soap/mockapp/pages/.gitignore new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/unit/Soap/mockapp/pages/.gitignore diff --git a/tests/unit/Soap/mockapp/runtime/.gitignore b/tests/unit/Soap/mockapp/runtime/.gitignore new file mode 100755 index 00000000..d6b7ef32 --- /dev/null +++ b/tests/unit/Soap/mockapp/runtime/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/unit/Soap/mockapp/ws.php b/tests/unit/Soap/mockapp/ws.php new file mode 100644 index 00000000..9096183e --- /dev/null +++ b/tests/unit/Soap/mockapp/ws.php @@ -0,0 +1,7 @@ +<?php + +include_once '../../framework/prado.php'; +include_once './Soap/ContactManager.php'; + +$app = new TApplication('.'); +$app->run(); |