summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-03-26 22:55:17 (GMT)
committerAlex Pott2014-03-26 22:55:17 (GMT)
commit5a0edc309e4a1bbd190dcba16434963364258100 (patch)
treef82ea2c75b33f3582d888129937547202f3fc36a
parent1ad4630ad63c86d9b4be22eb86ea1fd60441fe15 (diff)
Issue #2225333 by Boobaa: LogicException in Drupal\hal\Normalizer\FieldItemNormalizer does not exist.
-rw-r--r--core/modules/hal/lib/Drupal/hal/Normalizer/FieldItemNormalizer.php5
-rw-r--r--core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php6
-rw-r--r--core/modules/hal/tests/Drupal/hal/Tests/FieldItemNormalizerDenormalizeExceptionsUnitTest.php47
-rw-r--r--core/modules/hal/tests/Drupal/hal/Tests/FieldNormalizerDenormalizeExceptionsUnitTest.php47
-rw-r--r--core/modules/hal/tests/Drupal/hal/Tests/NormalizerDenormalizeExceptionsUnitTestBase.php36
5 files changed, 136 insertions, 5 deletions
diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldItemNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldItemNormalizer.php
index bee3930..a427fee 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 @@ class FieldItemNormalizer extends NormalizerBase {
*/
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 2648998..99a669c 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 @@ class FieldNormalizer extends NormalizerBase {
*/
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 0000000..dc73cbd
--- /dev/null
+++ b/core/modules/hal/tests/Drupal/hal/Tests/FieldItemNormalizerDenormalizeExceptionsUnitTest.php
@@ -0,0 +1,47 @@
+<?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);
+ }
+
+}
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 0000000..c39ffa0
--- /dev/null
+++ b/core/modules/hal/tests/Drupal/hal/Tests/FieldNormalizerDenormalizeExceptionsUnitTest.php
@@ -0,0 +1,47 @@
+<?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);
+ }
+
+}
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 0000000..f16b223
--- /dev/null
+++ b/core/modules/hal/tests/Drupal/hal/Tests/NormalizerDenormalizeExceptionsUnitTestBase.php
@@ -0,0 +1,36 @@
+<?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)),
+ );
+ }
+
+}