Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0802dff

Browse files
committed
Fix enum issue
1 parent b003136 commit 0802dff

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed
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 <[email protected]>
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\HttpFoundation\Tests\Fixtures;
13+
14+
enum FooEnum: int
15+
{
16+
case Bar = 1;
17+
}

src/Symfony/Component/HttpFoundation/Tests/InputBagTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
1616
use Symfony\Component\HttpFoundation\InputBag;
17+
use Symfony\Component\HttpFoundation\Tests\Fixtures\FooEnum;
1718

1819
class InputBagTest extends TestCase
1920
{
@@ -111,7 +112,7 @@ public function testGetEnum()
111112
{
112113
$bag = new InputBag(['valid-value' => 1]);
113114

114-
$this->assertSame(Foo::Bar, $bag->getEnum('valid-value', Foo::class));
115+
$this->assertSame(FooEnum::Bar, $bag->getEnum('valid-value', FooEnum::class));
115116
}
116117

117118
public function testGetEnumThrowsExceptionWithInvalidValue()
@@ -120,11 +121,11 @@ public function testGetEnumThrowsExceptionWithInvalidValue()
120121

121122
$this->expectException(BadRequestException::class);
122123
if (\PHP_VERSION_ID >= 80200) {
123-
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: 2 is not a valid backing value for enum Symfony\Component\HttpFoundation\Tests\Foo.');
124+
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: 2 is not a valid backing value for enum Symfony\Component\HttpFoundation\Tests\Fixtures\FooEnum.');
124125
} else {
125-
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: 2 is not a valid backing value for enum "Symfony\Component\HttpFoundation\Tests\Foo".');
126+
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: 2 is not a valid backing value for enum "Symfony\Component\HttpFoundation\Tests\Fixtures\FooEnum".');
126127
}
127128

128-
$this->assertNull($bag->getEnum('invalid-value', Foo::class));
129+
$this->assertNull($bag->getEnum('invalid-value', FooEnum::class));
129130
}
130131
}

src/Symfony/Component/HttpFoundation/Tests/ParameterBagTest.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
1616
use Symfony\Component\HttpFoundation\ParameterBag;
17+
use Symfony\Component\HttpFoundation\Tests\Fixtures\FooEnum;
1718

1819
class ParameterBagTest extends TestCase
1920
{
@@ -231,10 +232,10 @@ public function testGetEnum()
231232
{
232233
$bag = new ParameterBag(['valid-value' => 1]);
233234

234-
$this->assertSame(Foo::Bar, $bag->getEnum('valid-value', Foo::class));
235+
$this->assertSame(FooEnum::Bar, $bag->getEnum('valid-value', FooEnum::class));
235236

236-
$this->assertNull($bag->getEnum('invalid-key', Foo::class));
237-
$this->assertSame(Foo::Bar, $bag->getEnum('invalid-key', Foo::class, Foo::Bar));
237+
$this->assertNull($bag->getEnum('invalid-key', FooEnum::class));
238+
$this->assertSame(FooEnum::Bar, $bag->getEnum('invalid-key', FooEnum::class, FooEnum::Bar));
238239
}
239240

240241
public function testGetEnumThrowsExceptionWithNotBackingValue()
@@ -243,26 +244,21 @@ public function testGetEnumThrowsExceptionWithNotBackingValue()
243244

244245
$this->expectException(\UnexpectedValueException::class);
245246
if (\PHP_VERSION_ID >= 80200) {
246-
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: 2 is not a valid backing value for enum Symfony\Component\HttpFoundation\Tests\Foo.');
247+
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: 2 is not a valid backing value for enum Symfony\Component\HttpFoundation\Tests\Fixtures\FooEnum.');
247248
} else {
248-
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: 2 is not a valid backing value for enum "Symfony\Component\HttpFoundation\Tests\Foo".');
249+
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: 2 is not a valid backing value for enum "Symfony\Component\HttpFoundation\Tests\Fixtures\FooEnum".');
249250
}
250251

251-
$this->assertNull($bag->getEnum('invalid-value', Foo::class));
252+
$this->assertNull($bag->getEnum('invalid-value', FooEnum::class));
252253
}
253254

254255
public function testGetEnumThrowsExceptionWithInvalidValueType()
255256
{
256257
$bag = new ParameterBag(['invalid-value' => ['foo']]);
257258

258259
$this->expectException(\UnexpectedValueException::class);
259-
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: Symfony\Component\HttpFoundation\Tests\Foo::from(): Argument #1 ($value) must be of type int, array given.');
260+
$this->expectExceptionMessage('Parameter "invalid-value" cannot be converted to enum: Symfony\Component\HttpFoundation\Tests\Fixtures\FooEnum::from(): Argument #1 ($value) must be of type int, array given.');
260261

261-
$this->assertNull($bag->getEnum('invalid-value', Foo::class));
262+
$this->assertNull($bag->getEnum('invalid-value', FooEnum::class));
262263
}
263264
}
264-
265-
enum Foo: int
266-
{
267-
case Bar = 1;
268-
}

0 commit comments

Comments
 (0)