8000 Merge branch '5.3' into 5.4 · symfony/symfony@64ff5b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 64ff5b1

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: clean up remaining event mocks do not mock the Request class do not mock event classes Fix use_notify default value for PostgreSqlConnection recover from failed deserializations fix setDefaultCommand [ErrorHandle] Remove a link from the exception page [Validator] Added Ukrainian translations [DependencyInjection] Fix TaggedLocator attribute without index argument [GHA] Clarify some bits in the deps=high script
2 parents 5056841 + d67dc12 commit 64ff5b1

File tree

25 files changed

+196
-338
lines changed

25 files changed

+196
-338
lines changed

.github/workflows/unit-tests.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,26 @@ jobs:
184184
# matrix.mode = high-deps
185185
echo "$COMPONENTS" | xargs -n1 | parallel -j +3 "_run_tests {} 'cd {} && $COMPOSER_UP && $PHPUNIT$LEGACY'" || X=1
186186
187+
# get a list of the patched components (relies on .github/build-packages.php being called in the previous step)
187188
(cd src/Symfony/Component/HttpFoundation; mv composer.bak composer.json)
188-
COMPONENTS=$(git diff --name-only src/ | grep composer.json || true)
189+
PATCHED_COMPONENTS=$(git diff --name-only src/ | grep composer.json || true)
189190
190-
if [[ $COMPONENTS && $SYMFONY_VERSION = *.4 ]]; then
191+
# for x.4 branches, checkout and test previous major with the patched components (only for patched components)
192+
if [[ $PATCHED_COMPONENTS && $SYMFONY_VERSION = *.4 ]]; then
191193
export FLIP='^'
192194
SYMFONY_VERSION=$(echo $SYMFONY_VERSION | awk '{print $1 - 1}')
193195
echo -e "\\n\\e[33;1mChecking out Symfony $SYMFONY_VERSION and running tests with patched components as deps\\e[0m"
194196
export COMPOSER_ROOT_VERSION=$SYMFONY_VERSION.x-dev
195197
export SYMFONY_REQUIRE=">=$SYMFONY_VERSION"
196198
git fetch --depth=2 origin $SYMFONY_VERSION
197199
git checkout -m FETCH_HEAD
198-
COMPONENTS=$(echo "$C 10000 OMPONENTS" | xargs dirname | xargs -n1 -I{} bash -c "[ -e '{}/phpunit.xml.dist' ] && echo '{}'" | sort || true)
200+
PATCHED_COMPONENTS=$(echo "$PATCHED_COMPONENTS" | xargs dirname | xargs -n1 -I{} bash -c "[ -e '{}/phpunit.xml.dist' ] && echo '{}'" | sort || true)
199201
(cd src/Symfony/Component/HttpFoundation; composer require --dev --no-update mongodb/mongodb)
200-
if [[ $COMPONENTS ]]; then
202+
if [[ $PATCHED_COMPONENTS ]]; then
201203
echo "::group::install phpunit"
202204
./phpunit install
203205
echo "::endgroup::"
204-
echo "$COMPONENTS" | parallel -j +3 "_run_tests {} 'cd {} && rm composer.lock vendor/ -Rf && $COMPOSER_UP && $PHPUNIT$LEGACY'" || X=1
206+
echo "$PATCHED_COMPONENTS" | parallel -j +3 "_run_tests {} 'cd {} && rm composer.lock vendor/ -Rf && $COMPOSER_UP && $PHPUNIT$LEGACY'" || X=1
205207
fi
206208
fi
207209

src/Symfony/Bridge/Monolog/Tests/Processor/ConsoleCommandProcessorTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Event\ConsoleEvent;
1818
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
1920

2021
class ConsoleCommandProcessorTest extends TestCase
2122
{
@@ -66,10 +67,7 @@ private function getConsoleEvent(): ConsoleEvent
6667
$input->method('getOptions')->willReturn(self::TEST_OPTIONS);
6768
$command = $this->createMock(Command::class);
6869
$command->method('getName')->willReturn(self::TEST_NAME);
69-
$consoleEvent = $this->createMock(ConsoleEvent::class);
70-
$consoleEvent->method('getCommand')->willReturn($command);
71-
$consoleEvent->method('getInput')->willReturn($input);
7270

73-
return $consoleEvent;
71+
return new ConsoleEvent($command, $input, $this->createMock(OutputInterface::class));
7472
}
7573
}

