-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VarDumper] Fix serialization of stubs with null or uninitialized values
- Loading branch information
Showing
3 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\VarDumper\Cloner\Internal; | ||
|
||
/** | ||
* Flags a typed property that has no default value. | ||
* | ||
* This dummy object is used to distinguish a property with a default value of null | ||
* from a property that is uninitialized by default. | ||
* | ||
* @internal | ||
*/ | ||
enum NoDefault | ||
{ | ||
case NoDefault; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\VarDumper\Tests\Cloner; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\VarDumper\Cloner\Stub; | ||
|
||
final class StubTest extends TestCase | ||
{ | ||
public function testUnserializeNullValue() | ||
{ | ||
$stub = new Stub(); | ||
$stub->value = null; | ||
|
||
$stub = unserialize(serialize($stub)); | ||
|
||
self::assertNull($stub->value); | ||
} | ||
|
||
public function testUnserializeNullInTypedProperty() | ||
{ | ||
$stub = new MyStub(); | ||
$stub->myProp = null; | ||
|
||
$stub = unserialize(serialize($stub)); | ||
|
||
self::assertNull($stub->myProp); | ||
} | ||
|
||
public function testUninitializedStubPropertiesAreLeftUninitialized() | ||
{ | ||
$stub = new MyStub(); | ||
|
||
$stub = unserialize(serialize($stub)); | ||
|
||
$r = new \ReflectionProperty(MyStub::class, 'myProp'); | ||
self::assertFalse($r->isInitialized($stub)); | ||
} | ||
} | ||
|
||
final class MyStub extends Stub | ||
{ | ||
public mixed $myProp; | ||
} |