From 37cc16e3d8fd7685ee1618b0beae055bf63c5767 Mon Sep 17 00:00:00 2001 From: YaFou <33806646+YaFou@users.noreply.github.com> Date: Tue, 19 Jan 2021 20:11:07 +0100 Subject: [PATCH 1/5] [PropertyInfo] Fix breaking change with has*(arguments...) methods --- .../PropertyInfo/Extractor/ReflectionExtractor.php | 2 +- .../Tests/Extractor/ReflectionExtractorTest.php | 2 ++ src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index a4725ba3ce..2cb7c8cf5d 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -239,7 +239,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp foreach ($this->accessorPrefixes as $prefix) { $methodName = $prefix.$camelProp; - if ($reflClass->hasMethod($methodName) && ($reflClass->getMethod($methodName)->getModifiers() & $this->methodReflectionFlags)) { + if ($reflClass->hasMethod($methodName) && $reflClass->getMethod($methodName)->getModifiers() & $this->methodReflectionFlags && !$reflClass->getMethod($methodName)->getNumberOfRequiredParameters()) { $method = $reflClass->getMethod($methodName); return new PropertyReadInfo(PropertyReadInfo::TYPE_METHOD, $methodName, $this->getReadVisiblityForMethod($method), $method->isStatic(), false); diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php index 6998467e57..b4f861ce35 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php @@ -75,6 +75,7 @@ class ReflectionExtractorTest extends TestCase 'xTotals', 'YT', 'date', + 'element', 'c', 'd', 'e', @@ -291,6 +292,7 @@ class ReflectionExtractorTest extends TestCase ['id', true], ['Guid', true], ['guid', false], + ['element', false], ]; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php index bcec074438..d94148ddc3 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php @@ -130,6 +130,8 @@ class Dummy extends ParentDummy */ public $nestedIterators; + private $elements; + public static function getStatic() { } @@ -218,4 +220,8 @@ class Dummy extends ParentDummy public function addDate(\DateTime $date) { } + + public function hasElement(string $element): bool + { + } } From 4a98eeecdc4b32ee9655cf3b088b5f9dc9812a5b Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jan 2021 08:08:23 +0100 Subject: [PATCH 2/5] [Security] [HttpFoundation] Use class const in test --- .../Http/Tests/Authenticator/FormLoginAuthenticatorTest.php | 3 ++- .../Security/Http/Tests/Firewall/LogoutListenerTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Http/Tests/Authenticator/FormLoginAuthenticatorTest.php b/src/Symfony/Component/Security/Http/Tests/Authenticator/FormLoginAuthenticatorTest.php index bf466e794a..8853f61b57 100644 --- a/src/Symfony/Component/Security/Http/Tests/Authenticator/FormLoginAuthenticatorTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Authenticator/FormLoginAuthenticatorTest.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Security\Http\Tests\Authenticator; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Security\Core\Exception\BadCredentialsException; use Symfony\Component\Security\Core\Security; @@ -165,7 +166,7 @@ class FormLoginAuthenticatorTest extends TestCase private function createSession() { - return $this->createMock('Symfony\Component\HttpFoundation\Session\SessionInterface'); + return $this->createMock(SessionInterface::class); } } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/LogoutListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/LogoutListenerTest.php index 7d74ca63b8..0ddc86b878 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/LogoutListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/LogoutListenerTest.php @@ -19,6 +19,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Http\Event\LogoutEvent; use Symfony\Component\Security\Http\Firewall\LogoutListener; +use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface; use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface; class LogoutListenerTest extends TestCase @@ -183,7 +184,7 @@ class LogoutListenerTest extends TestCase $response = new Response(); $logoutSuccessHandler->expects($this->any())->method('onLogoutSuccess')->willReturn($response); - $handler = $this->createMock('Symfony\Component\Security\Http\Logout\LogoutHandlerInterface'); + $handler = $this->createMock(LogoutHandlerInterface::class); $handler->expects($this->once())->method('logout')->with($request, $response, $token); $listener->addHandler($handler); From 39181f4fdfecd45f671148b8b11bddd5e83ac3c2 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jan 2021 08:04:07 +0100 Subject: [PATCH 3/5] Use class const in test --- .../WebProfilerExtensionTest.php | 3 ++- .../Tests/Logger/ConsoleLoggerTest.php | 6 ++---- .../Tests/Firewall/AccessListenerTest.php | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php index c78f491b9b..555d67144a 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -20,6 +20,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\HttpKernel\KernelInterface; class WebProfilerExtensionTest extends TestCase { @@ -51,7 +52,7 @@ class WebProfilerExtensionTest extends TestCase { parent::setUp(); - $this->kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); + $this->kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); $this->container = new ContainerBuilder(); $this->container->register('error_handler.error_renderer.html', HtmlErrorRenderer::class)->setPublic(true); diff --git a/src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php b/src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php index 5066c426fe..ebf2d7aa13 100644 --- a/src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php +++ b/src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php @@ -20,8 +20,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tests\Fixtures\DummyOutput; /** - * Console logger test. - * * @author Kévin Dunglas * @author Jordi Boggiano */ @@ -157,9 +155,9 @@ class ConsoleLoggerTest extends TestCase public function testObjectCastToString() { if (method_exists($this, 'createPartialMock')) { - $dummy = $this->createPartialMock('Symfony\Component\Console\Tests\Logger\DummyTest', ['__toString']); + $dummy = $this->createPartialMock(DummyTest::class, ['__toString']); } else { - $dummy = $this->createPartialMock('Symfony\Component\Console\Tests\Logger\DummyTest', ['__toString']); + $dummy = $this->createPartialMock(DummyTest::class, ['__toString']); } $dummy->method('__toString')->willReturn('DUMMY'); diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php index 71731c5797..ccc0e6cdf4 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php @@ -18,7 +18,10 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; +use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException; use Symfony\Component\Security\Http\AccessMapInterface; use Symfony\Component\Security\Http\Event\LazyResponseEvent; use Symfony\Component\Security\Http\Firewall\AccessListener; @@ -27,7 +30,7 @@ class AccessListenerTest extends TestCase { public function testHandleWhenTheAccessDecisionManagerDecidesToRefuseAccess() { - $this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class); + $this->expectException(AccessDeniedException::class); $request = new Request(); $accessMap = $this->getMockBuilder(AccessMapInterface::class)->getMock(); @@ -38,7 +41,7 @@ class AccessListenerTest extends TestCase ->willReturn([['foo' => 'bar'], null]) ; - $token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock(); + $token = $this->getMockBuilder(TokenInterface::class)->getMock(); $token ->expects($this->any()) ->method('isAuthenticated') @@ -82,14 +85,14 @@ class AccessListenerTest extends TestCase ->willReturn([['foo' => 'bar'], null]) ; - $notAuthenticatedToken = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock(); + $notAuthenticatedToken = $this->getMockBuilder(TokenInterface::class)->getMock(); $notAuthenticatedToken ->expects($this->any()) ->method('isAuthenticated') ->willReturn(false) ; - $authenticatedToken = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock(); + $authenticatedToken = $this->getMockBuilder(TokenInterface::class)->getMock(); $authenticatedToken ->expects($this->any()) ->method('isAuthenticated') @@ -146,7 +149,7 @@ class AccessListenerTest extends TestCase ->willReturn([null, null]) ; - $token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock(); + $token = $this->getMockBuilder(TokenInterface::class)->getMock(); $token ->expects($this->never()) ->method('isAuthenticated') @@ -201,7 +204,7 @@ class AccessListenerTest extends TestCase public function testHandleWhenTheSecurityTokenStorageHasNoToken() { - $this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException::class); + $this->expectException(AuthenticationCredentialsNotFoundException::class); $tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); $tokenStorage ->expects($this->any()) @@ -241,7 +244,7 @@ class AccessListenerTest extends TestCase ->willReturn([['foo' => 'bar', 'bar' => 'baz'], null]) ; - $authenticatedToken = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock(); + $authenticatedToken = $this->getMockBuilder(TokenInterface::class)->getMock(); $authenticatedToken ->expects($this->any()) ->method('isAuthenticated') @@ -263,7 +266,7 @@ class AccessListenerTest extends TestCase $tokenStorage, $accessDecisionManager, $accessMap, - $this->createMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface') + $this->createMock(AuthenticationManagerInterface::class) ); $listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST)); From 18d426871e8854123063ff56dc3046fe1bd365ca Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Fri, 22 Jan 2021 09:23:15 +0100 Subject: [PATCH 4/5] [Console][Command] Fix Closure code binding when it is a static anonymous function --- src/Symfony/Component/Console/Command/Command.php | 9 ++++++++- .../Component/Console/Tests/Command/CommandTest.php | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index c2b1f4c7e9..71ad4a49e9 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -281,7 +281,14 @@ class Command if ($code instanceof \Closure) { $r = new \ReflectionFunction($code); if (null === $r->getClosureThis()) { - $code = \Closure::bind($code, $this); + set_error_handler(static function () {}); + try { + if ($c = \Closure::bind($code, $this)) { + $code = $c; + } + } finally { + restore_error_handler(); + } } } diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 34156f7b52..9e1ae05eb1 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -398,6 +398,18 @@ class CommandTest extends TestCase { $output->writeln('from the code...'); } + + public function testSetCodeWithStaticAnonymousFunction() + { + $command = new \TestCommand(); + $command->setCode(static function (InputInterface $input, OutputInterface $output) { + $output->writeln(isset($this) ? 'bound' : 'not bound'); + }); + $tester = new CommandTester($command); + $tester->execute([]); + + $this->assertEquals('interact called'.\PHP_EOL.'not bound'.\PHP_EOL, $tester->getDisplay()); + } } // In order to get an unbound closure, we should create it outside a class From 12e19a9a3d83565d27a670c77a15891c2cbca84a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 22 Jan 2021 10:53:35 +0100 Subject: [PATCH 5/5] "export-ignore" contracts and phpunit-bridge --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..c255f66722 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/src/Symfony/Contracts export-ignore +/src/Symfony/Bridge/PhpUnit export-ignore