src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler;
1616
use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
17-
use Symfony\Component\HttpFoundation\HeaderBag;
1817
use Symfony\Component\HttpFoundation\Request;
1918
use Symfony\Component\HttpFoundation\Response;
2019
use Symfony\Component\HttpFoundation\Session\Session;
@@ -63,11 +62,11 @@ public function getInjectToolbarTests()
6362
/**
6463
* @dataProvider provideRedirects
6564
*/
66-
public function testHtmlRedirectionIsIntercepted($statusCode, $hasSession)
65+
public function testHtmlRedirectionIsIntercepted($statusCode)
6766
{
6867
$response = new Response('Some content', $statusCode);
6968
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
70-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MAIN_REQUEST, $response);
69+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
7170

7271
$listener = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
7372
$listener->onKernelResponse($event);
@@ -80,7 +79,7 @@ public function testNonHtmlRedirectionIsNotIntercepted()
8079
{
8180
$response = new Response('Some content', '301');
8281
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
83-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'json', true), HttpKernelInterface::MAIN_REQUEST, $response);
82+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request([], [], ['_format' => 'json']), HttpKernelInterface::MAIN_REQUEST, $response);
8483

8584
$listener = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
8685
$listener->onKernelResponse($event);
@@ -94,7 +93,7 @@ public function testToolbarIsInjected()
9493
$response = new Response('<html><head></head><body></body></html>');
9594
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
9695

97-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MAIN_REQUEST, $response);
96+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
9897

9998
$listener = new WebDebugToolbarListener($this->getTwigMock());
10099
$listener->onKernelResponse($event);
@@ -110,7 +109,7 @@ public function testToolbarIsNotInjectedOnNonHtmlContentType()
110109
$response = new Response('<html><head></head><body></body></html>');
111110
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
112111
$response->headers->set('Content-Type', 'text/xml');
113-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MAIN_REQUEST, $response);
112+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
114113

115114
$listener = new WebDebugToolbarListener($this->getTwigMock());
116115
$listener->onKernelResponse($event);
@@ -126,7 +125,7 @@ public function testToolbarIsNotInjectedOnContentDispositionAttachment()
126125
$response = new Response('<html><head></head><body></body></html>');
127126
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
128127
$response->headers->set('Content-Disposition', 'attachment; filename=test.html');
129-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'html'), HttpKernelInterface::MAIN_REQUEST, $response);
128+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
130129

131130
$listener = new WebDebugToolbarListener($this->getTwigMock());
132131
$listener->onKernelResponse($event);
@@ -138,11 +137,11 @@ public function testToolbarIsNotInjectedOnContentDispositionAttachment()
138137
* @depends testToolbarIsInjected
139138
* @dataProvider provideRedirects
140139
*/
141-
public function testToolbarIsNotInjectedOnRedirection($statusCode, $hasSession)
140+
public function testToolbarIsNotInjectedOnRedirection($statusCode)
142141
{
143142
$response = new Response('<html><head></head><body></body></html>', $statusCode);
144143
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
145-
$event = new ResponseEvent($this->createMock(Kernel::class), $this< 10000 /span>->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MAIN_REQUEST, $response);
144+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
146145

147146
$listener = new WebDebugToolbarListener($this->getTwigMock());
148147
$listener->onKernelResponse($event);
@@ -153,10 +152,8 @@ public function testToolbarIsNotInjectedOnRedirection($statusCode, $hasSession)
153152
public function provideRedirects()
154153
{
155154
return [
156-
[301, true],
157-
[302, true],
158-
[301, false],
159-
[302, false],
155+
[301],
156+
[302],
160157
];
161158
}
162159

@@ -167,7 +164,7 @@ public function testToolbarIsNotInjectedWhenThereIsNoNoXDebugTokenResponseHeader
167164
{
168165
$response = new Response('<html><head></head><body></body></html>');
169166

170-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MAIN_REQUEST, $response);
167+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
171168

172169
$listener = new WebDebugToolbarListener($this->getTwigMock());
173170
$listener->onKernelResponse($event);
@@ -183,7 +180,7 @@ public function testToolbarIsNotInjectedWhenOnSubRequest()
183180
$response = new Response('<html><head></head><body></body></html>');
184181
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
185182

186-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::SUB_REQUEST, $response);
183+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::SUB_REQUEST, $response);
187184

