misd-service-development / guzzle-bundle

[NOT MAINTAINED] Integrates Guzzle into your Symfony2 application
99 stars 54 forks source link

onCommandCreate listener not used when creating commands from service definition #12

Closed smoorhouse11 closed 11 years ago

smoorhouse11 commented 11 years ago

I haven't been able to get automatic deserialization for services instantiated using the service description method described in the documentation.

So the expectation is that I can:

$client = $container->get('test_foo_service');
$command = $client->getCommand('GetFoo');
$fooIDOutputResult = $client->execute($command);

... and that the result ($fooIDOutputResult) is an instance of FooVendor\HttpBundle\Tests\WebService\Mock\FooIDOutput, as described below. However, it's actually an array.

Service description in services_test.yml:

services:
    test_foo_servicedescription:
        class: "%guzzle.service_description.class%"
        factory_class: "%guzzle.service_description.class%"
        factory_method: factory
        arguments: [ "%kernel.root_dir%/../src/FooVendor/HttpBundle/Tests/WebService/Mock/ServiceDefn/FooService.json" ]

    test_foo_service:
        class: "%guzzle.client.class%"
        calls:
            - [ setDescription, [ @test_foo_servicedescription ] ]

This is the json services description file, FooService.json. It seems like the description loads ok.

{
    "name": "Foo",
    "baseUrl": "http://foo.example.com",
    "description": "Foo is an API that allows you to Baz Bar",
    "operations": {
            "GetFoo": {
                "httpMethod": "GET",
                "uri": "/foo",
                "summary": "Gets a certain foo",
                "responseClass": " FooVendor\\HttpBundle\\Tests\\WebService\\Mock\\FooIDOutput"
            }
    }
}

It seems like the onCommandCreate listener might not be attached when the service is created in this fashion. Is this the correct way of doing things?

thewilkybarkid commented 11 years ago

Looks like you're missing the guzzle.client tag on your client service, add it and you should see the listener attached.

smoorhouse11 commented 11 years ago

You're right, tagging the client service with guzzle.client does hook up the listener. Thanks!

thewilkybarkid commented 11 years ago

No problem. :smiley: