Skip to content

Commit df639b0

Browse files
Merge branch '7.4' into 8.0
* 7.4: Fix inline var annotations run tests with PHPUnit 12.0 on PHP >= 8.3 fix expected stream to native value transformers replace #[TestWithJson] with #[TestWith] [Console][Table] Don't split grapheme clusters [FrameworkBundle] Fix block type from `OK` to `ERROR` when local vault is disabled in `SecretsGenerateKeysCommand` [FrameworkBundle] Add tests for `secrets:decrypt-to-local`, `encrypt-from-local`, and `generate-keys` commands Reflection*::setAccessible() has no effect as of PHP 8.1
2 parents b912117 + f687c00 commit df639b0

File tree

7 files changed

+90
-44
lines changed

7 files changed

+90
-44
lines changed

Extension/Validator/ValidatorExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public function __construct(
3333
private ?FormRendererInterface $formRenderer = null,
3434
private ?TranslatorInterface $translator = null,
3535
) {
36+
/** @var ClassMetadata $metadata */
3637
$metadata = $validator->getMetadataFor(\Symfony\Component\Form\Form::class);
3738

3839
// Register the form constraints in the validator programmatically.
3940
// This functionality is required when using the Form component without
4041
// the DIC, where the XML file is loaded automatically. Thus the following
4142
// code must be kept synchronized with validation.xml
4243

43-
/** @var ClassMetadata $metadata */
4444
$metadata->addConstraint(new Form());
4545
$metadata->addConstraint(new Traverse(false));
4646
}

ResolvedFormType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public function finishView(FormView $view, FormInterface $form, array $options):
117117

118118
$this->innerType->finishView($view, $form, $options);
119119

120+
/** @var FormTypeExtensionInterface $extension */
120121
foreach ($this->typeExtensions as $extension) {
121-
/** @var FormTypeExtensionInterface $extension */
122122
$extension->finishView($view, $form, $options);
123123
}
124124
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Form\Tests\ChoiceList;
13+
14+
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
15+
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
16+
17+
trait ChoiceListAssertionTrait
18+
{
19+
private function assertEqualsArrayChoiceList(ArrayChoiceList $expected, $actual)
20+
{
21+
$this->assertInstanceOf(ArrayChoiceList::class, $actual);
22+
$this->assertEquals($expected->getChoices(), $actual->getChoices());
23+
$this->assertEquals($expected->getStructuredValues(), $actual->getStructuredValues());
24+
$this->assertEquals($expected->getOriginalKeys(), $actual->getOriginalKeys());
25+
}
26+
27+
private function assertEqualsLazyChoiceList(LazyChoiceList $expected, $actual)
28+
{
29+
$this->assertInstanceOf(LazyChoiceList::class, $actual);
30+
$this->assertEquals($expected->getChoices(), $actual->getChoices());
31+
$this->assertEquals($expected->getValues(), $actual->getValues());
32+
$this->assertEquals($expected->getOriginalKeys(), $actual->getOriginalKeys());
33+
}
34+
}

Tests/ChoiceList/Factory/Cache/ChoiceLoaderTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
use Symfony\Component\Form\ChoiceList\Factory\Cache\ChoiceLoader;
1717
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
1818
use Symfony\Component\Form\Extension\Core\Type\FormType;
19+
use Symfony\Component\Form\Tests\ChoiceList\ChoiceListAssertionTrait;
1920
use Symfony\Component\Form\Tests\Fixtures\ArrayChoiceLoader;
2021

2122
class ChoiceLoaderTest extends TestCase
2223
{
24+
use ChoiceListAssertionTrait;
25+
2326
public function testSameFormTypeUseCachedLoader()
2427
{
2528
$choices = ['f' => 'foo', 'b' => 'bar', 'z' => 'baz'];
@@ -30,8 +33,8 @@ public function testSameFormTypeUseCachedLoader()
3033
$loader1 = new ChoiceLoader($type, $decorated);
3134
$loader2 = new ChoiceLoader($type, new ArrayChoiceLoader());
3235

33-
$this->assertEquals($choiceList, $loader1->loadChoiceList());
34-
$this->assertEquals($choiceList, $loader2->loadChoiceList());
36+
$this->assertEqualsArrayChoiceList($choiceList, $loader1->loadChoiceList());
37+
$this->assertEqualsArrayChoiceList($choiceList, $loader2->loadChoiceList());
3538

3639
$this->assertSame($choices, $loader1->loadChoicesForValues($choices));
3740
$this->assertSame($choices, $loader2->loadChoicesForValues($choices));

Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
use Symfony\Component\Form\ChoiceList\Loader\FilterChoiceLoaderDecorator;
2323
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
2424
use Symfony\Component\Form\Extension\Core\Type\FormType;
25+
use Symfony\Component\Form\Tests\ChoiceList\ChoiceListAssertionTrait;
2526
use Symfony\Component\Form\Tests\Fixtures\ArrayChoiceLoader;
2627

2728
/**
2829
* @author Bernhard Schussek <[email protected]>
2930
*/
3031
class CachingFactoryDecoratorTest extends TestCase
3132
{
33+
use ChoiceListAssertionTrait;
34+
3235
private CachingFactoryDecorator $factory;
3336

3437
protected function setUp(): void
@@ -42,8 +45,8 @@ public function testCreateFromChoicesEmpty()
4245
$list2 = $this->factory->createListFromChoices([]);
4346

4447
$this->assertSame($list1, $list2);
45-
$this->assertEquals(new ArrayChoiceList([]), $list1);
46-
$this->assertEquals(new ArrayChoiceList([]), $list2);
48+
self::assertEqualsArrayChoiceList(new ArrayChoiceList([]), $list1);
49+
self::assertEqualsArrayChoiceList(new ArrayChoiceList([]), $list2);
4750
}
4851

4952
public function testCreateFromChoicesComparesTraversableChoicesAsArray()
@@ -56,8 +59,8 @@ public function testCreateFromChoicesComparesTraversableChoicesAsArray()
5659
$list2 = $this->factory->createListFromChoices($choices2);
5760

5861
$this->assertSame($list1, $list2);
59-
$this->assertEquals(new ArrayChoiceList(['A' => 'a']), $list1);
60-
$this->assertEquals(new ArrayChoiceList(['A' => 'a']), $list2);
62+
self::assertEqualsArrayChoiceList(new ArrayChoiceList(['A' => 'a']), $list1);
63+
self::assertEqualsArrayChoiceList(new ArrayChoiceList(['A' => 'a']), $list2);
6164
}
6265

6366
public function testCreateFromChoicesGroupedChoices()
@@ -68,8 +71,8 @@ public function testCreateFromChoicesGroupedChoices()
6871
$list2 = $this->factory->createListFromChoices($choices2);
6972

7073
$this->assertNotSame($list1, $list2);
71-
$this->assertEquals(new ArrayChoiceList(['key' => ['A' => 'a']]), $list1);
72-
$this->assertEquals(new ArrayChoiceList(['A' => 'a']), $list2);
74+
self::assertEqualsArrayChoiceList(new ArrayChoiceList(['key' => ['A' => 'a']]), $list1);
75+
self::assertEqualsArrayChoiceList(new ArrayChoiceList(['A' => 'a']), $list2);
7376
}
7477

7578
#[DataProvider('provideSameChoices')]
@@ -79,8 +82,8 @@ public function testCreateFromChoicesSameChoices($choice1, $choice2)
7982
$list2 = $this->factory->createListFromChoices([$choice2]);
8083