188185
$listener = new WebDebugToolbarListener($this->getTwigMock());
189186
$listener->onKernelResponse($event);
@@ -199,7 +196,7 @@ public function testToolbarIsNotInjectedOnIncompleteHtmlResponses()
199196
$response = new Response('<div>Some content</div>');
200197
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
201198

202-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MAIN_REQUEST, $response);
199+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
203200

204201
$listener = new WebDebugToolbarListener($this->getTwigMock());
205202
$listener->onKernelResponse($event);
@@ -215,7 +212,10 @@ public function testToolbarIsNotInjectedOnXmlHttpRequests()
215212
$response = new Response('<html><head></head><body></body></html>');
216213
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
217214

218-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(true), HttpKernelInterface::MAIN_REQUEST, $response);
215+
$request = new Request();
216+
$request->headers->set('X-Requested-With', 'XMLHttpRequest');
217+
218+
$event = new ResponseEvent($this->createMock(Kernel::class), $request, HttpKernelInterface::MAIN_REQUEST, $response);
219219

220220
$listener = new WebDebugToolbarListener($this->getTwigMock());
221221
$listener->onKernelResponse($event);
@@ -231,7 +231,7 @@ public function testToolbarIsNotInjectedOnNonHtmlRequests()
231231
$response = new Response('<html><head></head><body></body></html>');
232232
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
233233

234-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'json'), HttpKernelInterface::MAIN_REQUEST, $response);
234+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request([], [], ['_format' => 'json']), HttpKernelInterface::MAIN_REQUEST, $response);
235235

236236
$listener = new WebDebugToolbarListener($this->getTwigMock());
237237
$listener->onKernelResponse($event);
@@ -252,7 +252,7 @@ public function testXDebugUrlHeader()
252252
->willReturn('http://mydomain.com/_profiler/xxxxxxxx')
253253
;
254254

255-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MAIN_REQUEST, $response);
255+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
256256

257257
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
258258
$listener->onKernelResponse($event);
@@ -273,7 +273,7 @@ public function testThrowingUrlGenerator()
273273
->willThrowException(new \Exception('foo'))
274274
;
275275

276-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MAIN_REQUEST, $response);
276+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
277277

278278
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
279279
$listener->onKernelResponse($event);
@@ -294,7 +294,7 @@ public function testThrowingErrorCleanup()
294294
->willThrowException(new \Exception("This\nmultiline\r\ntabbed text should\tcome out\r on\n \ta single plain\r\nline"))
295295
;
296296

297-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MAIN_REQUEST, $response);
297+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
298298

299299
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
300300
$listener->onKernelResponse($event);
@@ -307,7 +307,7 @@ public function testCspIsDisabledIfDumperWasUsed()
307307
$response = new Response('<html><head></head><body></body></html>');
308308
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
309309

310-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MAIN_REQUEST, $response);
310+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
311311

312312
$cspHandler = $this->createMock(ContentSecurityPolicyHandler::class);
313313
$cspHandler->expects($this->once())
@@ -328,7 +328,7 @@ public function testCspIsKeptEnabledIfDumperWasNotUsed()
328328
$response = new Response('<html><head></head><body></body></html>');
329329
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
330330

331-
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MAIN_REQUEST, $response);
331+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
332332

333333
$cspHandler = $this->createMock(ContentSecurityPolicyHandler::class);
334334
$cspHandler->expects($this->never())
@@ -344,28 +344,6 @@ public function testCspIsKeptEnabledIfDumperWasNotUsed()
344344
$this->assertEquals("<html><head></head><body>\nWDT\n</body></html>", $response->getContent());
345345
}
346346

