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
This commit is contained in:
commit
6f8b4cbfe6
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/src/Symfony/Contracts export-ignore
|
||||
/src/Symfony/Bridge/PhpUnit export-ignore
|
@ -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);
|
||||
|
@ -282,7 +282,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -391,6 +391,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
|
||||
|
@ -20,8 +20,6 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
|
||||
|
||||
/**
|
||||
* Console logger test.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
@ -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');
|
||||
|
||||
|
@ -296,7 +296,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);
|
||||
|
@ -81,6 +81,7 @@ class ReflectionExtractorTest extends TestCase
|
||||
'xTotals',
|
||||
'YT',
|
||||
'date',
|
||||
'element',
|
||||
'c',
|
||||
'd',
|
||||
'e',
|
||||
@ -303,6 +304,7 @@ class ReflectionExtractorTest extends TestCase
|
||||
['id', true],
|
||||
['Guid', true],
|
||||
['guid', false],
|
||||
['element', false],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -233,4 +233,8 @@ class Dummy extends ParentDummy
|
||||
public function addDate(\DateTime $date)
|
||||
{
|
||||
}
|
||||
|
||||
public function hasElement(string $element): bool
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,12 @@ use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterfac
|
||||
use Symfony\Component\Security\Core\Authentication\Token\NullToken;
|
||||
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\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
|
||||
use Symfony\Component\Security\Core\User\User;
|
||||
use Symfony\Component\Security\Http\AccessMapInterface;
|
||||
use Symfony\Component\Security\Http\Event\LazyResponseEvent;
|
||||
@ -32,7 +34,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();
|
||||
@ -43,7 +45,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')
|
||||
@ -87,14 +89,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')
|
||||
@ -151,7 +153,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')
|
||||
@ -206,7 +208,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())
|
||||
@ -336,7 +338,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')
|
||||
@ -358,7 +360,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));
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user