8184
$this->assertSame($list1, $list2);
82-
$this->assertEquals(new ArrayChoiceList([$choice1]), $list1);
83-
$this->assertEquals(new ArrayChoiceList([$choice2]), $list2);
85+
self::assertEqualsArrayChoiceList(new ArrayChoiceList([$choice1]), $list1);
86+
self::assertEqualsArrayChoiceList(new ArrayChoiceList([$choice2]), $list2);
8487
}
8588

8689
#[DataProvider('provideDistinguishedChoices')]
@@ -90,8 +93,8 @@ public function testCreateFromChoicesDifferentChoices($choice1, $choice2)
9093
$list2 = $this->factory->createListFromChoices([$choice2]);
9194

9295
$this->assertNotSame($list1, $list2);
93-
$this->assertEquals(new ArrayChoiceList([$choice1]), $list1);
94-
$this->assertEquals(new ArrayChoiceList([$choice2]), $list2);
96+
self::assertEqualsArrayChoiceList(new ArrayChoiceList([$choice1]), $list1);
97+
self::assertEqualsArrayChoiceList(new ArrayChoiceList([$choice2]), $list2);
9598
}
9699

97100
public function testCreateFromChoicesSameValueClosure()
@@ -103,8 +106,8 @@ public function testCreateFromChoicesSameValueClosure()
103106
$list2 = $this->factory->createListFromChoices($choices, $closure);
104107

105108
$this->assertNotSame($list1, $list2);
106-
$this->assertEquals(new ArrayChoiceList($choices, $closure), $list1);
107-
$this->assertEquals(new ArrayChoiceList($choices, $closure), $list2);
109+
self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $closure), $list1);
110+
self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $closure), $list2);
108111
}
109112

110113
public function testCreateFromChoicesSameValueClosureUseCache()
@@ -117,8 +120,8 @@ public function testCreateFromChoicesSameValueClosureUseCache()
117120
$list2 = $this->factory->createListFromChoices($choices, ChoiceList::value($formType, function () {}));
118121

119122
$this->assertSame($list1, $list2);
120-
$this->assertEquals(new ArrayChoiceList($choices, $valueCallback), $list1);
121-
$this->assertEquals(new ArrayChoiceList($choices, function () {}), $list2);
123+
self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $valueCallback), $list1);
124+
self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, function () {}), $list2);
122125
}
123126

124127
public function testCreateFromChoicesDifferentValueClosure()
@@ -130,8 +133,8 @@ public function testCreateFromChoicesDifferentValueClosure()
130133
$list2 = $this->factory->createListFromChoices($choices, $closure2);
131134

132135
$this->assertNotSame($list1, $list2);
133-
$this->assertEquals(new ArrayChoiceList($choices, $closure1), $list1);
134-
$this->assertEquals(new ArrayChoiceList($choices, $closure2), $list2);
136+
self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $closure1), $list1);
137+
self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $closure2), $list2);
135138
}
136139

137140
public function testCreateFromChoicesSameFilterClosure()
@@ -143,8 +146,8 @@ public function testCreateFromChoicesSameFilterClosure()
143146
$lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), $filter), null);
144147

145148
$this->assertNotSame($list1, $list2);
146-
$this->assertEquals($lazyChoiceList, $list1);
147-
$this->assertEquals($lazyChoiceList, $list2);
149+
self::assertEqualsLazyChoiceList($lazyChoiceList, $list1);
150+
self::assertEqualsLazyChoiceList($lazyChoiceList, $list2);
148151
}
149152

150153
public function testCreateFromChoicesSameFilterClosureUseCache()
@@ -157,8 +160,8 @@ public function testCreateFromChoicesSameFilterClosureUseCache()
157160
$lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), function () {}), null);
158161

159162
$this->assertSame($list1, $list2);
160-
$this->assertEquals($lazyChoiceList, $list1);
161-
$this->assertEquals($lazyChoiceList, $list2);
163+
self::assertEqualsLazyChoiceList($lazyChoiceList, $list1);
164+
self::assertEqualsLazyChoiceList($lazyChoiceList, $list2);
162165
}
163166

