Skip to content

Commit

Permalink
Merge pull request #60 from rvdbogerd/pass-soap-context-attributes
Browse files Browse the repository at this point in the history
Pass soapEndpoint and soapAction attributes on the serializer context
  • Loading branch information
goetas authored Jan 11, 2021
2 parents 20de7ef + dab63a9 commit 3079bef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public function __call(string $functionName, array $args)

$bag = new HeadersOutgoing($headers);
$context = SerializationContext::create()->setAttribute('headers_outgoing', $bag);
$context->setAttribute('soapOperation', $soapOperation);
$context->setAttribute('soapEndpoint', $this->serviceDefinition['endpoint']);

$xmlMessage = $this->serializer->serialize($message, 'xml', $context);

$requestMessage = $this->createRequestMessage($xmlMessage, $soapOperation);
Expand Down
31 changes: 31 additions & 0 deletions tests/Client/Client12RequestResponsesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use GoetasWebservices\XML\WSDLReader\DefinitionsReader;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GuzzleHttp\Psr7\Response;
use JMS\Serializer\Context;
use JMS\Serializer\GraphNavigator;
use Symfony\Component\EventDispatcher\EventDispatcher;

class Client12RequestResponsesTest extends RequestResponsesTest
Expand Down Expand Up @@ -398,4 +400,33 @@ public function testApplicationError(int $code): void
'), $detail->asXML());
}
}

public function testSerializerContextParametersAreAdded()
{
$this->handlerRegistry->registerHandler(GraphNavigator::DIRECTION_SERIALIZATION, \Ex\SoapEnvelope12\Messages\GetSimpleInput::class, 'xml',
function($visitor, \Ex\SoapEnvelope12\Messages\GetSimpleInput $obj, array $type, Context $context) {

$this->assertTrue($context->hasAttribute('soapEndpoint'), 'The "soapEndpoint" attribute was not found on the context object');
$this->assertEquals('http://www.example.org/12', $context->getAttribute('soapEndpoint'));

$this->assertTrue($context->hasAttribute('soapOperation'), 'The "soapOperation" attribute was not found on the context object');
$this->assertTrue(
is_array($context->getAttribute('soapOperation')),
'The "soapOperation" attribute is not of type array, but '.gettype($context->getAttribute('soapOperation'))
);
$this->assertEquals('http://www.example.org/test/getSimple', $context->getAttribute('soapOperation')['action']);

throw new SerializerHandlerAssertionsWereExecuted('Stop serialization, test has finished');
}
);

$client = $this->getClient();

// Assert that subscribing handler with assertions was executed
$this->expectException(SerializerHandlerAssertionsWereExecuted::class);

$client->getSimple('foo');
}
}

class SerializerHandlerAssertionsWereExecuted extends \Exception {};
8 changes: 7 additions & 1 deletion tests/Client/RequestResponsesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ abstract class RequestResponsesTest extends TestCase
*/
protected $factory;

/**
* @var HandlerRegistryInterface
*/
protected $handlerRegistry;

public static function setUpBeforeClass(): void
{
self::$generator = new Generator(self::$namespaces, [], __DIR__ . '/tmp');
Expand All @@ -81,8 +86,9 @@ public function setUp(): void
$d->addSubscriber($headerHandler);
};

$handlers = static function (HandlerRegistryInterface $h) use ($headerHandler): void {
$handlers = function (HandlerRegistryInterface $h) use ($headerHandler): void {
$h->registerSubscribingHandler($headerHandler);
$this->handlerRegistry = $h;
};

$serializer = self::$generator->buildSerializer($handlers, [
Expand Down

0 comments on commit 3079bef

Please sign in to comment.