347-
protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'html', $hasSession = true)
348-
{
349-
$request = $this->getMockBuilder(Request::class)->setMethods(['getSession', 'isXmlHttpRequest', 'getRequestFormat'])->disableOriginalConstructor()->getMock();
350-
$request->expects($this->any())
351-
->method('isXmlHttpRequest')
352-
->willReturn($isXmlHttpRequest);
353-
$request->expects($this->any())
354-
->method('getRequestFormat')
355-
->willReturn($requestFormat);
356-
357-
$request->headers = new HeaderBag();
358-
359-
if ($hasSession) {
360-
$session = $this->createMock(Session::class);
361-
$request->expects($this->any())
362-
->method('getSession')
363-
->willReturn($session);
364-
}
365-
366-
return $request;
367-
}
368-
369347
protected function getTwigMock($render = 'WDT')
370348
{
371349
$templating = $this->createMock(Environment::class);

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ private function findAlternatives(string $name, iterable $collection): array
11471147
*/
11481148
public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
11491149
{
1150-
$this->defaultCommand = $commandName;
1150+
$this->defaultCommand = explode('|', ltrim($commandName, '|'))[0];
11511151

11521152
if ($isSingleCommand) {
11531153
// Ensure the command exist

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,25 @@ public function testCommandAttribute()
422422
$this->assertTrue($command->isHidden());
423423
$this->assertSame(['f'], $command->getAliases());
424424
}
425+
426+
/**
427+
* @requires PHP 8
428+
*/
429+
public function testDefaultCommand()
430+
{
431+
$apl = new Application();
432+
$apl->setDefaultCommand(Php8Command::getDefaultName());
433+
$property = new \ReflectionProperty($apl, 'defaultCommand');
434+
$property->setAccessible(true);
435+
436+
$this->assertEquals('foo', $property->getValue($apl));
437+
438+
$apl->setDefaultCommand(Php8Command2::getDefaultName());
439+
$property = new \ReflectionProperty($apl, 'defaultCommand');
440+
$property->setAccessible(true);
441+
442+
$this->assertEquals('foo2', $property->getValue($apl));
443+
}
425444
}
426445

427446
// In order to get an unbound closure, we should create it outside a class
@@ -437,3 +456,8 @@ function createClosure()
437456
class Php8Command extends Command
438457
{
439458
}
459+
460+
#[AsCommand(name: 'foo2', description: 'desc2', hidden: true)]
461+
class Php8Command2 extends Command
462+
{
463+
}

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
218218

219219
if (TaggedLocator::class === $attribute->getName()) {
220220
$attribute = $attribute->newInstance();
221-
$arguments[$index] = new ServiceLocatorArgument(new TaggedIteratorArgument($attribute->tag, $attribute->indexAttribute));
221+
$arguments[$index] = new ServiceLocatorArgument(new TaggedIteratorArgument($attribute->tag, $attribute->indexAttribute, null, true));
222222
break;
223223
}
224224
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumer;
3333
use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerConsumer;
3434
use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerFactory;
35+
use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerWithoutIndex;
3536
use Symfony\Component\DependencyInjection\Tests\Fixtures\TaggedService1;
3637
use Symfony\Component\DependencyInjection\Tests\Fixtures\TaggedService2;
3738
use Symfony\Component\DependencyInjection\Tests\Fixtures\TaggedService3;
@@ -403,6 +404,35 @@ public function testTaggedLocatorConfiguredViaAttribute()
403404
self::assertSame($container->get(FooTagClass::class), $locator->get('foo'));
404405
}
405406

407+
/**
408+
* @requires PHP 8
409+
*/
410+
public function testTaggedLocatorConfiguredViaAttributeWithoutIndex()
411+
{
412+
$container = new ContainerBuilder();
413+
$container->register(BarTagClass::class)
414+
->setPublic(true)
415+
->addTag('foo_bar')
416+
;
417+
$container->register(FooTagClass::class)
418+
->setPublic(true)
419+
->addTag('foo_bar')
420+
;
421+
$container->register(LocatorConsumerWithoutIndex::class)
422+
->setAutowired(true)
423+
->setPublic(true)
424+
;
425+
426+
$container->compile();
427+
428+
/** @var LocatorConsumerWithoutIndex $s */
429+
$s = $container->get(LocatorConsumerWithoutIndex::class);
430+
431+
$locator = $s->getLocator();
432+
self::assertSame($container->get(BarTagClass::class), $locator->get(BarTagClass::class));
433+
self::assertSame($container->get(FooTagClass::class), $locator->get(FooTagClass::class));
434+
}
435+
406436
/**
407437
* @requires PHP 8
408438
*/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
use Psr\Container\ContainerInterface;
15+
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
16+
17+
final class LocatorConsumerWithoutIndex
18+
{
19+
public function __construct(
20+
#[TaggedLocator('foo_bar')]
21+
private ContainerInterface $locator,
22+
) {
23+
}
24+
25+
public function getLocator(): ContainerInterface
26+
{
27+
return $this->locator;
28+
}
29+
}

0 commit comments

Comments
 (0)
0