Skip to content
Snippets Groups Projects
Commit f0337421 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

Issue #2208115 by Xano, damiankloip, Crell: Add DependencySerializationTrait.

parent 505a062e
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Showing
with 79 additions and 169 deletions
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use \Drupal\Core\DependencyInjection\DependencySerialization; use \Drupal\Core\DependencyInjection\DependencySerializationTrait;
/** /**
* Provides a base class for configuration objects with get/set support. * Provides a base class for configuration objects with get/set support.
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
* @see \Drupal\Core\Config\Config * @see \Drupal\Core\Config\Config
* @see \Drupal\Core\Theme\ThemeSettings * @see \Drupal\Core\Theme\ThemeSettings
*/ */
abstract class ConfigBase extends DependencySerialization { abstract class ConfigBase {
use DependencySerializationTrait;
/** /**
* The name of the configuration object. * The name of the configuration object.
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Core\Config\Entity\ImportableEntityStorageInterface; use Drupal\Core\Config\Entity\ImportableEntityStorageInterface;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
...@@ -37,8 +37,9 @@ ...@@ -37,8 +37,9 @@
* *
* @see \Drupal\Core\Config\ConfigImporterEvent * @see \Drupal\Core\Config\ConfigImporterEvent
*/ */
class ConfigImporter extends DependencySerialization { class ConfigImporter {
use StringTranslationTrait; use StringTranslationTrait;
use DependencySerializationTrait;
/** /**
* The name used to identify the lock. * The name used to identify the lock.
......
...@@ -9,12 +9,13 @@ ...@@ -9,12 +9,13 @@
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Core\Config\Entity\ConfigDependencyManager; use Drupal\Core\Config\Entity\ConfigDependencyManager;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
/** /**
* Defines a config storage comparer. * Defines a config storage comparer.
*/ */
class StorageComparer extends DependencySerialization implements StorageComparerInterface { class StorageComparer implements StorageComparerInterface {
use DependencySerializationTrait;
/** /**
* The source storage used to discover configuration changes. * The source storage used to discover configuration changes.
......
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
namespace Drupal\Core\Controller; namespace Drupal\Core\Controller;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Controller\ControllerResolverInterface;
use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
...@@ -17,8 +16,8 @@ ...@@ -17,8 +16,8 @@
* *
* @todo Make this a trait in PHP 5.4. * @todo Make this a trait in PHP 5.4.
*/ */
abstract class FormController extends DependencySerialization { abstract class FormController {
use DependencySerializationTrait;
/** /**
* The form definition. The format may vary depending on the child class. * The form definition. The format may vary depending on the child class.
* *
......
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
/** /**
* @file * @file
* Contains \Drupal\Core\DependencyInjection\DependencySerialization. * Contains \Drupal\Core\DependencyInjection\DependencySerializationTrait.
*/ */
namespace Drupal\Core\DependencyInjection; namespace Drupal\Core\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Provides a dependency injection friendly methods for serialization. * Provides dependency injection friendly methods for serialization.
*/ */
abstract class DependencySerialization { trait DependencySerializationTrait {
/** /**
* An array of service IDs keyed by property name used for serialization. * An array of service IDs keyed by property name used for serialization.
...@@ -52,7 +53,7 @@ public function __wakeup() { ...@@ -52,7 +53,7 @@ public function __wakeup() {
foreach ($this->_serviceIds as $key => $service_id) { foreach ($this->_serviceIds as $key => $service_id) {
$this->$key = $container->get($service_id); $this->$key = $container->get($service_id);
} }
unset($this->_serviceIds); $this->_serviceIds = array();
} }
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\Core\Entity; namespace Drupal\Core\Entity;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
/** /**
* Defines a base entity class. * Defines a base entity class.
*/ */
abstract class Entity extends DependencySerialization implements EntityInterface { abstract class Entity implements EntityInterface {
use DependencySerializationTrait;
/** /**
* The entity type. * The entity type.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\Core\Entity; namespace Drupal\Core\Entity;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
* *
* @todo Convert this to a trait. * @todo Convert this to a trait.
*/ */
abstract class EntityControllerBase extends DependencySerialization { abstract class EntityControllerBase {
use StringTranslationTrait; use StringTranslationTrait;
use DependencySerializationTrait;
/** /**
* The module handler to invoke hooks on. * The module handler to invoke hooks on.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
/** /**
* Provides a base class for forms. * Provides a base class for forms.
*/ */
abstract class FormBase extends DependencySerialization implements FormInterface, ContainerInjectionInterface { abstract class FormBase implements FormInterface, ContainerInjectionInterface {
use StringTranslationTrait; use StringTranslationTrait;
use DependencySerializationTrait;
/** /**
* The current request. * The current request.
...@@ -38,14 +39,14 @@ abstract class FormBase extends DependencySerialization implements FormInterface ...@@ -38,14 +39,14 @@ abstract class FormBase extends DependencySerialization implements FormInterface
/** /**
* The config factory. * The config factory.
* *
* This is marked private in order to force subclasses to use the * Subclasses should use the self::config() method, which may be overridden to
* self::config() method, which may be overridden to address specific needs * address specific needs when loading config, rather than this property
* when loading config. See \Drupal\Core\Form\ConfigFormBase::config() for an * directly. See \Drupal\Core\Form\ConfigFormBase::config() for an example of
* example of this. * this.
* *
* @var \Drupal\Core\Config\ConfigFactoryInterface * @var \Drupal\Core\Config\ConfigFactoryInterface
*/ */
private $configFactory; protected $configFactory;
/** /**
* The form error handler. * The form error handler.
......
...@@ -8,13 +8,14 @@ ...@@ -8,13 +8,14 @@
namespace Drupal\Core\Language; namespace Drupal\Core\Language;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
/** /**
* Class responsible for providing language support on language-unaware sites. * Class responsible for providing language support on language-unaware sites.
*/ */
class LanguageManager extends DependencySerialization implements LanguageManagerInterface { class LanguageManager implements LanguageManagerInterface {
use DependencySerializationTrait;
/** /**
* The string translation service. * The string translation service.
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
namespace Drupal\Core\Plugin; namespace Drupal\Core\Plugin;
use Drupal\Component\Plugin\ContextAwarePluginBase as ComponentContextAwarePluginBase; use Drupal\Component\Plugin\ContextAwarePluginBase as ComponentContextAwarePluginBase;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\Context;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Drupal specific class for plugins that use context. * Drupal specific class for plugins that use context.
...@@ -22,16 +22,7 @@ ...@@ -22,16 +22,7 @@
*/ */
abstract class ContextAwarePluginBase extends ComponentContextAwarePluginBase { abstract class ContextAwarePluginBase extends ComponentContextAwarePluginBase {
use StringTranslationTrait; use StringTranslationTrait;
use DependencySerializationTrait;
/**
* An array of service IDs keyed by property name used for serialization.
*
* @todo Remove when Drupal\Core\DependencyInjection\DependencySerialization
* is converted to a trait in https://drupal.org/node/2208115.
*
* @var array
*/
protected $_serviceIds = array();
/** /**
* Override of \Drupal\Component\Plugin\ContextAwarePluginBase::__construct(). * Override of \Drupal\Component\Plugin\ContextAwarePluginBase::__construct().
...@@ -61,45 +52,4 @@ public function setContextValue($name, $value) { ...@@ -61,45 +52,4 @@ public function setContextValue($name, $value) {
return $this; return $this;
} }
/**
* {@inheritdoc}
*
* @todo Remove when Drupal\Core\DependencyInjection\DependencySerialization
* is converted to a trait in https://drupal.org/node/2208115.
*/
public function __sleep() {
$this->_serviceIds = array();
$vars = get_object_vars($this);
foreach ($vars 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]);
}
// Special case the container, which might not have a service ID.
elseif ($value instanceof ContainerInterface) {
$this->_serviceIds[$key] = 'service_container';
unset($vars[$key]);
}
}
return array_keys($vars);
}
/**
* {@inheritdoc}
*
* @todo Remove when Drupal\Core\DependencyInjection\DependencySerialization
* is converted to a trait in https://drupal.org/node/2208115.
*/
public function __wakeup() {
$container = \Drupal::getContainer();
foreach ($this->_serviceIds as $key => $service_id) {
$this->$key = $container->get($service_id);
}
unset($this->_serviceIds);
}
} }
...@@ -9,63 +9,13 @@ ...@@ -9,63 +9,13 @@
use Drupal\Component\Plugin\PluginBase as ComponentPluginBase; use Drupal\Component\Plugin\PluginBase as ComponentPluginBase;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
/** /**
* Base class for plugins supporting metadata inspection and translation. * Base class for plugins supporting metadata inspection and translation.
*/ */
abstract class PluginBase extends ComponentPluginBase { abstract class PluginBase extends ComponentPluginBase {
use StringTranslationTrait; use StringTranslationTrait;
use DependencySerializationTrait;
/**
* An array of service IDs keyed by property name used for serialization.
*
* @todo Remove when Drupal\Core\DependencyInjection\DependencySerialization
* is converted to a trait.
*
* @var array
*/
protected $_serviceIds = array();
/**
* {@inheritdoc}
*
* @todo Remove when Drupal\Core\DependencyInjection\DependencySerialization
* is converted to a trait.
*/
public function __sleep() {
$this->_serviceIds = array();
$vars = get_object_vars($this);
foreach ($vars 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]);
}
// Special case the container, which might not have a service ID.
elseif ($value instanceof ContainerInterface) {
$this->_serviceIds[$key] = 'service_container';
unset($vars[$key]);
}
}
return array_keys($vars);
}
/**
* {@inheritdoc}
*
* @todo Remove when Drupal\Core\DependencyInjection\DependencySerialization
* is converted to a trait.
*/
public function __wakeup() {
$container = \Drupal::getContainer();
foreach ($this->_serviceIds as $key => $service_id) {
$this->$key = $container->get($service_id);
}
unset($this->_serviceIds);
}
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\Core; namespace Drupal\Core;
use Drupal\Component\Utility\UrlHelper; use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Routing\MatchingRouteNotFoundException; use Drupal\Core\Routing\MatchingRouteNotFoundException;
use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Routing\UrlGeneratorInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface;
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
/** /**
* Defines an object that holds information about a URL. * Defines an object that holds information about a URL.
*/ */
class Url extends DependencySerialization { class Url {
use DependencySerializationTrait;
/** /**
* The URL generator. * The URL generator.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
...@@ -19,8 +19,12 @@ ...@@ -19,8 +19,12 @@
/** /**
* Provides forum manager service. * Provides forum manager service.
*/ */
class ForumManager extends DependencySerialization implements ForumManagerInterface { class ForumManager implements ForumManagerInterface {
use StringTranslationTrait; use StringTranslationTrait;
use DependencySerializationTrait {
__wakeup as defaultWakeup;
__sleep as defaultSleep;
}
/** /**
* Forum sort order, newest first. * Forum sort order, newest first.
...@@ -499,7 +503,7 @@ public function unreadTopics($term, $uid) { ...@@ -499,7 +503,7 @@ public function unreadTopics($term, $uid) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __sleep() { public function __sleep() {
$vars = parent::__sleep(); $vars = $this->defaultSleep();
// Do not serialize static cache. // Do not serialize static cache.
unset($vars['history'], $vars['index'], $vars['lastPostData'], $vars['forumChildren'], $vars['forumStatistics']); unset($vars['history'], $vars['index'], $vars['lastPostData'], $vars['forumChildren'], $vars['forumStatistics']);
return $vars; return $vars;
...@@ -509,7 +513,7 @@ public function __sleep() { ...@@ -509,7 +513,7 @@ public function __sleep() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __wakeup() { public function __wakeup() {
parent::__wakeup(); $this->defaultWakeup();
// Initialize static cache. // Initialize static cache.
$this->history = array(); $this->history = array();
$this->lastPostData = array(); $this->lastPostData = array();
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
use Drupal\Core\Controller\ControllerResolverInterface; use Drupal\Core\Controller\ControllerResolverInterface;
use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormInterface;
use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
* default is \Drupal\views\Form\ViewsFormMainForm). That way it is actually * default is \Drupal\views\Form\ViewsFormMainForm). That way it is actually
* possible for modules to have a multistep form if they need to. * possible for modules to have a multistep form if they need to.
*/ */
class ViewsForm extends DependencySerialization implements FormInterface, ContainerInjectionInterface { class ViewsForm implements FormInterface, ContainerInjectionInterface {
use DependencySerializationTrait;
/** /**
* The class resolver to get the subform form objects. * The class resolver to get the subform form objects.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\views; namespace Drupal\views;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\views\query\QueryPluginBase; use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ViewStorageInterface; use Drupal\views\ViewStorageInterface;
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
* An object to contain all of the data to generate a view, plus the member * An object to contain all of the data to generate a view, plus the member
* functions to build the view query, execute the query and render the output. * functions to build the view query, execute the query and render the output.
*/ */
class ViewExecutable extends DependencySerialization { class ViewExecutable {
use DependencySerializationTrait;
/** /**
* The config entity in which the view is stored. * The config entity in which the view is stored.
......
...@@ -8,15 +8,15 @@ ...@@ -8,15 +8,15 @@
namespace Drupal\Tests\Core\DependencyInjection; namespace Drupal\Tests\Core\DependencyInjection;
use Drupal\Core\DependencyInjection\Container; use Drupal\Core\DependencyInjection\Container;
use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Tests the dependency serialization base class. * Tests the dependency serialization trait.
* *
* @see \Drupal\Core\DependencyInjection\DependencySerialization * @coversDefaultClass \Drupal\Core\DependencyInjection\DependencySerializationTrait
*/ */
class DependencySerializationTest extends UnitTestCase { class DependencySerializationTest extends UnitTestCase {
...@@ -25,14 +25,15 @@ class DependencySerializationTest extends UnitTestCase { ...@@ -25,14 +25,15 @@ class DependencySerializationTest extends UnitTestCase {
*/ */
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'Service dependency serialization', 'name' => '\Drupal\Core\DependencyInjection\DependencySerializationTrait unit test',
'description' => 'Tests the dependency serialization base class.', 'description' => '',
'group' => 'System' 'group' => 'System'
); );
} }
/** /**
* Tests serialization and unserialization. * @covers ::__sleep
* @covers ::__wakeup
*/ */
public function testSerialization() { public function testSerialization() {
// Create a pseudo service and dependency injected object. // Create a pseudo service and dependency injected object.
...@@ -43,26 +44,19 @@ public function testSerialization() { ...@@ -43,26 +44,19 @@ public function testSerialization() {
$container->set('service_container', $container); $container->set('service_container', $container);
\Drupal::setContainer($container); \Drupal::setContainer($container);
$dependencySerialization = new TestClass($service); $dependencySerialization = new DependencySerializationTestDummy($service);
$dependencySerialization->setContainer($container); $dependencySerialization->setContainer($container);
$string = serialize($dependencySerialization); $string = serialize($dependencySerialization);
$object = unserialize($string); $object = unserialize($string);
// The original object got _serviceIds added so removing it to check $string = serialize($dependencySerialization);
// equality. /** @var \Drupal\Tests\Core\DependencyInjection\DependencySerializationTestDummy $object */
unset($dependencySerialization->_serviceIds); $dependencySerialization = unserialize($string);
// Ensure dependency injected object remains the same after serialization.
$this->assertEquals($dependencySerialization, $object);
// Ensure that _serviceIds does not exist on the object anymore.
$this->assertFalse(isset($object->_serviceIds));
// Ensure that both the service and the variable are in the unserialized $this->assertSame($service, $dependencySerialization->service);
// object. $this->assertSame($container, $dependencySerialization->container);
$this->assertSame($service, $object->service); $this->assertEmpty($dependencySerialization->getServiceIds());
$this->assertSame($container, $object->container);
} }
} }
...@@ -70,7 +64,9 @@ public function testSerialization() { ...@@ -70,7 +64,9 @@ public function testSerialization() {
/** /**
* Defines a test class which has a single service as dependency. * Defines a test class which has a single service as dependency.
*/ */
class TestClass extends DependencySerialization implements ContainerAwareInterface { class DependencySerializationTestDummy implements ContainerAwareInterface {
use DependencySerializationTrait;
/** /**
* A test service. * A test service.
...@@ -86,13 +82,6 @@ class TestClass extends DependencySerialization implements ContainerAwareInterfa ...@@ -86,13 +82,6 @@ class TestClass extends DependencySerialization implements ContainerAwareInterfa
*/ */
public $container; public $container;
/**
* {@inheritdoc}
*
* Make the property accessible for the test.
*/
public $_serviceIds;
/** /**
* Constructs a new TestClass object. * Constructs a new TestClass object.
* *
...@@ -109,4 +98,11 @@ public function __construct(\stdClass $service) { ...@@ -109,4 +98,11 @@ public function __construct(\stdClass $service) {
public function setContainer(ContainerInterface $container = NULL) { public function setContainer(ContainerInterface $container = NULL) {
$this->container = $container; $this->container = $container;
} }
/**
* Gets the stored service IDs.
*/
public function getServiceIds() {
return $this->_serviceIds;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment