Commit 95481848 authored by alexpott's avatar alexpott

Issue #2533776 by nicolas.rafaelli, lluvigne, dagmar: Instead of mocking...

Issue #2533776 by nicolas.rafaelli, lluvigne, dagmar: Instead of mocking TypedDataManager, use TypedDataManagerInterface in tests
parent 92339463
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\serialization\Unit\Normalizer;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\serialization\Normalizer\ListNormalizer;
use Drupal\Core\TypedData\Plugin\DataType\ItemList;
......@@ -37,10 +38,7 @@ class ListNormalizerTest extends UnitTestCase {
protected function setUp() {
// Mock the TypedDataManager to return a TypedDataInterface mock.
$typed_data = $this->getMock('Drupal\Core\TypedData\TypedDataInterface');
$typed_data_manager = $this->getMockBuilder('Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->setMethods(array('getPropertyInstance'))
->getMock();
$typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
$typed_data_manager->expects($this->any())
->method('getPropertyInstance')
->will($this->returnValue($typed_data));
......
......@@ -18,6 +18,7 @@
use Drupal\Core\Field\Plugin\Field\FieldType\StringItem;
use Drupal\Core\Field\Plugin\Field\FieldType\UriItem;
use Drupal\Core\Field\Plugin\Field\FieldType\UuidItem;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\text\Plugin\Field\FieldType\TextLongItem;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestMul;
......@@ -83,9 +84,7 @@ protected function setUp() {
->getMock();
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$typed_data_manager = $this->getMockBuilder('Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
$typed_data_manager->expects($this->any())
->method('createDataDefinition')
->willReturn($this->getMock('Drupal\Core\TypedData\DataDefinitionInterface'));
......
......@@ -7,6 +7,7 @@
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Language\Language;
......@@ -130,9 +131,7 @@ protected function setUp() {
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$this->typedDataManager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$this->typedDataManager = $this->getMock(TypedDataManagerInterface::class);
$this->typedDataManager->expects($this->any())
->method('getDefinition')
->with('entity')
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Language\Language;
......@@ -136,9 +137,7 @@ protected function setUp() {
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$this->typedDataManager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$this->typedDataManager = $this->getMock(TypedDataManagerInterface::class);
$this->typedDataManager->expects($this->any())
->method('getDefinition')
->with('entity')
......
......@@ -5,6 +5,7 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldTypePluginManager;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
......@@ -35,9 +36,7 @@ protected function setUp() {
->method('moduleExists')
->with($module_name)
->will($this->returnValue(TRUE));
$typed_data_manager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
$plugin_manager = new FieldTypePluginManager(
$namespaces,
$this->getMock('Drupal\Core\Cache\CacheBackendInterface'),
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\Core\Plugin\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
......@@ -61,10 +62,7 @@ public function testGetDataDefinition($is_multiple) {
if ($is_multiple) {
$create_definition_method = 'createListDataDefinition';
}
$mock_data_manager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->setMethods(array($create_definition_method))
->getMock();
$mock_data_manager = $this->getMock(TypedDataManagerInterface::class);
// Our mocked data manager will return our mocked data definition for a
// valid data type.
$mock_data_manager->expects($this->once())
......@@ -127,10 +125,7 @@ public function testGetDataDefinitionInvalidType($is_multiple) {
if ($is_multiple) {
$create_definition_method = 'createListDataDefinition';
}
$mock_data_manager = $this->getMockBuilder('\Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->setMethods(array($create_definition_method))
->getMock();
$mock_data_manager = $this->getMock(TypedDataManagerInterface::class);
// Our mocked data manager will return NULL for a non-valid data type. This
// will eventually cause getDataDefinition() to throw an exception.
$mock_data_manager->expects($this->once())
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\Container;
......@@ -46,10 +47,7 @@ class ContextTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
$this->typedDataManager = $this->getMockBuilder('Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->setMethods(array('create'))
->getMock();
$this->typedDataManager = $this->getMock(TypedDataManagerInterface::class);
}
/**
......
......@@ -7,6 +7,7 @@
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\Plugin\DataType\StringData;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
......@@ -34,9 +35,7 @@ class ContextTypedDataTest extends UnitTestCase {
*/
public function testGetContextValue() {
// Prepare a container that holds the typed data manager mock.
$typed_data_manager = $this->getMockBuilder('Drupal\Core\TypedData\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
$typed_data_manager->expects($this->once())
->method('getCanonicalRepresentation')
->will($this->returnCallback(array($this, 'getCanonicalRepresentation')));
......
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