Issue #2533776 by nicolas.rafaelli, lluvigne, dagmar: Instead of mocking TypedDataManager, use TypedDataManagerInterface in tests

8.2.x
Alex Pott 2016-05-27 15:17:52 +01:00
parent 9233946397
commit 95481848dc
8 changed files with 17 additions and 31 deletions

View File

@ -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));

View File

@ -18,6 +18,7 @@ use Drupal\Core\Field\Plugin\Field\FieldType\LanguageItem;
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 @@ class EntityViewsDataTest extends UnitTestCase {
->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'));

View File

@ -7,6 +7,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder;
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 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
$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')

View File

@ -6,6 +6,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder;
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 @@ class EntityAdapterUnitTest extends UnitTestCase {
$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')

View File

@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\Field;
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 @@ abstract class BaseFieldDefinitionTestBase extends UnitTestCase {
->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'),

View File

@ -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 @@ class ContextDefinitionTest extends UnitTestCase {
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 @@ class ContextDefinitionTest extends UnitTestCase {
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())

View File

@ -10,6 +10,7 @@ namespace Drupal\Tests\Core\Plugin\Context;
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);
}
/**

View File

@ -7,6 +7,7 @@ use Drupal\Core\Plugin\Context\Context;
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')));