Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test using lowest possible dependencies #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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