Merge branch '5.1' into 5.2

* 5.1:
  More cleanups and fixes
This commit is contained in:
Nicolas Grekas 2021-01-27 12:19:04 +01:00
commit 8a7bf238d6
26 changed files with 108 additions and 106 deletions

View File

@ -19,20 +19,34 @@ use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormConfigInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\WebLink\Link;
use Twig\Environment;
class AbstractControllerTest extends TestCase
{
@ -103,7 +117,7 @@ class AbstractControllerTest extends TestCase
$requestStack = new RequestStack();
$requestStack->push($request);
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock();
$kernel = $this->createMock(HttpKernelInterface::class);
$kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) {
return new Response($request->getRequestFormat().'--'.$request->getLocale());
});
@ -161,7 +175,7 @@ class AbstractControllerTest extends TestCase
private function getContainerWithTokenStorage($token = null): Container
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage::class)->getMock();
$tokenStorage = $this->createMock(TokenStorage::class);
$tokenStorage
->expects($this->once())
->method('getToken')
@ -187,7 +201,7 @@ class AbstractControllerTest extends TestCase
{
$container = new Container();
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
$serializer = $this->createMock(SerializerInterface::class);
$serializer
->expects($this->once())
->method('serialize')
@ -208,7 +222,7 @@ class AbstractControllerTest extends TestCase
{
$container = new Container();
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
$serializer = $this->createMock(SerializerInterface::class);
$serializer
->expects($this->once())
->method('serialize')
@ -230,7 +244,7 @@ class AbstractControllerTest extends TestCase
public function testFile()
{
$container = new Container();
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock();
$kernel = $this->createMock(HttpKernelInterface::class);
$container->set('http_kernel', $kernel);
$controller = $this->createController();
@ -331,7 +345,7 @@ class AbstractControllerTest extends TestCase
public function testFileWhichDoesNotExist()
{
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class);
$this->expectException(FileNotFoundException::class);
$controller = $this->createController();
@ -340,7 +354,7 @@ class AbstractControllerTest extends TestCase
public function testIsGranted()
{
$authorizationChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface::class)->getMock();
$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(true);
$container = new Container();
@ -354,9 +368,9 @@ class AbstractControllerTest extends TestCase
public function testdenyAccessUnlessGranted()
{
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
$this->expectException(AccessDeniedException::class);
$authorizationChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface::class)->getMock();
$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(false);
$container = new Container();
@ -370,7 +384,7 @@ class AbstractControllerTest extends TestCase
public function testRenderViewTwig()
{
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
$twig = $this->createMock(Environment::class);
$twig->expects($this->once())->method('render')->willReturn('bar');
$container = new Container();
@ -384,7 +398,7 @@ class AbstractControllerTest extends TestCase
public function testRenderTwig()
{
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
$twig = $this->createMock(Environment::class);
$twig->expects($this->once())->method('render')->willReturn('bar');
$container = new Container();
@ -398,7 +412,7 @@ class AbstractControllerTest extends TestCase
public function testStreamTwig()
{
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
$twig = $this->createMock(Environment::class);
$container = new Container();
$container->set('twig', $twig);
@ -406,12 +420,12 @@ class AbstractControllerTest extends TestCase
$controller = $this->createController();
$controller->setContainer($container);
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\StreamedResponse::class, $controller->stream('foo'));
$this->assertInstanceOf(StreamedResponse::class, $controller->stream('foo'));
}
public function testRedirectToRoute()
{
$router = $this->getMockBuilder(\Symfony\Component\Routing\RouterInterface::class)->getMock();
$router = $this->createMock(RouterInterface::class);
$router->expects($this->once())->method('generate')->willReturn('/foo');
$container = new Container();
@ -421,7 +435,7 @@ class AbstractControllerTest extends TestCase
$controller->setContainer($container);
$response = $controller->redirectToRoute('foo');
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\RedirectResponse::class, $response);
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertSame('/foo', $response->getTargetUrl());
$this->assertSame(302, $response->getStatusCode());
}
@ -432,7 +446,7 @@ class AbstractControllerTest extends TestCase
public function testAddFlash()
{
$flashBag = new FlashBag();
$session = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\Session::class)->getMock();
$session = $this->createMock(Session::class);
$session->expects($this->once())->method('getFlashBag')->willReturn($flashBag);
$container = new Container();
@ -449,12 +463,12 @@ class AbstractControllerTest extends TestCase
{
$controller = $this->createController();
$this->assertInstanceOf(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class, $controller->createAccessDeniedException());
$this->assertInstanceOf(AccessDeniedException::class, $controller->createAccessDeniedException());
}
public function testIsCsrfTokenValid()
{
$tokenManager = $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock();
$tokenManager = $this->createMock(CsrfTokenManagerInterface::class);
$tokenManager->expects($this->once())->method('isTokenValid')->willReturn(true);
$container = new Container();
@ -468,7 +482,7 @@ class AbstractControllerTest extends TestCase
public function testGenerateUrl()
{
$router = $this->getMockBuilder(\Symfony\Component\Routing\RouterInterface::class)->getMock();
$router = $this->createMock(RouterInterface::class);
$router->expects($this->once())->method('generate')->willReturn('/foo');
$container = new Container();
@ -485,7 +499,7 @@ class AbstractControllerTest extends TestCase
$controller = $this->createController();
$response = $controller->redirect('https://dunglas.fr', 301);
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\RedirectResponse::class, $response);
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertSame('https://dunglas.fr', $response->getTargetUrl());
$this->assertSame(301, $response->getStatusCode());
}
@ -494,14 +508,14 @@ class AbstractControllerTest extends TestCase
{
$controller = $this->createController();
$this->assertInstanceOf(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class, $controller->createNotFoundException());
$this->assertInstanceOf(NotFoundHttpException::class, $controller->createNotFoundException());
}
public function testCreateForm()
{
$form = new Form($this->getMockBuilder(FormConfigInterface::class)->getMock());
$form = new Form($this->createMock(FormConfigInterface::class));
$formFactory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
$formFactory = $this->createMock(FormFactoryInterface::class);
$formFactory->expects($this->once())->method('create')->willReturn($form);
$container = new Container();
@ -515,9 +529,9 @@ class AbstractControllerTest extends TestCase
public function testCreateFormBuilder()
{
$formBuilder = $this->getMockBuilder(\Symfony\Component\Form\FormBuilderInterface::class)->getMock();
$formBuilder = $this->createMock(FormBuilderInterface::class);
$formFactory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
$formFactory = $this->createMock(FormFactoryInterface::class);
$formFactory->expects($this->once())->method('createBuilder')->willReturn($formBuilder);
$container = new Container();

View File

@ -239,7 +239,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromLoaderSameLoader()
{
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$loader = $this->createMock(ChoiceLoaderInterface::class);
$list = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]);
@ -270,8 +270,8 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromLoaderDifferentLoader()
{
$loader1 = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$loader2 = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$loader1 = $this->createMock(ChoiceLoaderInterface::class);
$loader2 = $this->createMock(ChoiceLoaderInterface::class);
$list1 = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]);
@ -289,7 +289,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromLoaderSameValueClosure()
{
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$loader = $this->createMock(ChoiceLoaderInterface::class);
$type = $this->createMock(FormTypeInterface::class);
$list = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]);
@ -329,7 +329,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromLoaderDifferentValueClosure()
{
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$loader = $this->createMock(ChoiceLoaderInterface::class);
$type = $this->createMock(FormTypeInterface::class);
$list1 = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]);
@ -350,7 +350,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromLoaderSameFilterClosure()
{
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$loader = $this->createMock(ChoiceLoaderInterface::class);
$type = $this->createMock(FormTypeInterface::class);
$list = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]);
@ -392,7 +392,7 @@ class CachingFactoryDecoratorTest extends TestCase
public function testCreateFromLoaderDifferentFilterClosure()
{
$loader = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$loader = $this->createMock(ChoiceLoaderInterface::class);
$type = $this->createMock(FormTypeInterface::class);
$list1 = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]);

