diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldItemNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldItemNormalizer.php index bee3930f7417e2927f5b6fa3a4751230bbe6da7f..a427fee0f9012a0f54d4fe3070246bffad282267 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldItemNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldItemNormalizer.php @@ -8,6 +8,7 @@ namespace Drupal\hal\Normalizer; use Drupal\Core\Field\FieldItemInterface; +use Symfony\Component\Serializer\Exception\InvalidArgumentException; /** * Converts the Drupal field item object structure to HAL array structure. @@ -45,10 +46,10 @@ public function normalize($field_item, $format = NULL, array $context = array()) */ public function denormalize($data, $class, $format = NULL, array $context = array()) { if (!isset($context['target_instance'])) { - throw new LogicException('$context[\'target_instance\'] must be set to denormalize with the FieldItemNormalizer'); + throw new InvalidArgumentException('$context[\'target_instance\'] must be set to denormalize with the FieldItemNormalizer'); } if ($context['target_instance']->getParent() == NULL) { - throw new LogicException('The field item passed in via $context[\'target_instance\'] must have a parent set.'); + throw new InvalidArgumentException('The field item passed in via $context[\'target_instance\'] must have a parent set.'); } $field_item = $context['target_instance']; diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php index 2648998f927f1b17b0e396eff1cd27e0f3574857..99a669c590188c6dfc4d482fe8af09f8769104c1 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php @@ -8,7 +8,7 @@ namespace Drupal\hal\Normalizer; use Drupal\Component\Utility\NestedArray; -use Symfony\Component\Serializer\Exception\LogicException; +use Symfony\Component\Serializer\Exception\InvalidArgumentException; /** * Converts the Drupal field structure to HAL array structure. @@ -62,10 +62,10 @@ public function normalize($field, $format = NULL, array $context = array()) { */ public function denormalize($data, $class, $format = NULL, array $context = array()) { if (!isset($context['target_instance'])) { - throw new LogicException('$context[\'target_instance\'] must be set to denormalize with the FieldNormalizer'); + throw new InvalidArgumentException('$context[\'target_instance\'] must be set to denormalize with the FieldNormalizer'); } if ($context['target_instance']->getParent() == NULL) { - throw new LogicException('The field passed in via $context[\'target_instance\'] must have a parent set.'); + throw new InvalidArgumentException('The field passed in via $context[\'target_instance\'] must have a parent set.'); } $field = $context['target_instance']; diff --git a/core/modules/hal/tests/Drupal/hal/Tests/FieldItemNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/Drupal/hal/Tests/FieldItemNormalizerDenormalizeExceptionsUnitTest.php new file mode 100644 index 0000000000000000000000000000000000000000..dc73cbdc716b7311ba1961d33f41d265f4b0097a --- /dev/null +++ b/core/modules/hal/tests/Drupal/hal/Tests/FieldItemNormalizerDenormalizeExceptionsUnitTest.php @@ -0,0 +1,47 @@ + 'FieldItemNormalizer::denormalize() Unit Test', + 'description' => 'Test that FieldItemNormalizer::denormalize() throws proper exceptions.', + 'group' => 'HAL', + ); + } + + /** + * Tests that the FieldItemNormalizer::denormalize() throws proper exceptions. + * + * @param array $context + * Context for FieldItemNormalizer::denormalize(). + * + * @dataProvider providerNormalizerDenormalizeExceptions + * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException + */ + public function testFieldItemNormalizerDenormalizeExceptions($context) { + $field_item_normalizer = new FieldItemNormalizer(); + $data = array(); + $class = array(); + $field_item_normalizer->denormalize($data, $class, NULL, $context); + } + +} diff --git a/core/modules/hal/tests/Drupal/hal/Tests/FieldNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/Drupal/hal/Tests/FieldNormalizerDenormalizeExceptionsUnitTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c39ffa0480c7d27f4f2204db84d4448b6cf6f0fa --- /dev/null +++ b/core/modules/hal/tests/Drupal/hal/Tests/FieldNormalizerDenormalizeExceptionsUnitTest.php @@ -0,0 +1,47 @@ + 'FieldNormalizer::denormalize() Unit Test', + 'description' => 'Test that FieldNormalizer::denormalize() throws proper exceptions.', + 'group' => 'HAL', + ); + } + + /** + * Tests that the FieldNormalizer::denormalize() throws proper exceptions. + * + * @param array $context + * Context for FieldNormalizer::denormalize(). + * + * @dataProvider providerNormalizerDenormalizeExceptions + * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException + */ + public function testFieldNormalizerDenormalizeExceptions($context) { + $field_item_normalizer = new FieldNormalizer(); + $data = array(); + $class = array(); + $field_item_normalizer->denormalize($data, $class, NULL, $context); + } + +} diff --git a/core/modules/hal/tests/Drupal/hal/Tests/NormalizerDenormalizeExceptionsUnitTestBase.php b/core/modules/hal/tests/Drupal/hal/Tests/NormalizerDenormalizeExceptionsUnitTestBase.php new file mode 100644 index 0000000000000000000000000000000000000000..f16b223230ff7f87beb28e253998e182261897a1 --- /dev/null +++ b/core/modules/hal/tests/Drupal/hal/Tests/NormalizerDenormalizeExceptionsUnitTestBase.php @@ -0,0 +1,36 @@ +getMock('\Drupal\Core\Field\Plugin\DataType\FieldItem', array('getParent')); + $mock->expects($this->any()) + ->method('getParent') + ->will($this->returnValue(NULL)); + return array( + array(array()), + array(array('target_instance' => $mock)), + ); + } + +}