164167
public function testCreateFromChoicesDifferentFilterClosure()
@@ -171,8 +174,8 @@ public function testCreateFromChoicesDifferentFilterClosure()
171174
$lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), function () {}), null);
172175

173176
$this->assertNotSame($list1, $list2);
174-
$this->assertEquals($lazyChoiceList, $list1);
175-
$this->assertEquals($lazyChoiceList, $list2);
177+
self::assertEqualsLazyChoiceList($lazyChoiceList, $list1);
178+
self::assertEqualsLazyChoiceList($lazyChoiceList, $list2);
176179
}
177180

178181
public function testCreateFromLoaderSameLoader()
@@ -182,8 +185,8 @@ public function testCreateFromLoaderSameLoader()
182185
$list2 = $this->factory->createListFromLoader($loader);
183186

184187
$this->assertNotSame($list1, $list2);
185-
$this->assertEquals(new LazyChoiceList($loader), $list1);
186-
$this->assertEquals(new LazyChoiceList($loader), $list2);
188+
self::assertEqualsLazyChoiceList(new LazyChoiceList($loader), $list1);
189+
self::assertEqualsLazyChoiceList(new LazyChoiceList($loader), $list2);
187190
}
188191

189192
public function testCreateFromLoaderSameLoaderUseCache()
@@ -193,8 +196,8 @@ public function testCreateFromLoaderSameLoaderUseCache()
193196
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()));
194197

195198
$this->assertSame($list1, $list2);
196-
$this->assertEquals(new LazyChoiceList(new ArrayChoiceLoader(), null), $list1);
197-
$this->assertEquals(new LazyChoiceList(new ArrayChoiceLoader(), null), $list2);
199+
self::assertEqualsLazyChoiceList(new LazyChoiceList(new ArrayChoiceLoader(), null), $list1);
200+
self::assertEqualsLazyChoiceList(new LazyChoiceList(new ArrayChoiceLoader(), null), $list2);
198201
}
199202

200203
public function testCreateFromLoaderDifferentLoader()
@@ -210,8 +213,8 @@ public function testCreateFromLoaderSameValueClosure()
210213
$list2 = $this->factory->createListFromLoader($loader, $closure);
211214

212215
$this->assertNotSame($list1, $list2);
213-
$this->assertEquals(new LazyChoiceList($loader, $closure), $list1);
214-
$this->assertEquals(new LazyChoiceList($loader, $closure), $list2);
216+
self::assertEqualsLazyChoiceList(new LazyChoiceList($loader, $closure), $list1);
217+
self::assertEqualsLazyChoiceList(new LazyChoiceList($loader, $closure), $list2);
215218
}
216219

217220
public function testCreateFromLoaderSameValueClosureUseCache()
@@ -223,8 +226,8 @@ public function testCreateFromLoaderSameValueClosureUseCache()
223226
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), ChoiceList::value($type, function () {}));
224227

225228
$this->assertSame($list1, $list2);
226-
$this->assertEquals(new LazyChoiceList($loader, $closure), $list1);
227-
$this->assertEquals(new LazyChoiceList(new ArrayChoiceLoader(), function () {}), $list2);
229+
self::assertEqualsLazyChoiceList(new LazyChoiceList($loader, $closure), $list1);
230+
self::assertEqualsLazyChoiceList(new LazyChoiceList(new ArrayChoiceLoader(), function () {}), $list2);
228231
}
229232

230233
public function testCreateFromLoaderDifferentValueClosure()
@@ -246,8 +249,8 @@ public function testCreateFromLoaderSameFilterClosure()
246249
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $closure);
247250

248251
$this->assertNotSame($list1, $list2);
249-
$this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator($loader, $closure)), $list1);
250-
$this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure)), $list2);
252+
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator($loader, $closure)), $list1);
253+
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure)), $list2);
251254
}
252255

