8000 Merge branch '5.1' into 5.2 · symfony/symfony@6f8b4cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f8b4cb

Browse files
committed
Merge branch '5.1' into 5.2
* 5.1: "export-ignore" contracts and phpunit-bridge [Console][Command] Fix Closure code binding when it is a static anonymous function Use class const in test [Security] [HttpFoundation] Use class const in test [PropertyInfo] Fix breaking change with has*(arguments...) methods
2 parents de714b9 + a933c3e commit 6f8b4cb

File tree

11 files changed

+47
-17
lines changed

11 files changed

+47
-17
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/src/Symfony/Contracts export-ignore
2+
/src/Symfony/Bridge/PhpUnit export-ignore

src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
2121
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
2222
use Symfony\Component\EventDispatcher\EventDispatcher;
23+
use Symfony\Component\HttpKernel\KernelInterface;
2324

2425
class WebProfilerExtensionTest extends TestCase
2526
{
@@ -51,7 +52,7 @@ protected function setUp(): void
5152
{
5253
parent::setUp();
5354

54-
$this->kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
55+
$this->kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
5556

5657
$this->container = new ContainerBuilder();
5758
$this->container->register('error_handler.error_renderer.html', HtmlErrorRenderer::class)->setPublic(true);
< 6293 button class="Button Button--iconOnly Button--invisible flex-shrink-0 flex-order-1" aria-label="Collapse file: src/Symfony/Component/Console/Command/Command.php">

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,14 @@ public function setCode(callable $code)
282282
if ($code instanceof \Closure) {
283283
$r = new \ReflectionFunction($code);
284284
if (null === $r->getClosureThis()) {
285-
$code = \Closure::bind($code, $this);
285+
set_error_handler(static function () {});
286+
try {
287+
if ($c = \Closure::bind($code, $this)) {
288+
$code = $c;
289+
}
290+
} finally {
291+
restore_error_handler();
292+
}
286293
}
287294
}
288295

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,18 @@ public function callableMethodCommand(InputInterface $input, OutputInterface $ou
391391
{
392392
$output->writeln('from the code...');
393393
}
394+
395+
public function testSetCodeWithStaticAnonymousFunction()
396+
{
397+
$command = new \TestCommand();
398+
$command->setCode(static function (InputInterface $input, OutputInterface $output) {
399+
$output->writeln(isset($this) ? 'bound' : 'not bound');
400+
});
401+
$tester = new CommandTester($command);
402+
$tester->execute([]);
403+
404+
$this->assertEquals('interact called'.\PHP_EOL.'not bound'.\PHP_EOL, $tester->getDisplay());
405+
}
394406
}
395407

396408
// In order to get an unbound closure, we should create it outside a class

src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
2121

2222
/**
23-
* Console logger test.
24-
*
2523
* @author Kévin Dunglas <dunglas@gmail.com>
2624
* @author Jordi Boggiano <j.boggiano@seld.be>
2725
*/
@@ -157,9 +155,9 @@ public function testContextReplacement()
157155
public function testObjectCastToString()
158156
{
159157
if (method_exists($this, 'createPartialMock')) {
160-
$dummy = $this->createPartialMock('Symfony\Component\Console\Tests\Logger\DummyTest', ['__toString']);
158+
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
161159
} else {
162-
$dummy = $this->createPartialMock('Symfony\Component\Console\Tests\Logger\DummyTest', ['__toString']);
160+
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
163161
}
164162
$dummy->method('__toString')->willReturn('DUMMY');
165163

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public function getReadInfo(string $class, string $property, array $context = []
296296
foreach ($this->accessorPrefixes as $prefix) {
297297
$methodName = $prefix.$camelProp;
298298

299-
if ($reflClass->hasMethod($methodName) && ($reflClass->getMethod($methodName)->getModifiers() & $this->methodReflectionFlags)) {
299+
if ($reflClass->hasMethod($methodName) && $reflClass->getMethod($methodName)->getModifiers() & $this->methodReflectionFlags && !$reflClass->getMethod($methodName)->getNumberOfRequiredParameters()) {
300300
$method = $reflClass->getMethod($methodName);
301301

302302
return new PropertyReadInfo(PropertyReadInfo::TYPE_METHOD, $methodName, $this->getReadVisiblityForMethod($method), $method->isStatic(), false);

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function testGetProperties()
8181
'xTotals',
8282
'YT',
8383
'date',
84+
'element',
8485
'c',
8586
'd',
8687
'e',
@@ -303,6 +304,7 @@ public function getReadableProperties()
303304
['id', true],
304305
['Guid', true],
305306
['guid', false],
307+
['element', false],
306308
];
307309
}
308310

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,8 @@ public function setDate(\DateTime $date)
233233
public function addDate(\DateTime $date)
234234
{
235235
}
236+
237+
public function hasElement(string $element): bool
238+
{
239+
}
236240
}

src/Symfony/Component/Security/Http/Tests/Authenticator/FormLoginAuthenticatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1617
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1718
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1819
use Symfony\Component\Security\Core\Security;
@@ -165,7 +166,7 @@ private function setUpAuthenticator(array $options = [])
165166

166167
private function createSession()
167168
{
168-
return $this->createMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
169+
return $this->createMock(SessionInterface::class);
169170
}
170171
}
171172

src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
use Symfony\Component\Security\Core\Authentication\Token\NullToken;
2020
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
2121
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
22+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2223
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
2324
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
2425
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
2526
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
27+
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
2628
use Symfony\Component\Security\Core\User\User;
2729
use Symfony\Component\Security\Http\AccessMapInterface;
2830
use Symfony\Component\Security\Http\Event\LazyResponseEvent;
@@ -32,7 +34,7 @@ class AccessListenerTest extends TestCase
3234
{
3335
public function testHandleWhenTheAccessDecisionManagerDecidesToRefuseAccess()
3436
{
35-
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
37+
$this->expectException(AccessDeniedException::class);
3638
$request = new Request();
3739

3840
$accessMap = $this->getMockBuilder(AccessMapInterface::class)->getMock();
@@ -43,7 +45,7 @@ public function testHandleWhenTheAccessDecisionManagerDecidesToRefuseAccess()
4345
->willReturn([['foo' => 'bar'], null])
4446
;
4547

46-
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
48+
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
4749
$token
4850
->expects($this->any())
4951
->method('isAuthenticated')
@@ -87,14 +89,14 @@ public function testHandleWhenTheTokenIsNotAuthenticated()
8789
->willReturn([['foo' => 'bar'], null])
8890
;
8991

90-
$notAuthenticatedToken = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
92+
$notAuthenticatedToken = $this->getMockBuilder(TokenInterface::class)->getMock();
9193
$notAuthenticatedToken
9294
->expects($this->any())
9395
->method('isAuthenticated')
9496
->willReturn(false)
9597
;
9698

97-
$authenticatedToken = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
99+
$authenticatedToken = $this->getMockBuilder(TokenInterface::class)->getMock();
98100
$authenticatedToken
99101
->expects($this->any())
100102
->method('isAuthenticated')
@@ -151,7 +153,7 @@ public function testHandleWhenThereIsNoAccessMapEntryMatchingTheRequest()
151153
->willReturn([null, null])
152154
;
153155

154-
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
156+
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
155157
$token
156158
->expects($this->never())
157159
->method('isAuthenticated')
@@ -206,7 +208,7 @@ public function testHandleWhenAccessMapReturnsEmptyAttributes()
206208

207209
public function testHandleWhenTheSecurityTokenStorageHasNoToken()
208210
{
209-
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException::class);
211+
$this->expectException(AuthenticationCredentialsNotFoundException::class);
210212
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();
211213
$tokenStorage
212214
->expects($this->any())
@@ -336,7 +338,7 @@ public function testHandleMWithultipleAttributesShouldBeHandledAsAnd()
336338
->willReturn([['foo' => 'bar', 'bar' => 'baz'], null])
337339
;
338340

339-
$authenticatedToken = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
341+
$authenticatedToken = $this->getMockBuilder(TokenInterface::class)->getMock();
340342
$authenticatedToken
341343
->expects($this->any())
342344
->method('isAuthenticated')
@@ -358,7 +360,7 @@ public function testHandleMWithultipleAttributesShouldBeHandledAsAnd()
358360
$tokenStorage,
359361
$accessDecisionManager,
360362
$accessMap,
361-
$this->createMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')
363+
$this->createMock(AuthenticationManagerInterface::class)
362364
);
363365

364366
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));

0 commit comments

Comments
 (0)
0