Skip to content

Commit

Permalink
Test using lowest possible dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Dec 23, 2014
1 parent 555c105 commit 09499e7
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 51 deletions.
15 changes: 5 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.3.3
- 5.3
- 5.4
- 5.5
Expand All @@ -11,18 +10,14 @@ php:
matrix:
allow_failures:
- php: hhvm

env:
- SYMFONY_VERSION="2.2.0" GUZZLE_VERSION="3.0.0" SENSIO_FRAMEWORK_EXTRA_VERSION="~2.2"
- SYMFONY_VERSION="2.3.x" GUZZLE_VERSION="~3.0" SENSIO_FRAMEWORK_EXTRA_VERSION="~2.2"
- SYMFONY_VERSION="~2.4" GUZZLE_VERSION="~3.0" SENSIO_FRAMEWORK_EXTRA_VERSION="~3.0"
include:
- php: 5.3.3
env: dependencies=lowest

before_install:
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --no-interaction --no-update
- composer require guzzle/guzzle:${GUZZLE_VERSION} --no-interaction --no-update
- composer require sensio/framework-extra-bundle:${SENSIO_FRAMEWORK_EXTRA_VERSION} --no-interaction --dev --no-update
- composer self-update

install:
- composer install --no-interaction --dev --prefer-source
- if [ "$dependencies" = "lowest" ]; then composer update --dev --prefer-lowest --prefer-stable --prefer-source --no-interaction; else composer install --dev --prefer-source --no-interaction; fi;