253256
public function testCreateFromLoaderSameFilterClosureUseCache()
@@ -258,8 +261,8 @@ public function testCreateFromLoaderSameFilterClosureUseCache()
258261
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $choiceFilter);
259262

260263
$this->assertSame($list1, $list2);
261-
$this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list1);
262-
$this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list2);
264+
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list1);
265+
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list2);
263266
}
264267

265268
public function testCreateFromLoaderDifferentFilterClosure()
@@ -271,8 +274,8 @@ public function testCreateFromLoaderDifferentFilterClosure()
271274
$list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $closure2);
272275

273276
$this->assertNotSame($list1, $list2);
274-
$this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure1), null), $list1);
275-
$this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure2), null), $list2);
277+
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure1), null), $list1);
278+
self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure2), null), $list2);
276279
}
277280

278281
public function testCreateViewSamePreferredChoices()

Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
2121
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
2222
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
23+
use Symfony\Component\Form\Tests\ChoiceList\ChoiceListAssertionTrait;
2324
use Symfony\Component\Form\Tests\Fixtures\ArrayChoiceLoader;
2425
use Symfony\Component\Translation\TranslatableMessage;
2526
use Symfony\Contracts\Translation\TranslatableInterface;
2627
use Symfony\Contracts\Translation\TranslatorInterface;
2728

2829
class DefaultChoiceListFactoryTest extends TestCase
2930
{
31+
use ChoiceListAssertionTrait;
32+
3033
private \stdClass $obj1;
3134
private \stdClass $obj2;
3235
private \stdClass $obj3;
@@ -261,7 +264,7 @@ public function testCreateFromLoaderWithFilter()
261264

262265
$list = $this->factory->createListFromLoader(new ArrayChoiceLoader(), null, $filter);
263266

264-
$this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $filter)), $list);
267+
$this->assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $filter)), $list);
265268
}
266269

267270
public function testCreateViewFlat()

Tests/ChoiceList/Loader/FilterChoiceLoaderDecoratorTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
1616
use Symfony\Component\Form\ChoiceList\Loader\FilterChoiceLoaderDecorator;
17+
use Symfony\Component\Form\Tests\ChoiceList\ChoiceListAssertionTrait;
1718
use Symfony\Component\Form\Tests\Fixtures\ArrayChoiceLoader;
1819

1920
class FilterChoiceLoaderDecoratorTest extends TestCase
2021
{
22+
use ChoiceListAssertionTrait;
23+
2124
public function testLoadChoiceList()
2225
{
2326
$filter = fn ($choice) => 0 === $choice % 2;
2427

2528
$loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(range(1, 4)), $filter);
2629

27-
$this->assertEquals(new ArrayChoiceList([1 => 2, 3 => 4]), $loader->loadChoiceList());
30+
$this->assertEqualsArrayChoiceList(new ArrayChoiceList([1 => 2, 3 => 4]), $loader->loadChoiceList());
2831
}
2932

3033
public function testLoadChoiceListWithGroupedChoices()
@@ -33,7 +36,7 @@ public function testLoadChoiceListWithGroupedChoices()
3336

3437
$loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(['units' => range(1, 9), 'tens' => range(10, 90, 10)]), $filter);
3538

36-
$this->assertEquals(new ArrayChoiceList([
39+
$this->assertEqualsArrayChoiceList(new ArrayChoiceList([
3740
'units' => [
3841
1 => 2,
3942
3 => 4,
@@ -50,7 +53,7 @@ public function testLoadChoiceListMixedWithGroupedAndNonGroupedChoices()
5053
$choices = array_merge(range(1, 9), ['grouped' => range(10, 40, 5)]);
5154
$loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader($choices), $filter);
5255

53-
$this->assertEquals(new ArrayChoiceList([
56+
$this->assertEqualsArrayChoiceList(new ArrayChoiceList([
5457
1 => 2,
5558
3 => 4,
5659
5 => 6,

0 commit comments

Comments
 (0)