Issue #3020165 by alexpott: Dependency objects can be optimised for serialisation
parent
56ccba066c
commit
e5b70636c9
|
@ -190,4 +190,14 @@ class Dependency implements \ArrayAccess {
|
|||
return new static($name, $project, $version_string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents unnecessary serialization of constraint objects.
|
||||
*
|
||||
* @return array
|
||||
* The properties to seriailize.
|
||||
*/
|
||||
public function __sleep() {
|
||||
return ['name', 'project', 'constraintString'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\Core\Extension;
|
||||
|
||||
use Drupal\Component\Version\Constraint;
|
||||
use Drupal\Core\Extension\Dependency;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
|
@ -100,4 +101,19 @@ class DependencyTest extends UnitTestCase {
|
|||
$dependency['name'] = 'foo';
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that constraint objects are not serialized.
|
||||
*
|
||||
* @covers ::__sleep
|
||||
*/
|
||||
public function testSerialization() {
|
||||
$dependency = new Dependency('paragraphs_demo', 'paragraphs', '>8.x-1.1');
|
||||
$this->assertTrue($dependency->isCompatible('1.2'));
|
||||
$this->assertInstanceOf(Constraint::class, $this->getObjectAttribute($dependency, 'constraint'));
|
||||
$dependency = unserialize(serialize($dependency));
|
||||
$this->assertNull($this->getObjectAttribute($dependency, 'constraint'));
|
||||
$this->assertTrue($dependency->isCompatible('1.2'));
|
||||
$this->assertInstanceOf(Constraint::class, $this->getObjectAttribute($dependency, 'constraint'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue