Skip to content

Commit 28ee545

Browse files
committed
Add functional test for proxy serialization bug
1 parent dfcda74 commit 28ee545

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace Neos\Flow\Tests\Functional\ObjectManagement\Fixtures;
3+
4+
/*
5+
* This file is part of the Neos.Flow package.
6+
*
7+
* (c) Contributors of the Neos Project - www.neos.io
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Neos\Flow\Annotations as Flow;
15+
16+
/**
17+
* A prototype class with an entity property (Issue #3493)
18+
* Before the fix, this class would NOT get serialization code
19+
* because the proxy builder was too eager in skipping it.
20+
*
21+
* @Flow\Scope("prototype")
22+
*/
23+
class ClassWithEntityProperty
24+
{
25+
/**
26+
* @var SimpleEntity
27+
*/
28+
public $entity;
29+
30+
/**
31+
* @var string
32+
*/
33+
public $someValue;
34+
35+
public function __construct(SimpleEntity $entity, string $someValue = 'default')
36+
{
37+
$this->entity = $entity;
38+
$this->someValue = $someValue;
39+
}
40+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
namespace Neos\Flow\Tests\Functional\ObjectManagement\Fixtures;
3+
4+
/*
5+
* This file is part of the Neos.Flow package.
6+
*
7+
* (c) Contributors of the Neos Project - www.neos.io
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Neos\Flow\Annotations as Flow;
15+
16+
/**
17+
* A simple entity for testing proxy serialization
18+
*
19+
* @Flow\Entity
20+
*/
21+
class SimpleEntity
22+
{
23+
/**
24+
* @var string
25+
*/
26+
protected $name = '';
27+
28+
public function __construct(string $name = '')
29+
{
30+
$this->name = $name;
31+
}
32+
33+
public function getName(): string
34+
{
35+
return $this->name;
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
namespace Neos\Flow\Tests\Functional\ObjectManagement;
3+
4+
/*
5+
* This file is part of the Neos.Flow package.
6+
*
7+
* (c) Contributors of the Neos Project - www.neos.io
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Neos\Flow\Tests\FunctionalTestCase;
15+
16+
/**
17+
* Test for Issue #3493: Classes with entity properties should get serialization code
18+
*/
19+
class ProxySerializationTest extends FunctionalTestCase
20+
{
21+
/**
22+
* @test
23+
*/
24+
public function classWithEntityPropertyCanBeSerialized(): void
25+
{
26+
$entity = new Fixtures\SimpleEntity('Test Entity');
27+
$object = new Fixtures\ClassWithEntityProperty($entity, 'some value');
28+
29+
// This should not fail - the proxy should have __sleep() method
30+
// Before the fix, this would fail because entity references would not be stripped
31+
$serialized = serialize($object);
32+
$unserialized = unserialize($serialized);
33+
34+
self::assertInstanceOf(Fixtures\ClassWithEntityProperty::class, $unserialized);
35+
self::assertEquals('some value', $unserialized->someValue);
36+
}
37+
}

0 commit comments

Comments
 (0)