minor #37874 stop using the deprecated at() PHPUnit matcher (xabbuh)

This PR was merged into the 5.1 branch.

Discussion
----------

stop using the deprecated at() PHPUnit matcher

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Commits
-------

e36e73b9cf stop using the deprecated at() PHPUnit matcher
This commit is contained in:
Fabien Potencier 2020-09-01 14:25:21 +02:00
commit 3061bfeb48
3 changed files with 75 additions and 132 deletions

View File

@ -137,14 +137,10 @@ class CachingFactoryDecoratorTest extends TestCase
$list2 = new ArrayChoiceList([]); $list2 = new ArrayChoiceList([]);
$closure = function () {}; $closure = function () {};
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromChoices') ->method('createListFromChoices')
->with($choices, $closure) ->with($choices, $closure)
->willReturn($list1); ->willReturnOnConsecutiveCalls($list1, $list2);
$this->decoratedFactory->expects($this->at(1))
->method('createListFromChoices')
->with($choices, $closure)
->willReturn($list2);
$this->assertSame($list1, $this->factory->createListFromChoices($choices, $closure)); $this->assertSame($list1, $this->factory->createListFromChoices($choices, $closure));
$this->assertSame($list2, $this->factory->createListFromChoices($choices, $closure)); $this->assertSame($list2, $this->factory->createListFromChoices($choices, $closure));
@ -194,14 +190,10 @@ class CachingFactoryDecoratorTest extends TestCase
$list2 = new ArrayChoiceList([]); $list2 = new ArrayChoiceList([]);
$filter = function () {}; $filter = function () {};
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromChoices') ->method('createListFromChoices')
->with($choices, null, $filter) ->with($choices, null, $filter)
->willReturn($list1); ->willReturnOnConsecutiveCalls($list1, $list2);
$this->decoratedFactory->expects($this->at(1))
->method('createListFromChoices')
->with($choices, null, $filter)
->willReturn($list2);
$this->assertSame($list1, $this->factory->createListFromChoices($choices, null, $filter)); $this->assertSame($list1, $this->factory->createListFromChoices($choices, null, $filter));
$this->assertSame($list2, $this->factory->createListFromChoices($choices, null, $filter)); $this->assertSame($list2, $this->factory->createListFromChoices($choices, null, $filter));
@ -232,14 +224,13 @@ class CachingFactoryDecoratorTest extends TestCase
$closure1 = function () {}; $closure1 = function () {};
$closure2 = function () {}; $closure2 = function () {};
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromChoices') ->method('createListFromChoices')
->with($choices, null, $closure1) ->withConsecutive(
->willReturn($list1); [$choices, null, $closure1],
$this->decoratedFactory->expects($this->at(1)) [$choices, null, $closure2]
->method('createListFromChoices') )
->with($choices, null, $closure2) ->willReturnOnConsecutiveCalls($list1, $list2);
->willReturn($list2);
$this->assertSame($list1, $this->factory->createListFromChoices($choices, null, $closure1)); $this->assertSame($list1, $this->factory->createListFromChoices($choices, null, $closure1));
$this->assertSame($list2, $this->factory->createListFromChoices($choices, null, $closure2)); $this->assertSame($list2, $this->factory->createListFromChoices($choices, null, $closure2));
@ -251,16 +242,10 @@ class CachingFactoryDecoratorTest extends TestCase
$list = new ArrayChoiceList([]); $list = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]); $list2 = new ArrayChoiceList([]);
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromLoader') ->method('createListFromLoader')
->with($loader) ->with($loader)
->willReturn($list) ->willReturnOnConsecutiveCalls($list, $list2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createListFromLoader')
->with($loader)
->willReturn($list2)
;
$this->assertSame($list, $this->factory->createListFromLoader($loader)); $this->assertSame($list, $this->factory->createListFromLoader($loader));
$this->assertSame($list2, $this->factory->createListFromLoader($loader)); $this->assertSame($list2, $this->factory->createListFromLoader($loader));
@ -309,16 +294,10 @@ class CachingFactoryDecoratorTest extends TestCase
$list2 = new ArrayChoiceList([]); $list2 = new ArrayChoiceList([]);
$closure = function () {}; $closure = function () {};
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromLoader') ->method('createListFromLoader')
->with($loader, $closure) ->with($loader, $closure)
->willReturn($list) ->willReturnOnConsecutiveCalls($list, $list2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createListFromLoader')
->with($loader, $closure)
->willReturn($list2)
;
$this->assertSame($list, $this->factory->createListFromLoader(ChoiceList::loader($type, $loader), $closure)); $this->assertSame($list, $this->factory->createListFromLoader(ChoiceList::loader($type, $loader), $closure));
$this->assertSame($list2, $this->factory->createListFromLoader(ChoiceList::loader($type, $this->createMock(ChoiceLoaderInterface::class)), $closure)); $this->assertSame($list2, $this->factory->createListFromLoader(ChoiceList::loader($type, $this->createMock(ChoiceLoaderInterface::class)), $closure));
@ -376,16 +355,10 @@ class CachingFactoryDecoratorTest extends TestCase
$list2 = new ArrayChoiceList([]); $list2 = new ArrayChoiceList([]);
$closure = function () {}; $closure = function () {};
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromLoader') ->method('createListFromLoader')
->with($loader, null, $closure) ->with($loader, null, $closure)
->willReturn($list) ->willReturnOnConsecutiveCalls($list, $list2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createListFromLoader')
->with($loader, null, $closure)
->willReturn($list2)
;
$this->assertSame($list, $this->factory->createListFromLoader(ChoiceList::loader($type, $loader), null, $closure)); $this->assertSame($list, $this->factory->createListFromLoader(ChoiceList::loader($type, $loader), null, $closure));
$this->assertSame($list2, $this->factory->createListFromLoader(ChoiceList::loader($type, $this->createMock(ChoiceLoaderInterface::class)), null, $closure)); $this->assertSame($list2, $this->factory->createListFromLoader(ChoiceList::loader($type, $this->createMock(ChoiceLoaderInterface::class)), null, $closure));
@ -425,14 +398,13 @@ class CachingFactoryDecoratorTest extends TestCase
$closure1 = function () {}; $closure1 = function () {};
$closure2 = function () {}; $closure2 = function () {};
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromLoader') ->method('createListFromLoader')
->with($loader, null, $closure1) ->withConsecutive(
->willReturn($list1); [$loader, null, $closure1],
$this->decoratedFactory->expects($this->at(1)) [$loader, null, $closure2]
->method('createListFromLoader') )
->with($loader, null, $closure2) ->willReturnOnConsecutiveCalls($list1, $list2);
->willReturn($list2);
$this->assertSame($list1, $this->factory->createListFromLoader(ChoiceList::loader($type, $loader), null, $closure1)); $this->assertSame($list1, $this->factory->createListFromLoader(ChoiceList::loader($type, $loader), null, $closure1));
$this->assertSame($list2, $this->factory->createListFromLoader(ChoiceList::loader($type, $this->createMock(ChoiceLoaderInterface::class)), null, $closure2)); $this->assertSame($list2, $this->factory->createListFromLoader(ChoiceList::loader($type, $this->createMock(ChoiceLoaderInterface::class)), null, $closure2));
@ -445,16 +417,10 @@ class CachingFactoryDecoratorTest extends TestCase
$view = new ChoiceListView(); $view = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, $preferred) ->with($list, $preferred)
->willReturn($view) ->willReturnOnConsecutiveCalls($view, $view2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createView')
->with($list, $preferred)
->willReturn($view2)
;
$this->assertSame($view, $this->factory->createView($list, $preferred)); $this->assertSame($view, $this->factory->createView($list, $preferred));
$this->assertSame($view2, $this->factory->createView($list, $preferred)); $this->assertSame($view2, $this->factory->createView($list, $preferred));
@ -504,16 +470,10 @@ class CachingFactoryDecoratorTest extends TestCase
$view = new ChoiceListView(); $view = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, $preferred) ->with($list, $preferred)
->willReturn($view) ->willReturnOnConsecutiveCalls($view, $view2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createView')
->with($list, $preferred)
->willReturn($view2)
;
$this->assertSame($view, $this->factory->createView($list, $preferred)); $this->assertSame($view, $this->factory->createView($list, $preferred));
$this->assertSame($view2, $this->factory->createView($list, $preferred)); $this->assertSame($view2, $this->factory->createView($list, $preferred));
@ -563,16 +523,10 @@ class CachingFactoryDecoratorTest extends TestCase
$view = new ChoiceListView(); $view = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, $labels) ->with($list, null, $labels)
->willReturn($view) ->willReturnOnConsecutiveCalls($view, $view2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createView')
->with($list, null, $labels)
->willReturn($view2)
;
$this->assertSame($view, $this->factory->createView($list, null, $labels)); $this->assertSame($view, $this->factory->createView($list, null, $labels));
$this->assertSame($view2, $this->factory->createView($list, null, $labels)); $this->assertSame($view2, $this->factory->createView($list, null, $labels));
@ -622,16 +576,10 @@ class CachingFactoryDecoratorTest extends TestCase
$view = new ChoiceListView(); $view = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, null, $index) ->with($list, null, null, $index)
->willReturn($view) ->willReturnOnConsecutiveCalls($view, $view2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createView')
->with($list, null, null, $index)
->willReturn($view2)
;
$this->assertSame($view, $this->factory->createView($list, null, null, $index)); $this->assertSame($view, $this->factory->createView($list, null, null, $index));
$this->assertSame($view2, $this->factory->createView($list, null, null, $index)); $this->assertSame($view2, $this->factory->createView($list, null, null, $index));
@ -681,16 +629,10 @@ class CachingFactoryDecoratorTest extends TestCase
$view = new ChoiceListView(); $view = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, null, null, $groupBy) ->with($list, null, null, null, $groupBy)
->willReturn($view) ->willReturnOnConsecutiveCalls($view, $view2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createView')
->with($list, null, null, null, $groupBy)
->willReturn($view2)
;
$this->assertSame($view, $this->factory->createView($list, null, null, null, $groupBy)); $this->assertSame($view, $this->factory->createView($list, null, null, null, $groupBy));
$this->assertSame($view2, $this->factory->createView($list, null, null, null, $groupBy)); $this->assertSame($view2, $this->factory->createView($list, null, null, null, $groupBy));
@ -740,16 +682,10 @@ class CachingFactoryDecoratorTest extends TestCase
$view = new ChoiceListView(); $view = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, null, null, null, $attr) ->with($list, null, null, null, null, $attr)
->willReturn($view) ->willReturnOnConsecutiveCalls($view, $view2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createView')
->with($list, null, null, null, null, $attr)
->willReturn($view2)
;
$this->assertSame($view, $this->factory->createView($list, null, null, null, null, $attr)); $this->assertSame($view, $this->factory->createView($list, null, null, null, null, $attr));
$this->assertSame($view2, $this->factory->createView($list, null, null, null, null, $attr)); $this->assertSame($view2, $this->factory->createView($list, null, null, null, null, $attr));
@ -798,16 +734,10 @@ class CachingFactoryDecoratorTest extends TestCase
$view = new ChoiceListView(); $view = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, null, null, null, $attr) ->with($list, null, null, null, null, $attr)
->willReturn($view) ->willReturnOnConsecutiveCalls($view, $view2);
;
$this->decoratedFactory->expects($this->at(1))
->method('createView')
->with($list, null, null, null, null, $attr)
->willReturn($view2)
;
$this->assertSame($view, $this->factory->createView($list, null, null, null, null, $attr)); $this->assertSame($view, $this->factory->createView($list, null, null, null, null, $attr));
$this->assertSame($view2, $this->factory->createView($list, null, null, null, null, $attr)); $this->assertSame($view2, $this->factory->createView($list, null, null, null, null, $attr));

View File

@ -152,7 +152,11 @@ class CheckLdapCredentialsListenerTest extends TestCase
$query = $this->getMockBuilder(QueryInterface::class)->getMock(); $query = $this->getMockBuilder(QueryInterface::class)->getMock();
$query->expects($this->once())->method('execute')->willReturn($collection); $query->expects($this->once())->method('execute')->willReturn($collection);
$this->ldap->expects($this->at(0))->method('bind')->with('elsa', 'test1234A$'); $this->ldap
->method('bind')
->withConsecutive(
['elsa', 'test1234A$']
);
$this->ldap->expects($this->any())->method('escape')->with('Wouter', '', LdapInterface::ESCAPE_FILTER)->willReturn('wouter'); $this->ldap->expects($this->any())->method('escape')->with('Wouter', '', LdapInterface::ESCAPE_FILTER)->willReturn('wouter');
$this->ldap->expects($this->once())->method('query')->with('{username}', 'wouter_test')->willReturn($query); $this->ldap->expects($this->once())->method('query')->with('{username}', 'wouter_test')->willReturn($query);
@ -170,7 +174,11 @@ class CheckLdapCredentialsListenerTest extends TestCase
$query = $this->getMockBuilder(QueryInterface::class)->getMock(); $query = $this->getMockBuilder(QueryInterface::class)->getMock();
$query->expects($this->once())->method('execute')->willReturn($collection); $query->expects($this->once())->method('execute')->willReturn($collection);
$this->ldap->expects($this->at(0))->method('bind')->with('elsa', 'test1234A$'); $this->ldap
->method('bind')
->withConsecutive(
['elsa', 'test1234A$']
);
$this->ldap->expects($this->once())->method('query')->willReturn($query); $this->ldap->expects($this->once())->method('query')->willReturn($query);
$listener = $this->createListener(); $listener = $this->createListener();

View File

@ -198,31 +198,36 @@ class ConnectionTest extends TestCase
->method('getQueueUrl') ->method('getQueueUrl')
->with(['QueueName' => 'queue', 'QueueOwnerAWSAccountId' => 123]) ->with(['QueueName' => 'queue', 'QueueOwnerAWSAccountId' => 123])
->willReturn(ResultMockFactory::create(GetQueueUrlResult::class, ['QueueUrl' => 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue'])); ->willReturn(ResultMockFactory::create(GetQueueUrlResult::class, ['QueueUrl' => 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue']));
$client->expects($this->at(1)) $client->expects($this->exactly(2))
->method('receiveMessage') ->method('receiveMessage')
->with([ ->withConsecutive(
'QueueUrl' => 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue', [
'MaxNumberOfMessages' => 9, [
'WaitTimeSeconds' => 20, 'QueueUrl' => 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue',
'MessageAttributeNames' => ['All'], 'MaxNumberOfMessages' => 9,
'VisibilityTimeout' => null, 'WaitTimeSeconds' => 20,
]) 'MessageAttributeNames' => ['All'],
->willReturn(ResultMockFactory::create(ReceiveMessageResult::class, ['Messages' => [ 'VisibilityTimeout' => null,
new Message(['MessageId' => 1, 'Body' => 'this is a test']), ],
new Message(['MessageId' => 2, 'Body' => 'this is a test']), ],
new Message(['MessageId' => 3, 'Body' => 'this is a test']), [
]])); [
$client->expects($this->at(2)) 'QueueUrl' => 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue',
->method('receiveMessage') 'MaxNumberOfMessages' => 9,
->with([ 'WaitTimeSeconds' => 20,
'QueueUrl' => 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue', 'MessageAttributeNames' => ['All'],
'MaxNumberOfMessages' => 9, 'VisibilityTimeout' => null,
'WaitTimeSeconds' => 20, ],
'MessageAttributeNames' => ['All'], ]
'VisibilityTimeout' => null, )
]) ->willReturnOnConsecutiveCalls(
->willReturn(ResultMockFactory::create(ReceiveMessageResult::class, ['Messages' => [ ResultMockFactory::create(ReceiveMessageResult::class, ['Messages' => [
]])); new Message(['MessageId' => 1, 'Body' => 'this is a test']),
new Message(['MessageId' => 2, 'Body' => 'this is a test']),
new Message(['MessageId' => 3, 'Body' => 'this is a test']),
]]),
ResultMockFactory::create(ReceiveMessageResult::class, ['Messages' => []])
);
$connection = new Connection(['queue_name' => 'queue', 'account' => 123, 'auto_setup' => false], $client); $connection = new Connection(['queue_name' => 'queue', 'account' => 123, 'auto_setup' => false], $client);
$this->assertNotNull($connection->get()); $this->assertNotNull($connection->get());