File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -58,3 +58,5 @@ parameters:
5858 path: 'tests/AutoReview/GAE2ECollector.php'
5959 - message: '#normalizeSymbolsRegistryReference#'
6060 path: 'tests/Console/Command/AddInspectCommandIntegrationTest.php'
61+ - message: '#unserialize#'
62+ path: 'src/Symbol/SymbolsRegistry.php'
Original file line number Diff line number Diff line change 1818use PhpParser \Node \Name \FullyQualified ;
1919use function array_values ;
2020use function count ;
21+ use function serialize ;
22+ use function unserialize ;
2123
2224final class SymbolsRegistry implements Countable
2325{
@@ -31,6 +33,9 @@ final class SymbolsRegistry implements Countable
3133 */
3234 private array $ recordedClasses = [];
3335
36+ /**
37+ * @param self[] $symbolsRegistries
38+ */
3439 public static function createFromRegistries (array $ symbolsRegistries ): self
3540 {
3641 $ symbolsRegistry = new self ();
@@ -42,6 +47,19 @@ public static function createFromRegistries(array $symbolsRegistries): self
4247 return $ symbolsRegistry ;
4348 }
4449
50+ public static function unserialize (string $ serialized ): self
51+ {
52+ return unserialize (
53+ $ serialized ,
54+ ['allowed_classes ' => [self ::class]],
55+ );
56+ }
57+
58+ public function serialize (): string
59+ {
60+ return serialize ($ this );
61+ }
62+
4563 public function merge (self $ symbolsRegistry ): void
4664 {
4765 foreach ($ symbolsRegistry ->getRecordedFunctions () as [$ original , $ alias ]) {
Original file line number Diff line number Diff line change @@ -50,6 +50,25 @@ public function test_it_records_functions_and_classes(
5050 );
5151 }
5252
53+ /**
54+ * @dataProvider provideRecords
55+ *
56+ * @param array<array{FullyQualified, FullyQualified}> $functions
57+ * @param array<array{FullyQualified, FullyQualified}> $classes
58+ */
59+ public function test_it_can_be_serialized_and_unserialized (
60+ array $ functions ,
61+ array $ classes ,
62+ ): void {
63+ $ registry = self ::createRegistry ($ functions , $ classes );
64+
65+ $ unserializedRegistry = SymbolsRegistry::unserialize (
66+ $ registry ->serialize (),
67+ );
68+
69+ self ::assertEquals ($ unserializedRegistry , $ registry );
70+ }
71+
5372 public static function provideRecords (): iterable
5473 {
5574 $ main = new FullyQualified ('PHPUnit\main ' );
You can’t perform that action at this time.
0 commit comments