View File

@ -267,7 +267,7 @@ class DefaultChoiceListFactoryTest extends TestCase
public function testCreateFromLoaderWithFilter()
{
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
$loader = $this->createMock(ChoiceLoaderInterface::class);
$filter = function () {};
$list = $this->factory->createListFromLoader($loader, null, $filter);

View File

@ -127,7 +127,7 @@ class PropertyAccessDecoratorTest extends TestCase
public function testCreateFromLoaderFilterPropertyPath()
{
$loader = $this->getMockBuilder(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class)->getMock();
$loader = $this->createMock(ChoiceLoaderInterface::class);
$filteredChoices = [
'two' => (object) ['property' => 'value 2', 'filter' => true],
];

View File

@ -11,7 +11,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
{
public function testLoadChoiceList()
{
$decorated = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$decorated = $this->createMock(ChoiceLoaderInterface::class);
$decorated->expects($this->once())
->method('loadChoiceList')
->willReturn(new ArrayChoiceList(range(1, 4)))
@ -28,7 +28,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
public function testLoadChoiceListWithGroupedChoices()
{
$decorated = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$decorated = $this->createMock(ChoiceLoaderInterface::class);
$decorated->expects($this->once())
->method('loadChoiceList')
->willReturn(new ArrayChoiceList(['units' => range(1, 9), 'tens' => range(10, 90, 10)]))
@ -54,7 +54,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
{
$evenValues = [1 => '2', 3 => '4'];
$decorated = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$decorated = $this->createMock(ChoiceLoaderInterface::class);
$decorated->expects($this->never())
->method('loadChoiceList')
;
@ -78,7 +78,7 @@ class FilterChoiceLoaderDecoratorTest extends TestCase
$evenChoices = [1 => 2, 3 => 4];
$values = array_map('strval', range(1, 4));
$decorated = $this->getMockBuilder(ChoiceLoaderInterface::class)->getMock();
$decorated = $this->createMock(ChoiceLoaderInterface::class);
$decorated->expects($this->never())
->method('loadChoiceList')
;

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormRendererEngineInterface;
use Symfony\Component\Form\FormView;
class FormRendererTest extends TestCase
@ -38,7 +39,7 @@ class FormRendererTest extends TestCase
$formView->vars['name'] = 'foo';
$formView->setRendered();
$engine = $this->getMockBuilder(\Symfony\Component\Form\FormRendererEngineInterface::class)->getMock();
$engine = $this->createMock(FormRendererEngineInterface::class);
$renderer = new FormRenderer($engine);
$renderer->searchAndRenderBlock($formView, 'row');
}

View File

@ -34,8 +34,8 @@ class MarshallingSessionHandlerTest extends TestCase
protected function setUp(): void
{
$this->marshaller = $this->getMockBuilder(MarshallerInterface::class)->getMock();
$this->handler = $this->getMockBuilder(AbstractSessionHandler::class)->getMock();
$this->marshaller = $this->createMock(MarshallerInterface::class);
$this->handler = $this->createMock(AbstractSessionHandler::class);
}
public function testOpen()

View File

@ -217,14 +217,14 @@ class SessionListenerTest extends TestCase
public function testSessionUsageExceptionIfStatelessAndSessionUsed()
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session = $this->createMock(Session::class);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$container = new Container();
$container->set('initialized_session', $session);
$listener = new SessionListener($container, true);
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
$kernel = $this->createMock(HttpKernelInterface::class);
$request = new Request();
$request->attributes->set('_stateless', true);
@ -236,10 +236,10 @@ class SessionListenerTest extends TestCase
public function testSessionUsageLogIfStatelessAndSessionUsed()
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session = $this->createMock(Session::class);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->exactly(1))->method('warning');
$container = new Container();
@ -247,7 +247,7 @@ class SessionListenerTest extends TestCase
$container->set('logger', $logger);
$listener = new SessionListener($container, false);
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
$kernel = $this->createMock(HttpKernelInterface::class);
$request = new Request();
$request->attributes->set('_stateless', true);
@ -258,7 +258,7 @@ class SessionListenerTest extends TestCase
public function testSessionIsSavedWhenUnexpectedSessionExceptionThrown()
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session = $this->createMock(Session::class);
$session->method('isStarted')->willReturn(true);
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
$session->expects($this->exactly(1))->method('save');
@ -267,7 +267,7 @@ class SessionListenerTest extends TestCase
$container->set('initialized_session', $session);
$listener = new SessionListener($container, true);
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
$kernel = $this->createMock(HttpKernelInterface::class);
$request = new Request();
$request->attributes->set('_stateless', true);
@ -281,7 +281,7 @@ class SessionListenerTest extends TestCase
public function testSessionUsageCallbackWhenDebugAndStateless()
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session = $this->createMock(Session::class);
$session->method('isStarted')->willReturn(true);
$session->expects($this->exactly(1))->method('save');
@ -308,7 +308,7 @@ class SessionListenerTest extends TestCase
public function testSessionUsageCallbackWhenNoDebug()
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session = $this->createMock(Session::class);
$session->method('isStarted')->willReturn(true);
$session->expects($this->exactly(0))->method('save');
@ -331,7 +331,7 @@ class SessionListenerTest extends TestCase
public function testSessionUsageCallbackWhenNoStateless()
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session = $this->createMock(Session::class);
$session->method('isStarted')->willReturn(true);
$session->expects($this->never())->method('save');

View File

@ -148,7 +148,7 @@ class CheckLdapCredentialsListenerTest extends TestCase
{
$collection = new \ArrayIterator([new Entry('')]);
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
$query = $this->createMock(QueryInterface::class);
$query->expects($this->once())->method('execute')->willReturn($collection);
$this->ldap
@ -168,9 +168,9 @@ class CheckLdapCredentialsListenerTest extends TestCase
$this->expectException(BadCredentialsException::class);
$this->expectExceptionMessage('The presented username is invalid.');
$collection = $this->getMockBuilder(CollectionInterface::class)->getMock();
$collection = $this->createMock(CollectionInterface::class);
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
$query = $this->createMock(QueryInterface::class);
$query->expects($this->once())->method('execute')->willReturn($collection);
$this->ldap

View File

@ -29,7 +29,7 @@ class AmazonSqsReceiverTest extends TestCase
$serializer = $this->createSerializer();
$sqsEnvelop = $this->createSqsEnvelope();
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$connection = $this->createMock(Connection::class);
$connection->method('get')->willReturn($sqsEnvelop);
$receiver = new AmazonSqsReceiver($connection, $serializer);
@ -46,7 +46,7 @@ class AmazonSqsReceiverTest extends TestCase
$serializer->method('decode')->willThrowException(new MessageDecodingFailedException());
$sqsEnvelop = $this->createSqsEnvelope();
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$connection = $this->createMock(Connection::class);
$connection->method('get')->willReturn($sqsEnvelop);
$connection->expects($this->once())->method('delete');

View File

@ -26,12 +26,10 @@ class AmazonSqsSenderTest extends TestCase
$envelope = new Envelope(new DummyMessage('Oy'));
$encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];
$connection = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
$connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers']);
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
$serializer = $this->createMock(SerializerInterface::class);
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);
$sender = new AmazonSqsSender($connection, $serializer);
@ -45,13 +43,11 @@ class AmazonSqsSenderTest extends TestCase
$encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];
$connection = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
$connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('send')
->with($encoded['body'], $encoded['headers'], 0, $stamp->getMessageGroupId(), $stamp->getMessageDeduplicationId());
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
$serializer = $this->createMock(SerializerInterface::class);
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);
$sender = new AmazonSqsSender($connection, $serializer);

View File

@ -32,8 +32,8 @@ class AmazonSqsTransportTest extends TestCase
public function testReceivesMessages()
{
$transport = $this->getTransport(
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(),
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock()
$serializer = $this->createMock(SerializerInterface::class),
$connection = $this->createMock(Connection::class)
);
$decodedMessage = new DummyMessage('Decoded.');
@ -60,8 +60,8 @@ class AmazonSqsTransportTest extends TestCase
private function getTransport(SerializerInterface $serializer = null, Connection $connection = null)
{
$serializer = $serializer ?: $this->getMockBuilder(SerializerInterface::class)->getMock();
$connection = $connection ?: $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$serializer = $serializer ?: $this->createMock(SerializerInterface::class);
$connection = $connection ?: $this->createMock(Connection::class);
return new AmazonSqsTransport($connection, $serializer);
}

View File

@ -42,7 +42,7 @@ class ConnectionTest extends TestCase
$awsKey = 'some_aws_access_key_value';
$awsSecret = 'some_aws_secret_value';
$region = 'eu-west-1';
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => $region, 'accessKeyId' => $awsKey, 'accessKeySecret' => $awsSecret], null, $httpClient)),
Connection::fromDsn('sqs://default/queue', [
@ -63,7 +63,7 @@ class ConnectionTest extends TestCase
public function testFromDsn()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
Connection::fromDsn('sqs://default/queue', [], $httpClient)
@ -72,7 +72,7 @@ class ConnectionTest extends TestCase
public function testDsnPrecedence()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue_dsn'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)),
Connection::fromDsn('sqs://key_dsn:secret_dsn@default/queue_dsn?region=us-east-2', ['region' => 'eu-west-3', 'queue_name' => 'queue_options', 'access_key' => 'key_option', 'secret_key' => 'secret_option'], $httpClient)
@ -81,7 +81,7 @@ class ConnectionTest extends TestCase
public function testFromDsnWithRegion()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'us-west-2', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
Connection::fromDsn('sqs://default/queue?region=us-west-2', [], $httpClient)
@ -99,7 +99,7 @@ class ConnectionTest extends TestCase
public function testFromDsnWithCustomEndpoint()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'endpoint' => 'https://localhost', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
Connection::fromDsn('sqs://localhost/queue', [], $httpClient)
@ -108,7 +108,7 @@ class ConnectionTest extends TestCase
public function testFromDsnWithSslMode()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'endpoint' => 'http://localhost', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
Connection::fromDsn('sqs://localhost/queue?sslmode=disable', [], $httpClient)
@ -117,7 +117,7 @@ class ConnectionTest extends TestCase
public function testFromDsnWithSslModeOnDefault()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
Connection::fromDsn('sqs://default/queue?sslmode=disable', [], $httpClient)
@ -126,7 +126,7 @@ class ConnectionTest extends TestCase
public function testFromDsnWithCustomEndpointAndPort()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'endpoint' => 'https://localhost:1234', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
Connection::fromDsn('sqs://localhost:1234/queue', [], $httpClient)
@ -135,7 +135,7 @@ class ConnectionTest extends TestCase
public function testFromDsnWithOptions()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['account' => '213', 'queue_name' => 'queue', 'buffer_size' => 1, 'wait_time' => 5, 'auto_setup' => false], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
Connection::fromDsn('sqs://default/213/queue', ['buffer_size' => 1, 'wait_time' => 5, 'auto_setup' => false], $httpClient)
@ -144,7 +144,7 @@ class ConnectionTest extends TestCase
public function testFromDsnWithQueryOptions()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['account' => '213', 'queue_name' => 'queue', 'buffer_size' => 1, 'wait_time' => 5, 'auto_setup' => false], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
Connection::fromDsn('sqs://default/213/queue?buffer_size=1&wait_time=5&auto_setup=0', [], $httpClient)
@ -153,7 +153,7 @@ class ConnectionTest extends TestCase
public function testFromDsnWithQueueNameOption()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
@ -168,7 +168,7 @@ class ConnectionTest extends TestCase
public function testFromDsnWithAccountAndEndpointOption()
{
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['account' => 12345], new SqsClient(['endpoint' => 'https://custom-endpoint.tld', 'region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),

View File

@ -18,9 +18,6 @@ use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpReceiver;
use Symfony\Component\Messenger\Bridge\Amqp\Transport\Connection;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Transport\AmqpExt\AmqpReceivedStamp;
use Symfony\Component\Messenger\Transport\AmqpExt\AmqpReceiver;
use Symfony\Component\Messenger\Transport\AmqpExt\Connection;
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Serializer as SerializerComponent;

View File

@ -18,10 +18,6 @@ use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpStamp;
use Symfony\Component\Messenger\Bridge\Amqp\Transport\Connection;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Transport\AmqpExt\AmqpSender;
use Symfony\Component\Messenger\Transport\AmqpExt\AmqpStamp;
use Symfony\Component\Messenger\Transport\AmqpExt\Connection;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
/**

View File

@ -31,7 +31,6 @@ use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection;
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
class ConnectionTest extends TestCase
{

View File

@ -20,9 +20,6 @@ use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection;
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransport;
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
class DoctrineTransportFactoryTest extends TestCase

View File

@ -226,7 +226,7 @@ class ConnectionTest extends TestCase
public function testClaimAbandonedMessageWithRaceCondition()
{
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();
$redis = $this->createMock(\Redis::class);
$redis->expects($this->exactly(3))->method('xreadgroup')
->withConsecutive(
@ -252,7 +252,7 @@ class ConnectionTest extends TestCase
public function testClaimAbandonedMessage()
{
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();
$redis = $this->createMock(\Redis::class);
$redis->expects($this->exactly(2))->method('xreadgroup')
->withConsecutive(
@ -346,7 +346,7 @@ class ConnectionTest extends TestCase
public function testDeleteAfterAck()
{
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();
$redis = $this->createMock(\Redis::class);
$redis->expects($this->exactly(1))->method('xack')
->with('queue', 'symfony', ['1'])

View File

@ -185,7 +185,7 @@ class DaoAuthenticationProviderTest extends TestCase
public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChanged()
{
$this->expectException(BadCredentialsException::class);
$user = $this->getMockBuilder(UserInterface::class)->getMock();
$user = $this->createMock(UserInterface::class);
$user->expects($this->once())
->method('getPassword')
->willReturn('foo')

View File

@ -118,7 +118,7 @@ class FormLoginAuthenticatorTest extends TestCase
*/
public function testHandleNonStringUsernameWithToString($postOnly)
{
$usernameObject = $this->getMockBuilder(DummyUserClass::class)->getMock();
$usernameObject = $this->createMock(DummyUserClass::class);
$usernameObject->expects($this->once())->method('__toString')->willReturn('someUsername');
$request = Request::create('/login_check', 'POST', ['_username' => $usernameObject, '_password' => 's$cr$t']);

View File

@ -22,9 +22,9 @@ class HttpBasicAuthenticatorTest extends TestCase
protected function setUp(): void
{
$this->userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
$this->encoderFactory = $this->getMockBuilder(EncoderFactoryInterface::class)->getMock();
$this->encoder = $this->getMockBuilder(PasswordEncoderInterface::class)->getMock();
$this->userProvider = $this->createMock(UserProviderInterface::class);
$this->encoderFactory = $this->createMock(EncoderFactoryInterface::class);
$this->encoder = $this->createMock(PasswordEncoderInterface::class);
$this->encoderFactory
->expects($this->any())
->method('getEncoder')

View File

@ -39,7 +39,7 @@ class RememberMeListenerTest extends TestCase
{
$this->rememberMeServices = $this->createMock(RememberMeServicesInterface::class);
$this->listener = new RememberMeListener($this->rememberMeServices);
$this->request = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
$this->request = $this->createMock(Request::class);
$this->response = $this->createMock(Response::class);
$this->token = $this->createMock(TokenInterface::class);
}

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Security\Http\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
@ -68,7 +69,7 @@ class SessionStrategyListenerTest extends TestCase
private function configurePreviousSession()
{
$session = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock();
$session = $this->createMock(SessionInterface::class);
$session->expects($this->any())
->method('getName')
->willReturn('test_session_name');

View File

@ -259,7 +259,7 @@ class AccessListenerTest extends TestCase
$tokenStorage,
$accessDecisionManager,
$accessMap,
$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),
$this->createMock(AuthenticationManagerInterface::class),
false
);
@ -288,7 +288,7 @@ class AccessListenerTest extends TestCase
$tokenStorage,
$accessDecisionManager,
$accessMap,
$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),
$this->createMock(AuthenticationManagerInterface::class),
false
);
@ -319,7 +319,7 @@ class AccessListenerTest extends TestCase
$tokenStorage,
$accessDecisionManager,
$accessMap,
$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),
$this->createMock(AuthenticationManagerInterface::class),
false
);

View File

@ -369,7 +369,7 @@ class ContextListenerTest extends TestCase
$tokenStorage = new TokenStorage();
$listener = new ContextListener($tokenStorage, [], 'context_key', null, null, null, [$tokenStorage, 'getToken']);
$listener(new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST));
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
}
protected function runSessionOnKernelResponse($newToken, $original = null)

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Serializer\Tests\Normalizer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Tests\Normalizer\Features\ObjectDummy;
/**
@ -26,7 +27,7 @@ class UnwrappinDenormalizerTest extends TestCase
protected function setUp(): void
{
$this->serializer = $this->getMockBuilder(\Symfony\Component\Serializer\Serializer::class)->getMock();
$this->serializer = $this->createMock(Serializer::class);
$this->denormalizer = new UnwrappingDenormalizer();
$this->denormalizer->setSerializer($this->serializer);
}