Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2dd8445

Browse filesBrowse files
committed
minor #40867 [VarDumper] Add PHP 8.1 enums tests (shiftby)
This PR was merged into the 4.4 branch. Discussion ---------- [VarDumper] Add PHP 8.1 enums tests VarDumper component already supports PHP 8.1 enums, but didn't have tests | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #40238 | License | MIT | Doc PR | no VarDumper component already supports PHP 8.1 enums, but it didn't have tests. ```php enum UnitEnumFixture { case Hearts; case Diamonds; case Clubs; case Spades; } dump(UnitEnumFixture::Hearts); ``` ``` Symfony\Component\VarDumper\Tests\Fixtures\UnitEnumFixture {#435 +name: "Hearts" } ``` ```php enum BackedEnumFixture: string { case Hearts = 'H'; case Diamonds = 'D'; case Clubs = 'C'; case Spades = 'S'; } dump(BackedEnumFixture::Hearts); ``` ``` Symfony\Component\VarDumper\Tests\Fixtures\BackedEnumFixture {#157 +name: "Hearts" +value: "H" } ``` Commits ------- 9a2a027 [VarDumper] Add PHP 8.1 enums tests
2 parents a24f389 + 9a2a027 commit 2dd8445
Copy full SHA for 2dd8445

File tree

Expand file treeCollapse file tree

4 files changed

+139
-1
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+139
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Cloner/VarClonerTest.php
+104-1Lines changed: 104 additions & 1 deletion
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 <p@tchwork.com>
@@ -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
}
+10Lines changed: 10 additions & 0 deletions
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+
}
+15Lines changed: 15 additions & 0 deletions
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+
}
+10Lines changed: 10 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.