Commit 00b7574f authored by catch's avatar catch
Browse files

Issue #3210898 by quietone, BhumikaVarshney: Combine tests using...

Issue #3210898 by quietone, BhumikaVarshney: Combine tests using NormalizerDenormalizeExceptionsUnitTestBase
parent caac9c9f
......@@ -3,19 +3,36 @@
namespace Drupal\Tests\hal\Unit;
use Drupal\hal\Normalizer\FieldItemNormalizer;
use Drupal\hal\Normalizer\FieldNormalizer;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @coversDefaultClass \Drupal\hal\Normalizer\FieldItemNormalizer
* Tests the exceptions thrown by FieldNormalizer and FieldItemNormalizer.
*
* @group hal
*/
class FieldItemNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalizeExceptionsUnitTestBase {
class FieldNormalizerDenormalizeExceptionsTest extends UnitTestCase {
/**
* Tests that the FieldNormalizer::denormalize() throws proper exceptions.
*
* @covers \Drupal\hal\Normalizer\FieldNormalizer
*
* @dataProvider providerNormalizerDenormalizeExceptions
*/
public function testFieldNormalizerDenormalizeExceptions($context) {
$field_item_normalizer = new FieldNormalizer();
$data = [];
$class = [];
$this->expectException(InvalidArgumentException::class);
$field_item_normalizer->denormalize($data, $class, NULL, $context);
}
/**
* Tests that the FieldItemNormalizer::denormalize() throws proper exceptions.
*
* @param array $context
* Context for FieldItemNormalizer::denormalize().
* @covers \Drupal\hal\Normalizer\FieldItemNormalizer
*
* @dataProvider providerNormalizerDenormalizeExceptions
*/
......@@ -27,4 +44,23 @@ public function testFieldItemNormalizerDenormalizeExceptions($context) {
$field_item_normalizer->denormalize($data, $class, NULL, $context);
}
/**
* Provides data for field normalization tests.
*
* @return array
* The context of the normalizer.
*/
public function providerNormalizerDenormalizeExceptions() {
$mock = $this->getMockBuilder('\Drupal\Core\Field\Plugin\DataType\FieldItem')
->setMethods(['getParent'])
->getMock();
$mock->expects($this->any())
->method('getParent')
->will($this->returnValue(NULL));
return [
[[]],
[['target_instance' => $mock]],
];
}
}
<?php
namespace Drupal\Tests\hal\Unit;
use Drupal\hal\Normalizer\FieldNormalizer;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @coversDefaultClass \Drupal\hal\Normalizer\FieldNormalizer
* @group hal
*/
class FieldNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalizeExceptionsUnitTestBase {
/**
* Tests that the FieldNormalizer::denormalize() throws proper exceptions.
*
* @param array $context
* Context for FieldNormalizer::denormalize().
*
* @dataProvider providerNormalizerDenormalizeExceptions
*/
public function testFieldNormalizerDenormalizeExceptions($context) {
$field_item_normalizer = new FieldNormalizer();
$data = [];
$class = [];
$this->expectException(InvalidArgumentException::class);
$field_item_normalizer->denormalize($data, $class, NULL, $context);
}
}
<?php
namespace Drupal\Tests\hal\Unit;
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->getMockBuilder('\Drupal\Core\Field\Plugin\DataType\FieldItem')
->setMethods(['getParent'])
->getMock();
$mock->expects($this->any())
->method('getParent')
->will($this->returnValue(NULL));
return [
[[]],
[['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