script: ./vendor/bin/phpunit
2 changes: 1 addition & 1 deletion Resources/doc/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Executing the `GetPerson` command will now return an instance of `Vendor\MyBundl
$command = $client->getCommand('GetPerson', array('id' => $id));
$person = $client->execute($command);

If you wish to customize the deserialization context of the serializer, you can do so by usage of the `data` property of the Operation. Groups, version, and max depth checks are configurable for deserialization:
If you wish to customize the deserialization context of the serializer (JMSSerializer v0.12+), you can do so by usage of the `data` property of the Operation. Groups, version, and max depth checks (JMSSerializer v0.13+) are configurable for deserialization:

For example:

Expand Down
36 changes: 24 additions & 12 deletions Service/Command/JMSSerializerResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,36 @@ protected function deserialize(CommandInterface $command, Response $response, $c
if (null !== $serializerContentType &&
OperationInterface::TYPE_CLASS === $command->getOperation()->getResponseType()
) {
$context = DeserializationContext::create();
$operation = $command->getOperation();
if (true === class_exists('JMS\Serializer\DeserializationContext')) {
$context = DeserializationContext::create();
$operation = $command->getOperation();

if (null !== $groups = $operation->getData('jms_serializer.groups')) {
$context->setGroups($groups);
}
if (null !== $version = $operation->getData('jms_serializer.version')) {
$context->setVersion($version);
}
if (true === $operation->getData('jms_serializer.max_depth_checks')) {
$context->enableMaxDepthChecks();
if (null !== $groups = $operation->getData('jms_serializer.groups')) {
$context->setGroups($groups);
}
if (null !== $version = $operation->getData('jms_serializer.version')) {
$context->setVersion($version);
}
if (
true === $operation->getData('jms_serializer.max_depth_checks')
&&
true === method_exists('JMS\Serializer\DeserializationContext', 'enableMaxDepthChecks')
) {
$context->enableMaxDepthChecks();
}

return $this->serializer->deserialize(
$response->getBody(),
$command->getOperation()->getResponseClass(),
$serializerContentType,
$context
);
}

return $this->serializer->deserialize(
$response->getBody(),
$command->getOperation()->getResponseClass(),
$serializerContentType,
$context
$serializerContentType
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,31 @@ public function visit(CommandInterface $command, RequestInterface $request, Para
$contentType = 'xml';
break;
}
$context = SerializationContext::create();

if (null !== $groups = $param->getData('jms_serializer.groups')) {
$context->setGroups($groups);
}
if (null !== $version = $param->getData('jms_serializer.version')) {
$context->setVersion($version);
}
if (null !== $nulls = $param->getData('jms_serializer.serialize_nulls')) {
$context->setSerializeNull($nulls);
}
if (true === $param->getData('jms_serializer.max_depth_checks')) {
$context->enableMaxDepthChecks();
}
if (true === class_exists('JMS\Serializer\SerializationContext')) {
$context = SerializationContext::create();

if (null !== $groups = $param->getData('jms_serializer.groups')) {
$context->setGroups($groups);
}
if (null !== $version = $param->getData('jms_serializer.version')) {
$context->setVersion($version);
}
if (null !== $nulls = $param->getData('jms_serializer.serialize_nulls')) {
$context->setSerializeNull($nulls);
}
if (
true === $param->getData('jms_serializer.max_depth_checks')
&&
true === method_exists('JMS\Serializer\SerializationContext', 'enableMaxDepthChecks')
) {
$context->enableMaxDepthChecks();
}

$value = $this->serializer->serialize($filteredValue, $contentType, $context);
$value = $this->serializer->serialize($filteredValue, $contentType, $context);
} else {
$value = $this->serializer->serialize($filteredValue, $contentType);
}
}

parent::visit($command, $request, $param, $value);
Expand Down
23 changes: 17 additions & 6 deletions Tests/Service/Command/JMSSerializerResponseParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ class JMSSerializerResponseParserTest extends \PHPUnit_Framework_TestCase
{
public function testDeserializeContextConfiguration()
{
$expectedContext = DeserializationContext::create();
$expectedContext->setGroups('group');
$expectedContext->setVersion(1);
$expectedContext->enableMaxDepthChecks();
if (true === class_exists('JMS\Serializer\DeserializationContext')) {
$expectedContext = DeserializationContext::create();
$expectedContext->setGroups('group');
$expectedContext->setVersion(1);
if(true === method_exists('JMS\Serializer\DeserializationContext', 'enableMaxDepthChecks')) {
$expectedContext->enableMaxDepthChecks();
}
} else {
$expectedContext = null;
}

$operation = $this->getMock('Guzzle\Service\Description\OperationInterface');
$operation->expects($this->any())->method('getResponseType')->will($this->returnValue(OperationInterface::TYPE_CLASS));
Expand All @@ -46,8 +52,13 @@ public function testDeserializeContextConfiguration()
$response->setBody('body');

$serializer = $this->getMock('JMS\Serializer\SerializerInterface');
$serializer->expects($this->once())->method('deserialize')
->with('body', 'ResponseClass', 'json', $this->equalTo($expectedContext));
if(null === $expectedContext) {
$serializer->expects($this->once())->method('deserialize')
->with('body', 'ResponseClass', 'json');
} else {
$serializer->expects($this->once())->method('deserialize')
->with('body', 'ResponseClass', 'json', $this->equalTo($expectedContext));
}

$parser = new JMSSerializerResponseParser($serializer, $this->getMock('Guzzle\Service\Command\ResponseParserInterface'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ class JMSSerializerBodyVisitorTest extends \PHPUnit_Framework_TestCase
{
public function testSerializeContextConfiguration()
{
$expectedContext = SerializationContext::create();
$expectedContext->setGroups('group');
$expectedContext->setVersion(1);
$expectedContext->setSerializeNull(true);
$expectedContext->enableMaxDepthChecks();
if (true === class_exists('JMS\Serializer\SerializationContext')) {
$expectedContext = SerializationContext::create();
$expectedContext->setGroups('group');
$expectedContext->setVersion(1);
$expectedContext->setSerializeNull(true);
if(true === method_exists('JMS\Serializer\SerializationContext', 'enableMaxDepthChecks')) {
$expectedContext->enableMaxDepthChecks();
}
} else {
$expectedContext = null;
}

$parameter = $this->getMock('Guzzle\Service\Description\Parameter');
$parameter->expects($this->once())->method('getSentAs')->will($this->returnValue('json'));
Expand All @@ -45,9 +51,15 @@ public function testSerializeContextConfiguration()
->getMock();

$serializer = $this->getMock('JMS\Serializer\SerializerInterface');
$serializer->expects($this->once())->method('serialize')
->with(array(), 'json', $this->equalTo($expectedContext))
->will($this->returnValue('serialized'));
if(null === $expectedContext) {
$serializer->expects($this->once())->method('serialize')
->with(array(), 'json')
->will($this->returnValue('serialized'));
} else {
$serializer->expects($this->once())->method('serialize')
->with(array(), 'json', $this->equalTo($expectedContext))
->will($this->returnValue('serialized'));
}

$parser = new JMSSerializerBodyVisitor($serializer, $this->getMock('Guzzle\Service\Command\ResponseParserInterface'));

Expand Down

0 comments on commit 09499e7

Please sign in to comment.