WSO2 WSF/PHP comes with a comprehensive set of test cases. It covers the most of the basic/concrete scenarios supported by WSF/PHP. You can find these test cases inside the “src/tests” directory of WSF/PHP source package. Or you can find the latest test-suite from the SVN location.
You have to have the ‘pear’ utility tool comes with PHP. And add this to the PATH environment variable.
Copy the samples and src/tests/samples/services directory (paths are relative to the root directory of the wsf/php package) to the web root directory.
Then go to the src/tests directory and execute the following command.
pear run-tests -r
This will execute all the test cases under the ‘tests’ directory and finally give a summery of the test results.
You can run individual test cases separately by providing the relative path to the test case from the ‘test’ directory. E.g. To run the echo_client.phpt test case, you may type
PHP2WSDL feature of the WSF/PHP allows you to generate the WSDL for your service when you access the URL formed by adding “?wsdl” to the service URL ( or you can use service URL + “?wsdl2″ to access the wsdl version 2.0). It will generate the schema types for the wsdl from the classes you use to build the request message + the annotations you provided describing the types of the variables.
Sometime you may need to generate schema types with different names to the corresponding PHP classes. May be you need to have a ‘-’ in the schema type which is not valid in PHP class syntax or you like to have a different naming convention for PHP and wsdl. Similarly you may need to have the operation names different in the WSDL and the PHP code.
Here is how you do it with WSF/PHP.
Different Names for Operations
/**
* Service logic for the echo operation
* @namespace http://ws.dimuthu.org/php/myecho/operations
* @param object testObject $param
* @return object testObject $return
*/function echoMe($param){return$param;
}/* The Service operation name to PHP function name map */$operations = array("echo" => "echoMe");
There I want my actual operation name to be echo. But I can’t declare a function name echo since PHP already has a library function echo (Yea, the one you regularly use to echo output). So I don’t have option other than declaring a function with different name (here it is “echoMe”) and mapped it in to echo operation in the operation map. We are going to feed this $operation variable at the WSService creation as its constructor argument.
Lets see how different names are used in schema types and corresponding php class names.
Different names for Types and Classes
/**
* @namespace http://ws.dimuthu.org/php/myecho/types
*/class testObject {/**
* @var integer aint
*/public$aint;
/**
* @var string astring
*/public$astring;
}/* The mapping of schema types to PHP class */$classmap = array("test-object" => "testObject");
It is similar how we mapped operation in the previous section. Just use $classmap variable which map the schema type name to the php class name.
Here is the type section and the interface section of the WSDL 2.0 generated using above codes. Observe the operation names and the types names are formed the way we expected.
Here is the complete code (Combining all the previously mentioned code segments). You can check the complete wsdl generation (wsdl 1.1 or wsdl 2.0 as your preference) by copying and pasting this code to the online php2wsdl generator at the WSF/PHP Demo Site.
<?php/**
* Service logic for the echo operation
* @namespace http://ws.dimuthu.org/php/myecho/operations
* @param object testObject $param
* @return object testObject $return
*/function echoMe($param){return$param;
}/**
* @namespace http://ws.dimuthu.org/php/myecho/types
*/class testObject {/**
* @var integer aint
*/public$aint;
/**
* @var string astring
*/public$astring;
}/* The Service operation name to PHP function name map */$operations = array("echo" => "echoMe");
/* Telling that we input MIX types for the parameters */$opParams = array("echo" => "MIXED");
/* The mapping of schema types to PHP class */$classmap = array("test-object" => "testObject");
/* Creating the WSService and serving the Request */$service = new WSService(array("operations" => $operations,
"classmap" => $classmap,
"opParams" => $opParams,
"serviceName" => "myEcho"));
$service->reply();
?>