I hooked the php-opencloud samples up to a compliance test suite that runs samples from various rackspace/openstack providers. It does its best to find a sample that matches each of its scenarios, so it can run it and compare with results from other SDKs.
Some scenarios already pass, because they don't require any user interaction and are similar enough to samples from other SDKs. E.g. the test framework finds and successfully runs samples/Compute/create_server.php for the "create server" scenario.
However, some have hardcoded values in them that need to be changed before executing.
For example, in samples/Compute/delete_server.php:
// 3. Get your existing server
$serverId = '7af22b0d-7d01-4460-a222-77e65a9ab184';
$server = $service->server($serverId);
So, in order for this test to be automated-sample-code-runner friendly, the $serverId needs to be a dynamic lookup, or I need some other way to inject the value.
The simplest approach, which I've used for examples in other SDKs and would work right away, is to do a lookup based on a name, which is stored in an environment variable.
An alternate approach I'd be willing to spike is for my framework to inject values into the code. This would actually work well with the current userguide on php-opencloud or the ones being worked on for developer.rackspace.com, which have been showing IDs like this:
$image = $service->image('<image_id>');
or this:
$flavor = $service->flavor('{flavorId}');
There obviously a slight discrepancy w/ the syntax there. If I had to vote I'd go with the mustache syntax, since it's widely supported. That would allow me to easily run tests in my ruby-based "polyglot sample code runner", while individual SDKs could also easily implement compatible langauge-specific test runners (php for this, java for jclouds samples, etc.)
The mustache syntax uses double curly braces:
$serverId = '{{serverId}}';
I hooked the php-opencloud samples up to a compliance test suite that runs samples from various rackspace/openstack providers. It does its best to find a sample that matches each of its scenarios, so it can run it and compare with results from other SDKs.
Some scenarios already pass, because they don't require any user interaction and are similar enough to samples from other SDKs. E.g. the test framework finds and successfully runs samples/Compute/create_server.php for the "create server" scenario.
However, some have hardcoded values in them that need to be changed before executing.
For example, in samples/Compute/delete_server.php:
So, in order for this test to be automated-sample-code-runner friendly, the
$serverIdneeds to be a dynamic lookup, or I need some other way to inject the value.The simplest approach, which I've used for examples in other SDKs and would work right away, is to do a lookup based on a name, which is stored in an environment variable.
An alternate approach I'd be willing to spike is for my framework to inject values into the code. This would actually work well with the current userguide on php-opencloud or the ones being worked on for developer.rackspace.com, which have been showing IDs like this:
or this:
There obviously a slight discrepancy w/ the syntax there. If I had to vote I'd go with the mustache syntax, since it's widely supported. That would allow me to easily run tests in my ruby-based "polyglot sample code runner", while individual SDKs could also easily implement compatible langauge-specific test runners (php for this, java for jclouds samples, etc.)
The mustache syntax uses double curly braces: