Merge branch '4.4' into 5.2

* 4.4:
  [VarDumper] Add PHP 8.1 enums tests
  [Console] : added phpdocs to InputOption constants
This commit is contained in:
Alexander M. Turek 2021-04-19 16:07:32 +02:00
commit bf6e98c220
5 changed files with 154 additions and 1 deletions

View File

@ -21,9 +21,24 @@ use Symfony\Component\Console\Exception\LogicException;
*/
class InputOption
{
/**
* Do not accept input for the option (e.g. --yell). This is the default behavior of options.
*/
public const VALUE_NONE = 1;
/**
* A value must be passed when the option is used (e.g. --iterations=5 or -i5).
*/
public const VALUE_REQUIRED = 2;
/**
* The option may or may not have a value (e.g. --yell or --yell=loud).
*/
public const VALUE_OPTIONAL = 4;
/**
* The option accepts multiple values (e.g. --dir=/foo --dir=/bar).
*/
public const VALUE_IS_ARRAY = 8;
private $name;

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\VarDumper\Tests\Cloner;
use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Tests\Fixtures\Php74;
use Symfony\Component\VarDumper\Tests\Fixtures\Php81Enums;
/**
* @author Nicolas Grekas <p@tchwork.com>
@ -428,7 +429,7 @@ Symfony\Component\VarDumper\Cloner\Data Object
[attr] => Array
(
[file] => %a%eVarClonerTest.php
[line] => 21
[line] => 22
)
)
@ -526,6 +527,108 @@ Symfony\Component\VarDumper\Cloner\Data Object
)
EOTXT;
$this->assertStringMatchesFormat($expected, print_r($clone, true));
}
/**
* @requires PHP 8.1
*/
public function testPhp81Enums()
{
$data = new Php81Enums();
$cloner = new VarCloner();
$clone = $cloner->cloneVar($data);
$expected = <<<'EOTXT'
Symfony\Component\VarDumper\Cloner\Data Object
(
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
(
[0] => Array
(
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
(
[type] => 4
[class] => Symfony\Component\VarDumper\Tests\Fixtures\Php81Enums
[value] =>
[cut] => 0
[handle] => %i
[refCount] => 0
[position] => 1
[attr] => Array
(
[file] => %s
[line] => 5
)
)
)
[1] => Array
(
[e1] => Symfony\Component\VarDumper\Cloner\Stub Object
(
[type] => 4
[class] => Symfony\Component\VarDumper\Tests\Fixtures\UnitEnumFixture
[value] =>
[cut] => 0
[handle] => %i
[refCount] => 0
[position] => 2
[attr] => Array
(
[file] => %s
[line] => 5
)
)
[e2] => Symfony\Component\VarDumper\Cloner\Stub Object
(
[type] => 4
[class] => Symfony\Component\VarDumper\Tests\Fixtures\BackedEnumFixture
[value] =>
[cut] => 0
[handle] => %i
[refCount] => 0
[position] => 3
[attr] => Array
(
[file] => %s
[line] => 5
)
)
)
[2] => Array
(
[name] => Hearts
)
[3] => Array
(
[name] => Diamonds
[value] => D
)
)
[position:Symfony\Component\VarDumper\Cloner\Data:private] => 0
[key:Symfony\Component\VarDumper\Cloner\Data:private] => 0
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
[context:Symfony\Component\VarDumper\Cloner\Data:private] => Array
(
)
)
EOTXT;
$this->assertStringMatchesFormat($expected, print_r($clone, true));
}

View File

@ -0,0 +1,10 @@
<?php
namespace Symfony\Component\VarDumper\Tests\Fixtures;
enum BackedEnumFixture: string {
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
}

View File

@ -0,0 +1,15 @@
<?php
namespace Symfony\Component\VarDumper\Tests\Fixtures;
class Php81Enums
{
public UnitEnumFixture $e1;
public BackedEnumFixture $e2;
public function __construct()
{
$this->e1 = UnitEnumFixture::Hearts;
$this->e2 = BackedEnumFixture::Diamonds;
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Symfony\Component\VarDumper\Tests\Fixtures;
enum UnitEnumFixture {
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}