More cleanups and fixes

This commit is contained in:
Nicolas Grekas 2021-01-27 12:24:50 +01:00
parent 8a7bf238d6
commit 0045fc480d
16 changed files with 41 additions and 43 deletions

View File

@ -28,7 +28,7 @@ class DoctrineOrmTypeGuesserTest extends TestCase
*/ */
public function testTypeGuesser(string $type, $expected) public function testTypeGuesser(string $type, $expected)
{ {
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock(); $classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata->fieldMappings['field'] = true; $classMetadata->fieldMappings['field'] = true;
$classMetadata->expects($this->once())->method('getTypeOfField')->with('field')->willReturn($type); $classMetadata->expects($this->once())->method('getTypeOfField')->with('field')->willReturn($type);

View File

@ -28,7 +28,7 @@ class SwitchUserTokenProcessorTest extends TestCase
{ {
$originalToken = new UsernamePasswordToken('original_user', 'password', 'provider', ['ROLE_SUPER_ADMIN']); $originalToken = new UsernamePasswordToken('original_user', 'password', 'provider', ['ROLE_SUPER_ADMIN']);
$switchUserToken = new SwitchUserToken('user', 'passsword', 'provider', ['ROLE_USER'], $originalToken); $switchUserToken = new SwitchUserToken('user', 'passsword', 'provider', ['ROLE_USER'], $originalToken);
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); $tokenStorage = $this->createMock(TokenStorageInterface::class);
$tokenStorage->method('getToken')->willReturn($switchUserToken); $tokenStorage->method('getToken')->willReturn($switchUserToken);
$processor = new SwitchUserTokenProcessor($tokenStorage); $processor = new SwitchUserTokenProcessor($tokenStorage);

View File

@ -57,7 +57,7 @@ class EarlyExpirationDispatcherTest extends TestCase
$reverseContainer = new ReverseContainer($container, new ServiceLocator([])); $reverseContainer = new ReverseContainer($container, new ServiceLocator([]));
$bus = $this->getMockBuilder(MessageBusInterface::class)->getMock(); $bus = $this->createMock(MessageBusInterface::class);
$dispatcher = new EarlyExpirationDispatcher($bus, $reverseContainer); $dispatcher = new EarlyExpirationDispatcher($bus, $reverseContainer);
@ -107,7 +107,7 @@ class EarlyExpirationDispatcherTest extends TestCase
$reverseContainer = new ReverseContainer($container, new ServiceLocator([])); $reverseContainer = new ReverseContainer($container, new ServiceLocator([]));
$msg = EarlyExpirationMessage::create($reverseContainer, $computationService, $item, $pool); $msg = EarlyExpirationMessage::create($reverseContainer, $computationService, $item, $pool);
$bus = $this->getMockBuilder(MessageBusInterface::class)->getMock(); $bus = $this->createMock(MessageBusInterface::class);
$bus->expects($this->once()) $bus->expects($this->once())
->method('dispatch') ->method('dispatch')
->with($msg) ->with($msg)

View File

@ -1603,7 +1603,7 @@ class ViolationMapperTest extends TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock()
; ;
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock(); $translator = $this->createMock(TranslatorInterface::class);
$translator->expects($this->any())->method('trans')->willReturnMap([ $translator->expects($this->any())->method('trans')->willReturnMap([
['Name', [], null, null, 'Custom Name'], ['Name', [], null, null, 'Custom Name'],
]); ]);
@ -1630,7 +1630,7 @@ class ViolationMapperTest extends TestCase
public function testMessageWithLabel2() public function testMessageWithLabel2()
{ {
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock(); $translator = $this->createMock(TranslatorInterface::class);
$translator->expects($this->any())->method('trans')->willReturnMap([ $translator->expects($this->any())->method('trans')->willReturnMap([
['options_label', [], null, null, 'Translated Label'], ['options_label', [], null, null, 'Translated Label'],
]); ]);
@ -1668,7 +1668,7 @@ class ViolationMapperTest extends TestCase
public function testMessageWithLabelFormat1() public function testMessageWithLabelFormat1()
{ {
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock(); $translator = $this->createMock(TranslatorInterface::class);
$translator->expects($this->any())->method('trans')->willReturnMap([ $translator->expects($this->any())->method('trans')->willReturnMap([
['form.custom', [], null, null, 'Translated 1st Custom Label'], ['form.custom', [], null, null, 'Translated 1st Custom Label'],
]); ]);
@ -1706,7 +1706,7 @@ class ViolationMapperTest extends TestCase
public function testMessageWithLabelFormat2() public function testMessageWithLabelFormat2()
{ {
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock(); $translator = $this->createMock(TranslatorInterface::class);
$translator->expects($this->any())->method('trans')->willReturnMap([ $translator->expects($this->any())->method('trans')->willReturnMap([
['form_custom-id', [], null, null, 'Translated 2nd Custom Label'], ['form_custom-id', [], null, null, 'Translated 2nd Custom Label'],
]); ]);
@ -1793,7 +1793,7 @@ class ViolationMapperTest extends TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock()
; ;
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock(); $translator = $this->createMock(TranslatorInterface::class);
$translator->expects($this->never())->method('trans'); $translator->expects($this->never())->method('trans');
$this->mapper = new ViolationMapper($renderer, $translator); $this->mapper = new ViolationMapper($renderer, $translator);

View File

@ -54,7 +54,7 @@ class LockFactoryTest extends TestCase
public function testCreateLockFromKey() public function testCreateLockFromKey()
{ {
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$store->expects($this->any())->method('exists')->willReturn(false); $store->expects($this->any())->method('exists')->willReturn(false);
$keys = []; $keys = [];
@ -68,7 +68,7 @@ class LockFactoryTest extends TestCase
})) }))
->willReturn(true); ->willReturn(true);
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $logger = $this->createMock(LoggerInterface::class);
$factory = new LockFactory($store); $factory = new LockFactory($store);
$factory->setLogger($logger); $factory->setLogger($logger);

View File

@ -63,7 +63,7 @@ class LockTest extends TestCase
public function testAcquireBlockingWithPersistingStoreInterface() public function testAcquireBlockingWithPersistingStoreInterface()
{ {
$key = new Key(uniqid(__METHOD__, true)); $key = new Key(uniqid(__METHOD__, true));
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$lock = new Lock($key, $store); $lock = new Lock($key, $store);
$store $store
@ -79,7 +79,7 @@ class LockTest extends TestCase
public function testAcquireBlockingRetryWithPersistingStoreInterface() public function testAcquireBlockingRetryWithPersistingStoreInterface()
{ {
$key = new Key(uniqid(__METHOD__, true)); $key = new Key(uniqid(__METHOD__, true));
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$lock = new Lock($key, $store); $lock = new Lock($key, $store);
$store $store

View File

@ -90,7 +90,7 @@ class ConnectionTest extends TestCase
public function testFromDsnAsQueueUrl() public function testFromDsnAsQueueUrl()
{ {
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); $httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals( $this->assertEquals(
new Connection(['queue_name' => 'ab1-MyQueue-A2BCDEF3GHI4', 'account' => '123456789012'], new SqsClient(['region' => 'us-east-2', 'endpoint' => 'https://sqs.us-east-2.amazonaws.com', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient), 'https://sqs.us-east-2.amazonaws.com/123456789012/ab1-MyQueue-A2BCDEF3GHI4'), new Connection(['queue_name' => 'ab1-MyQueue-A2BCDEF3GHI4', 'account' => '123456789012'], new SqsClient(['region' => 'us-east-2', 'endpoint' => 'https://sqs.us-east-2.amazonaws.com', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient), 'https://sqs.us-east-2.amazonaws.com/123456789012/ab1-MyQueue-A2BCDEF3GHI4'),
Connection::fromDsn('https://sqs.us-east-2.amazonaws.com/123456789012/ab1-MyQueue-A2BCDEF3GHI4', [], $httpClient) Connection::fromDsn('https://sqs.us-east-2.amazonaws.com/123456789012/ab1-MyQueue-A2BCDEF3GHI4', [], $httpClient)
@ -304,7 +304,7 @@ class ConnectionTest extends TestCase
public function testGetQueueUrlNotCalled() public function testGetQueueUrlNotCalled()
{ {
$client = $this->getMockBuilder(SqsClient::class)->getMock(); $client = $this->createMock(SqsClient::class);
$connection = new Connection(['queue_name' => 'ab1-MyQueue-A2BCDEF3GHI4', 'account' => '123456789012'], $client, 'https://sqs.us-east-2.amazonaws.com/123456789012/ab1-MyQueue-A2BCDEF3GHI4'); $connection = new Connection(['queue_name' => 'ab1-MyQueue-A2BCDEF3GHI4', 'account' => '123456789012'], $client, 'https://sqs.us-east-2.amazonaws.com/123456789012/ab1-MyQueue-A2BCDEF3GHI4');
$client->expects($this->never())->method('getQueueUrl'); $client->expects($this->never())->method('getQueueUrl');

View File

@ -32,7 +32,7 @@ final class BeanstalkdReceiverTest extends TestCase
$tube = 'foo bar'; $tube = 'foo bar';
$beanstalkdEnvelope = $this->createBeanstalkdEnvelope(); $beanstalkdEnvelope = $this->createBeanstalkdEnvelope();
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); $connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('get')->willReturn($beanstalkdEnvelope); $connection->expects($this->once())->method('get')->willReturn($beanstalkdEnvelope);
$connection->expects($this->once())->method('getTube')->willReturn($tube); $connection->expects($this->once())->method('getTube')->willReturn($tube);
@ -53,7 +53,7 @@ final class BeanstalkdReceiverTest extends TestCase
{ {
$serializer = $this->createSerializer(); $serializer = $this->createSerializer();
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); $connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('get')->willReturn(null); $connection->expects($this->once())->method('get')->willReturn(null);
$receiver = new BeanstalkdReceiver($connection, $serializer); $receiver = new BeanstalkdReceiver($connection, $serializer);
@ -70,7 +70,7 @@ final class BeanstalkdReceiverTest extends TestCase
$serializer->expects($this->once())->method('decode')->willThrowException(new MessageDecodingFailedException()); $serializer->expects($this->once())->method('decode')->willThrowException(new MessageDecodingFailedException());
$beanstalkdEnvelope = $this->createBeanstalkdEnvelope(); $beanstalkdEnvelope = $this->createBeanstalkdEnvelope();
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); $connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('get')->willReturn($beanstalkdEnvelope); $connection->expects($this->once())->method('get')->willReturn($beanstalkdEnvelope);
$connection->expects($this->once())->method('reject'); $connection->expects($this->once())->method('reject');

View File

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

View File

@ -361,7 +361,7 @@ class ConnectionTest extends TestCase
public function testDeleteAfterReject() public function testDeleteAfterReject()
{ {
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock(); $redis = $this->createMock(\Redis::class);
$redis->expects($this->exactly(1))->method('xack') $redis->expects($this->exactly(1))->method('xack')
->with('queue', 'symfony', ['1']) ->with('queue', 'symfony', ['1'])

View File

@ -250,7 +250,7 @@ class WorkerTest extends TestCase
$envelope = new Envelope(new DummyMessage('Hello')); $envelope = new Envelope(new DummyMessage('Hello'));
$receiver = new DummyReceiver([[$envelope]]); $receiver = new DummyReceiver([[$envelope]]);
$bus = $this->getMockBuilder(MessageBusInterface::class)->getMock(); $bus = $this->createMock(MessageBusInterface::class);
$bus->method('dispatch')->willReturnArgument(0); $bus->method('dispatch')->willReturnArgument(0);
$eventDispatcher = new EventDispatcher(); $eventDispatcher = new EventDispatcher();

View File

@ -71,7 +71,7 @@ class UserValueResolverTest extends TestCase
public function testResolveWithAttribute() public function testResolveWithAttribute()
{ {
$user = $this->getMockBuilder(UserInterface::class)->getMock(); $user = $this->createMock(UserInterface::class);
$token = new UsernamePasswordToken($user, 'password', 'provider'); $token = new UsernamePasswordToken($user, 'password', 'provider');
$tokenStorage = new TokenStorage(); $tokenStorage = new TokenStorage();
$tokenStorage->setToken($token); $tokenStorage->setToken($token);

View File

@ -98,7 +98,7 @@ class UsernamePasswordJsonAuthenticationListenerTest extends TestCase
{ {
$this->createListener([], false, true, false); $this->createListener([], false, true, false);
$request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": "foo"}'); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": "foo"}');
$event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); $event = new RequestEvent($this->createMock(KernelInterface::class), $request, KernelInterface::MASTER_REQUEST);
($this->listener)($event); ($this->listener)($event);
$this->assertSame(['error' => 'An authentication exception occurred.'], json_decode($event->getResponse()->getContent(), true)); $this->assertSame(['error' => 'An authentication exception occurred.'], json_decode($event->getResponse()->getContent(), true));

View File

@ -25,7 +25,7 @@ class SemaphoreFactoryTest extends TestCase
{ {
public function testCreateSemaphore() public function testCreateSemaphore()
{ {
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$keys = []; $keys = [];
$store $store
@ -38,7 +38,7 @@ class SemaphoreFactoryTest extends TestCase
})) }))
->willReturn(true); ->willReturn(true);
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $logger = $this->createMock(LoggerInterface::class);
$factory = new SemaphoreFactory($store); $factory = new SemaphoreFactory($store);
$factory->setLogger($logger); $factory->setLogger($logger);
@ -54,7 +54,7 @@ class SemaphoreFactoryTest extends TestCase
public function testCreateSemaphoreFromKey() public function testCreateSemaphoreFromKey()
{ {
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$keys = []; $keys = [];
$store $store
@ -67,7 +67,7 @@ class SemaphoreFactoryTest extends TestCase
})) }))
->willReturn(true); ->willReturn(true);
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $logger = $this->createMock(LoggerInterface::class);
$factory = new SemaphoreFactory($store); $factory = new SemaphoreFactory($store);
$factory->setLogger($logger); $factory->setLogger($logger);

View File

@ -29,7 +29,7 @@ class SemaphoreTest extends TestCase
public function testAcquireReturnsTrue() public function testAcquireReturnsTrue()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store); $semaphore = new Semaphore($key, $store);
$store $store
@ -45,7 +45,7 @@ class SemaphoreTest extends TestCase
public function testAcquireReturnsFalse() public function testAcquireReturnsFalse()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store); $semaphore = new Semaphore($key, $store);
$store $store
@ -62,7 +62,7 @@ class SemaphoreTest extends TestCase
public function testAcquireThrowException() public function testAcquireThrowException()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store); $semaphore = new Semaphore($key, $store);
$store $store
@ -81,7 +81,7 @@ class SemaphoreTest extends TestCase
public function testRefresh() public function testRefresh()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store, 10.0); $semaphore = new Semaphore($key, $store, 10.0);
$store $store
@ -97,7 +97,7 @@ class SemaphoreTest extends TestCase
public function testRefreshWithCustomTtl() public function testRefreshWithCustomTtl()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store, 10.0); $semaphore = new Semaphore($key, $store, 10.0);
$store $store
@ -113,7 +113,7 @@ class SemaphoreTest extends TestCase
public function testRefreshWhenItFails() public function testRefreshWhenItFails()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store); $semaphore = new Semaphore($key, $store);
$store $store
@ -132,7 +132,7 @@ class SemaphoreTest extends TestCase
public function testRefreshWhenItFailsHard() public function testRefreshWhenItFailsHard()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store); $semaphore = new Semaphore($key, $store);
$store $store
@ -151,7 +151,7 @@ class SemaphoreTest extends TestCase
public function testRelease() public function testRelease()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store); $semaphore = new Semaphore($key, $store);
$store $store
@ -166,7 +166,7 @@ class SemaphoreTest extends TestCase
public function testReleaseWhenItFails() public function testReleaseWhenItFails()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store); $semaphore = new Semaphore($key, $store);
$store $store
@ -185,7 +185,7 @@ class SemaphoreTest extends TestCase
public function testReleaseWhenItFailsHard() public function testReleaseWhenItFailsHard()
{ {
$key = new Key('key', 1); $key = new Key('key', 1);
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$semaphore = new Semaphore($key, $store); $semaphore = new Semaphore($key, $store);
$store $store
@ -241,7 +241,7 @@ class SemaphoreTest extends TestCase
public function testExpiration() public function testExpiration()
{ {
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$key = new Key('key', 1); $key = new Key('key', 1);
$semaphore = new Semaphore($key, $store); $semaphore = new Semaphore($key, $store);
@ -258,7 +258,7 @@ class SemaphoreTest extends TestCase
*/ */
public function testExpirationResetAfter() public function testExpirationResetAfter()
{ {
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $store = $this->createMock(PersistingStoreInterface::class);
$key = new Key('key', 1); $key = new Key('key', 1);
$semaphore = new Semaphore($key, $store, 1); $semaphore = new Semaphore($key, $store, 1);

View File

@ -322,7 +322,7 @@ class AbstractObjectNormalizerTest extends TestCase
private function getDenormalizerForObjectWithBasicProperties() private function getDenormalizerForObjectWithBasicProperties()
{ {
$extractor = $this->getMockBuilder(PhpDocExtractor::class)->getMock(); $extractor = $this->createMock(PhpDocExtractor::class);
$extractor->method('getTypes') $extractor->method('getTypes')
->will($this->onConsecutiveCalls( ->will($this->onConsecutiveCalls(
[new Type('bool')], [new Type('bool')],