Commit 5a0edc30 authored by alexpott's avatar alexpott

Issue #2225333 by Boobaa: LogicException in...

Issue #2225333 by Boobaa: LogicException in Drupal\hal\Normalizer\FieldItemNormalizer does not exist.
parent 1ad4630a
......@@ -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'];
......
......@@ -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'];
......
<?php
/**
* @file
* Contains \Drupal\hal\Tests\FieldItemNormalizerDenormalizeExceptionsUnitTest.
*/
namespace Drupal\hal\Tests;
use Drupal\hal\Normalizer\FieldItemNormalizer;
/**
* @coversDefaultClass \Drupal\hal\Normalizer\FieldItemNormalizer
*
* @group Drupal
* @group HAL
*/
class FieldItemNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalizeExceptionsUnitTestBase {
/**
* @inheritdoc
*/
public static function getInfo() {
return array(
'name' => '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);
}
}
<?php
/**
* @file
* Contains \Drupal\hal\Tests\FieldNormalizerDenormalizeExceptionsUnitTest.
*/
namespace Drupal\hal\Tests;
use Drupal\hal\Normalizer\FieldNormalizer;
/**
* @coversDefaultClass \Drupal\hal\Normalizer\FieldNormalizer
*
* @group Drupal
* @group HAL
*/
class FieldNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalizeExceptionsUnitTestBase {
/**
* @inheritdoc
*/
public static function getInfo() {
return array(
'name' => '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);
}
}
<?php
/**
* @file
* Contains \Drupal\hal\Tests\NormalizerDenormalizeExceptionsUnitTestBase.
*/
namespace Drupal\hal\Tests;
use Drupal\Tests\UnitTestCase;
/**
* Common ancestor for FieldItemNormalizerDenormalizeExceptionsUnitTest and
* FieldNormalizerDenormalizeExceptionsUnitTest as they have the same
* dataProvider.
*/
abstract class NormalizerDenormalizeExceptionsUnitTestBase extends UnitTestCase {
/**
* Provides data for FieldItemNormalizerDenormalizeExceptionsUnitTest::testFieldItemNormalizerDenormalizeExceptions()
* and for FieldNormalizerDenormalizeExceptionsUnitTest::testFieldNormalizerDenormalizeExceptions().
*
* @return array Test data.
*/
public function providerNormalizerDenormalizeExceptions() {
$mock = $this->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)),
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment