8000 Bugfix: add \UnitEnum as a result of get() method · symfony/symfony@bd865f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit bd865f7

Browse files
jack.shpartkonicolas-grekas
jack.shpartko
authored andcommitted
Bugfix: add \UnitEnum as a result of get() method
1 parent 30a9506 commit bd865f7

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EnvPlaceholderParameterBag extends ParameterBag
2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function get(string $name): array|bool|string|int|float|null
32+
public function get(string $name): array|bool|string|int|float|\UnitEnum|null
3333
{
3434
if (str_starts_with($name, 'env(') && str_ends_with($name, ')') && 'env()' !== $name) {
3535
$env = substr($name, 4, -1);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
enum StringBackedEnum: string
15+
{
16+
case Bar = 'bar';
17+
}

src/Symfony/Component/DependencyInjection/Tests/ParameterBag/EnvPlaceholderParameterBagTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1616
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1717
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
18+
use Symfony\Component\DependencyInjection\Tests\Fixtures\StringBackedEnum;
1819

1920
class EnvPlaceholderParameterBagTest extends TestCase
2021
{
@@ -196,4 +197,12 @@ public function testExtraCharsInProcessor()
196197
$bag->resolve();
197198
$this->assertStringMatchesFormat('env_%s_key_a_b_c_FOO_%s', $bag->get('env(key:a.b-c:FOO)'));
198199
}
200+
201+
public function testGetEnum()
202+
{
203+
$bag = new EnvPlaceholderParameterBag();
204+
$bag->set('ENUM_VAR', StringBackedEnum::Bar);
205+
$this->assertInstanceOf(StringBackedEnum::class, $bag->get('ENUM_VAR'));
206+
$this->assertEquals(StringBackedEnum::Bar, $bag->get('ENUM_VAR'));
207+
}
199208
}

0 commit comments

Comments
 (0)
0