diff --git a/core/lib/Drupal/Core/Config/CachedStorage.php b/core/lib/Drupal/Core/Config/CachedStorage.php index c42e013..ef74fbf 100644 --- a/core/lib/Drupal/Core/Config/CachedStorage.php +++ b/core/lib/Drupal/Core/Config/CachedStorage.php @@ -17,7 +17,7 @@ * the cache and delegates the read to the storage on a cache miss. It also * handles cache invalidation. */ -class CachedStorage implements StorageInterface, StorageCacheInterface { +class CachedStorage implements StorageInterface, StorageCacheInterface, \Serializable { use DependencySerializationTrait; /** diff --git a/core/lib/Drupal/Core/Config/ConfigBase.php b/core/lib/Drupal/Core/Config/ConfigBase.php index 77460f9..36ea8a4 100644 --- a/core/lib/Drupal/Core/Config/ConfigBase.php +++ b/core/lib/Drupal/Core/Config/ConfigBase.php @@ -29,7 +29,7 @@ * @see \Drupal\Core\Config\Config * @see \Drupal\Core\Theme\ThemeSettings */ -abstract class ConfigBase implements RefinableCacheableDependencyInterface { +abstract class ConfigBase implements CacheableDependencyInterface, \Serializable { use DependencySerializationTrait; use RefinableCacheableDependencyTrait; diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index 20ae266..0ebb047 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -38,7 +38,7 @@ * * @see \Drupal\Core\Config\ConfigImporterEvent */ -class ConfigImporter { +class ConfigImporter implements \Serializable { use StringTranslationTrait; use DependencySerializationTrait; diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index 70096a0..fb88522 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -15,7 +15,7 @@ /** * Defines the Database storage. */ -class DatabaseStorage implements StorageInterface { +class DatabaseStorage implements StorageInterface, \Serializable { use DependencySerializationTrait; /** diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 4d0c0e3..421fc52 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -644,4 +644,36 @@ public function save() { return $return; } + /** + * {@inheritdoc} + */ + public function serialize() { + if ($this->getEntityType()->get('config_export')) { + $data = [ + 'entity_type_id' => $this->getEntityTypeId(), + 'is_new' => $this->isNew(), + 'values' => $this->toArray(), + ]; + return serialize(['_config_entity_serialize' => $data]); + } + else { + return parent::serialize(); + } + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) { + if (strpos($serialized, '"_config_entity_serialize"') !== FALSE ) { + $unserialized = unserialize($serialized); + $data = $unserialized['_config_entity_serialize']; + $this->__construct($data['values'], $data['entity_type_id']); + $this->enforceIsNew($data['is_new']); + } + else { + parent::unserialize($serialized); + } + } + } diff --git a/core/lib/Drupal/Core/Config/StorageComparer.php b/core/lib/Drupal/Core/Config/StorageComparer.php index a3fa7ee4..3f7b10a 100644 --- a/core/lib/Drupal/Core/Config/StorageComparer.php +++ b/core/lib/Drupal/Core/Config/StorageComparer.php @@ -14,7 +14,7 @@ /** * Defines a config storage comparer. */ -class StorageComparer implements StorageComparerInterface { +class StorageComparer implements StorageComparerInterface, \Serializable { use DependencySerializationTrait; /** diff --git a/core/lib/Drupal/Core/Controller/FormController.php b/core/lib/Drupal/Core/Controller/FormController.php index 6a9b9d5..a684900 100644 --- a/core/lib/Drupal/Core/Controller/FormController.php +++ b/core/lib/Drupal/Core/Controller/FormController.php @@ -18,7 +18,7 @@ * * @todo Make this a trait in PHP 5.4. */ -abstract class FormController { +abstract class FormController implements \Serializable { use DependencySerializationTrait; /** diff --git a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php index a7ab694..5e5141d 100644 --- a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php +++ b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php @@ -15,49 +15,46 @@ trait DependencySerializationTrait { /** - * An array of service IDs keyed by property name used for serialization. - * - * @var array - */ - protected $_serviceIds = array(); - - /** * {@inheritdoc} */ - public function __sleep() { - $this->_serviceIds = array(); - $vars = get_object_vars($this); - foreach ($vars as $key => $value) { + public function serialize() { + $serviceIds = []; + $data = get_object_vars($this); + foreach ($data as $key => $value) { if (is_object($value) && isset($value->_serviceId)) { // If a class member was instantiated by the dependency injection // container, only store its ID so it can be used to get a fresh object // on unserialization. - $this->_serviceIds[$key] = $value->_serviceId; - unset($vars[$key]); + $serviceIds[$key] = $value->_serviceId; + $data[$key] = null; } // Special case the container, which might not have a service ID. elseif ($value instanceof ContainerInterface) { - $this->_serviceIds[$key] = 'service_container'; - unset($vars[$key]); + $serviceIds[$key] = 'service_container'; + $data[$key] = null; } } - return array_keys($vars); + return serialize([ + 'data' => $data, + 'service_ids' => $serviceIds, + ]); } /** * {@inheritdoc} */ - public function __wakeup() { - // Tests in isolation potentially unserialize in the parent process. - if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP']) && !\Drupal::hasContainer()) { - return; - } - $container = \Drupal::getContainer(); - foreach ($this->_serviceIds as $key => $service_id) { - $this->$key = $container->get($service_id); + public function unserialize($serialized) { + $unserialized = unserialize($serialized); + // PHPUnit uses unserialize() on a made up string as a trick when bypassing + // the contructor on mock object creation. Make sure we only run on objects + // that have been serialized through our serialize() method. + if (is_array($unserialized)) { + $container = \Drupal::getContainer(); + foreach ($unserialized['data'] as $key => $value) { + $this->$key = isset($unserialized['service_ids'][$key]) ? $container->get($unserialized['service_ids'][$key]) : $value; + } } - $this->_serviceIds = array(); } } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index b49f3d4..f645fa9 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -22,12 +22,12 @@ /** * Defines a base entity class. */ -abstract class Entity implements EntityInterface { +abstract class Entity implements EntityInterface, \Serializable { use RefinableCacheableDependencyTrait; use DependencySerializationTrait { - __sleep as traitSleep; + serialize as traitSerialize; } /** @@ -601,9 +601,9 @@ public function getTypedData() { /** * {@inheritdoc} */ - public function __sleep() { + public function serialize() { $this->typedData = NULL; - return $this->traitSleep(); + return $this->traitSerialize(); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityHandlerBase.php b/core/lib/Drupal/Core/Entity/EntityHandlerBase.php index ef9eb34..4caa03d 100644 --- a/core/lib/Drupal/Core/Entity/EntityHandlerBase.php +++ b/core/lib/Drupal/Core/Entity/EntityHandlerBase.php @@ -21,7 +21,7 @@ * * @ingroup entity_api */ -abstract class EntityHandlerBase { +abstract class EntityHandlerBase implements \Serializable { use StringTranslationTrait; use DependencySerializationTrait; diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php index 5c2d2af..77e7da3 100644 --- a/core/lib/Drupal/Core/Form/FormBase.php +++ b/core/lib/Drupal/Core/Form/FormBase.php @@ -22,7 +22,7 @@ * * @ingroup form_api */ -abstract class FormBase implements FormInterface, ContainerInjectionInterface { +abstract class FormBase implements FormInterface, ContainerInjectionInterface, \Serializable { use DependencySerializationTrait; use LinkGeneratorTrait; diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php index aaa9114..a98cbac 100644 --- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php +++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php @@ -18,7 +18,7 @@ * This is Drupal's default key/value store implementation. It uses the database * to store key/value data. */ -class DatabaseStorage extends StorageBase { +class DatabaseStorage extends StorageBase implements \Serializable { use DependencySerializationTrait; diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index 4f19f8a..18f37f9 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -14,7 +14,7 @@ /** * Class responsible for providing language support on language-unaware sites. */ -class LanguageManager implements LanguageManagerInterface { +class LanguageManager implements LanguageManagerInterface, \Serializable { use DependencySerializationTrait; /** diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php index 219dd37..5d44e8b 100644 --- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php +++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php @@ -22,7 +22,7 @@ /** * Base class for plugins that are context aware. */ -abstract class ContextAwarePluginBase extends ComponentContextAwarePluginBase implements ContextAwarePluginInterface { +abstract class ContextAwarePluginBase extends ComponentContextAwarePluginBase implements ContextAwarePluginInterface, \Serializable { use TypedDataTrait; use StringTranslationTrait; use DependencySerializationTrait; diff --git a/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php b/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php index 61702a0..ada5928 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php +++ b/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php @@ -21,7 +21,7 @@ * the configuration key containing the plugin ID is specified by * self::$pluginKey. */ -class DefaultLazyPluginCollection extends LazyPluginCollection { +class DefaultLazyPluginCollection extends LazyPluginCollection implements \Serializable { use DependencySerializationTrait; /** diff --git a/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php b/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php index 298f94d..6f16a19 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php +++ b/core/lib/Drupal/Core/Plugin/DefaultSingleLazyPluginCollection.php @@ -21,7 +21,7 @@ * class can be used directly, or subclassed to add further exception handling * in self::initializePlugin(). */ -class DefaultSingleLazyPluginCollection extends LazyPluginCollection { +class DefaultSingleLazyPluginCollection extends LazyPluginCollection implements \Serializable { use DependencySerializationTrait; /** diff --git a/core/lib/Drupal/Core/Plugin/PluginBase.php b/core/lib/Drupal/Core/Plugin/PluginBase.php index 513d2aa..d32d3fe 100644 --- a/core/lib/Drupal/Core/Plugin/PluginBase.php +++ b/core/lib/Drupal/Core/Plugin/PluginBase.php @@ -16,7 +16,7 @@ * * @ingroup plugin_api */ -abstract class PluginBase extends ComponentPluginBase { +abstract class PluginBase extends ComponentPluginBase implements \Serializable { use StringTranslationTrait; use DependencySerializationTrait; diff --git a/core/lib/Drupal/Core/Session/SessionHandler.php b/core/lib/Drupal/Core/Session/SessionHandler.php index 658a6a7..7a41bde 100644 --- a/core/lib/Drupal/Core/Session/SessionHandler.php +++ b/core/lib/Drupal/Core/Session/SessionHandler.php @@ -17,7 +17,7 @@ /** * Default session handler. */ -class SessionHandler extends AbstractProxy implements \SessionHandlerInterface { +class SessionHandler extends AbstractProxy implements \SessionHandlerInterface, \Serializable { use DependencySerializationTrait; diff --git a/core/lib/Drupal/Core/Session/SessionManager.php b/core/lib/Drupal/Core/Session/SessionManager.php index 7a2e23d..0aaa00d 100644 --- a/core/lib/Drupal/Core/Session/SessionManager.php +++ b/core/lib/Drupal/Core/Session/SessionManager.php @@ -30,7 +30,7 @@ * here needs to be extracted either into a dedicated session handler proxy * (e.g. sid-hashing) or relocated to the authentication subsystem. */ -class SessionManager extends NativeSessionStorage implements SessionManagerInterface { +class SessionManager extends NativeSessionStorage implements SessionManagerInterface, \Serializable { use DependencySerializationTrait; diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 34b4cea..ee3804f 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -19,7 +19,7 @@ /** * Defines an object that holds information about a URL. */ -class Url { +class Url implements \Serializable { use DependencySerializationTrait; /** diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index 94505be..be2d965 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -27,7 +27,7 @@ * * @ingroup entity_api */ -class ContentTranslationHandler implements ContentTranslationHandlerInterface, EntityHandlerInterface { +class ContentTranslationHandler implements ContentTranslationHandlerInterface, EntityHandlerInterface, \Serializable { use DependencySerializationTrait; /** diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index a2117f8..f2c7467 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -705,21 +705,6 @@ public function hasData() { } /** - * Implements the magic __sleep() method. - * - * Using the Serialize interface and serialize() / unserialize() methods - * breaks entity forms in PHP 5.4. - * @todo Investigate in https://www.drupal.org/node/2074253. - */ - public function __sleep() { - // Only serialize necessary properties, excluding those that can be - // recalculated. - $properties = get_object_vars($this); - unset($properties['schema'], $properties['propertyDefinitions'], $properties['original']); - return array_keys($properties); - } - - /** * {@inheritdoc} */ public function getConstraints() { diff --git a/core/modules/forum/src/ForumManager.php b/core/modules/forum/src/ForumManager.php index 6545da1..0464ed3 100644 --- a/core/modules/forum/src/ForumManager.php +++ b/core/modules/forum/src/ForumManager.php @@ -20,11 +20,10 @@ /** * Provides forum manager service. */ -class ForumManager implements ForumManagerInterface { +class ForumManager implements ForumManagerInterface, \Serializable { use StringTranslationTrait; use DependencySerializationTrait { - __wakeup as defaultWakeup; - __sleep as defaultSleep; + serialize as traitSerialize; } /** @@ -498,24 +497,10 @@ public function unreadTopics($term, $uid) { /** * {@inheritdoc} */ - public function __sleep() { - $vars = $this->defaultSleep(); + public function serialize() { // Do not serialize static cache. - unset($vars['history'], $vars['index'], $vars['lastPostData'], $vars['forumChildren'], $vars['forumStatistics']); - return $vars; - } - - /** - * {@inheritdoc} - */ - public function __wakeup() { - $this->defaultWakeup(); - // Initialize static cache. - $this->history = array(); - $this->lastPostData = array(); - $this->forumChildren = array(); - $this->forumStatistics = array(); - $this->index = NULL; + unset($this->history, $this->index, $this->lastPostData, $this->forumChildren, $this->forumStatistics); + return $this->traitSerialize(); } } diff --git a/core/modules/migrate/src/Plugin/migrate/process/Migration.php b/core/modules/migrate/src/Plugin/migrate/process/Migration.php index 7dd850a..b57b260 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/Migration.php +++ b/core/modules/migrate/src/Plugin/migrate/process/Migration.php @@ -11,6 +11,7 @@ use Drupal\migrate\MigrateSkipProcessException; use Drupal\migrate\Plugin\MigratePluginManager; use Drupal\migrate\Plugin\MigrationPluginManagerInterface; +use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\MigrateExecutableInterface; @@ -139,7 +140,11 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $destination_ids = $destination_plugin->import($stub_row); } catch (\Exception $e) { - $migrate_executable->saveMessage($e->getMessage()); + $migration->getIdMap()->saveMessage($stub_row->getSourceIdValues(), $e->getMessage()); + } + + if ($destination_ids) { + $migration->getIdMap()->saveIdMapping($stub_row, $destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE); } } if ($destination_ids) { diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php index 1787210..0f7ebe0 100644 --- a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php @@ -67,6 +67,7 @@ public function testTransformWithStubbing() { $migration_plugin_manager->createInstances(['destination_migration']) ->willReturn(['destination_migration' => $destination_migration->reveal()]); $destination_id_map->lookupDestinationId([1])->willReturn(NULL); + $destination_id_map->saveIdMapping(Argument::any(), Argument::any(), MigrateIdMapInterface::STATUS_NEEDS_UPDATE)->willReturn(NULL); $configuration = [ 'no_stub' => FALSE, diff --git a/core/modules/taxonomy/src/Tests/Migrate/MigrateTaxonomyTermStubTest.php b/core/modules/taxonomy/src/Tests/Migrate/MigrateTaxonomyTermStubTest.php index c3fbd35..85ac634 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/MigrateTaxonomyTermStubTest.php +++ b/core/modules/taxonomy/src/Tests/Migrate/MigrateTaxonomyTermStubTest.php @@ -75,8 +75,11 @@ public function testStubWithWeightMapping() { // We have a term referencing an unmigrated parent, forcing a stub to be // created. - $term_executable = new MigrateExecutable($this->getMigration('taxonomy_term_stub_test'), $this); + $migration = $this->getMigration('taxonomy_term_stub_test'); + $term_executable = new MigrateExecutable($migration, $this); $term_executable->import(); + $this->assertTrue($migration->getIdMap()->getRowBySource(['2']), 'Stub row exists in the ID map table'); + // Load the referenced term, which should exist as a stub. /** @var \Drupal\Core\Entity\ContentEntityBase $stub_entity */ $stub_entity = Term::load(2); diff --git a/core/modules/tour/tests/src/Unit/Entity/TourTest.php b/core/modules/tour/tests/src/Unit/Entity/TourTest.php index a6625c8..93526e9 100644 --- a/core/modules/tour/tests/src/Unit/Entity/TourTest.php +++ b/core/modules/tour/tests/src/Unit/Entity/TourTest.php @@ -6,6 +6,7 @@ namespace Drupal\Tests\tour\Unit\Entity; +use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Tests\UnitTestCase; /** @@ -31,8 +32,17 @@ class TourTest extends UnitTestCase { * @dataProvider routeProvider */ public function testHasMatchingRoute($routes, $route_name, $route_params, $result) { - $tour = $this->getMockBuilder('\Drupal\tour\Entity\Tour') + // Tour::__construct() pulls the plugin.manager.tour.tip service from the + // container. Mock it and and place it there. + $tip_manager = $this->getMockBuilder('Drupal\tour\TipPluginManager') ->disableOriginalConstructor() + ->getMock(); + $container = new ContainerBuilder(); + $container->set('plugin.manager.tour.tip', $tip_manager); + \Drupal::setContainer($container); + + $tour = $this->getMockBuilder('\Drupal\tour\Entity\Tour') + ->setConstructorArgs(array(array(), 'tour')) ->setMethods(array('getRoutes')) ->getMock(); diff --git a/core/modules/update/src/UpdateFetcher.php b/core/modules/update/src/UpdateFetcher.php index 118d3a9..538538e 100644 --- a/core/modules/update/src/UpdateFetcher.php +++ b/core/modules/update/src/UpdateFetcher.php @@ -15,7 +15,7 @@ /** * Fetches project information from remote locations. */ -class UpdateFetcher implements UpdateFetcherInterface { +class UpdateFetcher implements UpdateFetcherInterface, \Serializable { use DependencySerializationTrait; diff --git a/core/modules/update/src/UpdateManager.php b/core/modules/update/src/UpdateManager.php index 007b040..489c23d 100644 --- a/core/modules/update/src/UpdateManager.php +++ b/core/modules/update/src/UpdateManager.php @@ -18,7 +18,7 @@ /** * Default implementation of UpdateManagerInterface. */ -class UpdateManager implements UpdateManagerInterface { +class UpdateManager implements UpdateManagerInterface, \Serializable { use DependencySerializationTrait; use StringTranslationTrait; diff --git a/core/modules/views/src/Form/ViewsForm.php b/core/modules/views/src/Form/ViewsForm.php index fe27c8c..c0744f1 100644 --- a/core/modules/views/src/Form/ViewsForm.php +++ b/core/modules/views/src/Form/ViewsForm.php @@ -27,7 +27,7 @@ * default is \Drupal\views\Form\ViewsFormMainForm). That way it is actually * possible for modules to have a multistep form if they need to. */ -class ViewsForm implements FormInterface, ContainerInjectionInterface { +class ViewsForm implements FormInterface, ContainerInjectionInterface, \Serializable { use DependencySerializationTrait; /** diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index a9648d9..84f7ec0 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -25,7 +25,6 @@ * functions to build the view query, execute the query and render the output. */ class ViewExecutable implements \Serializable { - use DependencySerializationTrait; /** * The config entity in which the view is stored. diff --git a/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php b/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php index c6d7726..a7bcd06 100644 --- a/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php +++ b/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php @@ -120,6 +120,12 @@ public function testIsLocked() { public function testSerialization() { // Set a container so the DependencySerializationTrait has it. $container = new ContainerBuilder(); + $entity_type = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityTypeInterface'); + $entity_manager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $entity_manager->expects($this->any()) + ->method('getDefinition') + ->will($this->returnValue($entity_type)); + $container->set('entity.manager', $entity_manager); \Drupal::setContainer($container); $storage = new View([], 'view'); diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php index 6b84d40..513b951 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php @@ -20,8 +20,8 @@ class DependencySerializationTest extends UnitTestCase { /** - * @covers ::__sleep - * @covers ::__wakeup + * @covers ::serialize + * @covers ::unserialize */ public function testSerialization() { // Create a pseudo service and dependency injected object. @@ -41,7 +41,6 @@ public function testSerialization() { $this->assertSame($service, $dependencySerialization->service); $this->assertSame($container, $dependencySerialization->container); - $this->assertEmpty($dependencySerialization->getServiceIds()); } } @@ -49,7 +48,7 @@ public function testSerialization() { /** * Defines a test class which has a single service as dependency. */ -class DependencySerializationTestDummy implements ContainerAwareInterface { +class DependencySerializationTestDummy implements ContainerAwareInterface, \Serializable { use DependencySerializationTrait; @@ -83,11 +82,4 @@ public function __construct(\stdClass $service) { public function setContainer(ContainerInterface $container = NULL) { $this->container = $container; } - - /** - * Gets the stored service IDs. - */ - public function getServiceIds() { - return $this->_serviceIds; - } }