Skip to content

Commit 527b885

Browse files
committed
Merge branch '5.2' into 5.x
* 5.2: [VarDumper] Add PHP 8.1 enums tests
2 parents 59211ce + bf6e98c commit 527b885

File tree

4 files changed

+139
-1
lines changed

4 files changed

+139
-1
lines changed

src/Symfony/Component/VarDumper/Tests/Cloner/VarClonerTest.php

+104-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\VarDumper\Cloner\VarCloner;
1616
use Symfony\Component\VarDumper\Tests\Fixtures\Php74;
17+
use Symfony\Component\VarDumper\Tests\Fixtures\Php81Enums;
1718

1819
/**
1920
* @author Nicolas Grekas <[email protected]>
@@ -428,7 +429,7 @@ public function testCaster()
428429
[attr] => Array
429430
(
430431
[file] => %a%eVarClonerTest.php
431-
[line] => 21
432+
[line] => 22
432433
)
433434
434435
)
@@ -526,6 +527,108 @@ public function testPhp74()
526527
527528
)
528529

530+
EOTXT;
531+
$this->assertStringMatchesFormat($expected, print_r($clone, true));
532+
}
533+
534+
/**
535+
* @requires PHP 8.1
536+
*/
537+
public function testPhp81Enums()
538+
{
539+
$data = new Php81Enums();
540+
541+
$cloner = new VarCloner();
542+
$clone = $cloner->cloneVar($data);
543+
544+
$expected = <<<'EOTXT'
545+
Symfony\Component\VarDumper\Cloner\Data Object
546+
(
547+
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
548+
(
549+
[0] => Array
550+
(
551+
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
552+
(
553+
[type] => 4
554+
[class] => Symfony\Component\VarDumper\Tests\Fixtures\Php81Enums
555+
[value] =>
556+
[cut] => 0
557+
[handle] => %i
558+
[refCount] => 0
559+
[position] => 1
560+
[attr] => Array
561+
(
562+
[file] => %s
563+
[line] => 5
564+
)
565+
566+
)
567+
568+
)
569+
570+
[1] => Array
571+
(
572+
[e1] => Symfony\Component\VarDumper\Cloner\Stub Object
573+
(
574+
[type] => 4
575+
[class] => Symfony\Component\VarDumper\Tests\Fixtures\UnitEnumFixture
576+
[value] =>
577+
[cut] => 0
578+
[handle] => %i
579+
[refCount] => 0
580+
[position] => 2
581+
[attr] => Array
582+
(
583+
[file] => %s
584+
[line] => 5
585+
)
586+
587+
)
588+
589+
[e2] => Symfony\Component\VarDumper\Cloner\Stub Object
590+
(
591+
[type] => 4
592+
[class] => Symfony\Component\VarDumper\Tests\Fixtures\BackedEnumFixture
593+
[value] =>
594+
[cut] => 0
595+
[handle] => %i
596+
[refCount] => 0
597+
[position] => 3
598+
[attr] => Array
599+
(
600+
[file] => %s
601+
[line] => 5
602+
)
603+
604+
)
605+
606+
)
607+
608+
[2] => Array
609+
(
610+
[name] => Hearts
611+
)
612+
613+
[3] => Array
614+
(
615+
[name] => Diamonds
616+
[value] => D
617+
)
618+
619+
)
620+
621+
[position:Symfony\Component\VarDumper\Cloner\Data:private] => 0
622+
[key:Symfony\Component\VarDumper\Cloner\Data:private] => 0
623+
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
624+
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
625+
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
626+
[context:Symfony\Component\VarDumper\Cloner\Data:private] => Array
627+
(
628+
)
629+
630+
)
631+
529632
EOTXT;
530633
$this->assertStringMatchesFormat($expected, print_r($clone, true));
531634
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
4+
5+
enum BackedEnumFixture: string {
6+
case Hearts = 'H';
7+
case Diamonds = 'D';
8+
case Clubs = 'C';
9+
case Spades = 'S';
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
4+
5+
class Php81Enums
6+
{
7+
public UnitEnumFixture $e1;
8+
public BackedEnumFixture $e2;
9+
10+
public function __construct()
11+
{
12+
$this->e1 = UnitEnumFixture::Hearts;
13+
$this->e2 = BackedEnumFixture::Diamonds;
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
4+
5+
enum UnitEnumFixture {
6+
case Hearts;
7+
case Diamonds;
8+
case Clubs;
9+
case Spades;
10+
}

0 commit comments

Comments
 (0)