Skip to content

Commit

Permalink
Replace use of deprecated TestCase::at() method (ref sebastianbergman…
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Aug 3, 2020
1 parent 3a43e51 commit dad12df
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 198 deletions.
198 changes: 83 additions & 115 deletions Tests/Client/ClientManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function testGetClientForConnectionAfterReauthenticating(): void
->with($connection)
->willReturn((string) $storageId);

// TODO - The mocks for `$this->clientStorage` need to be updated to not use the `at()` matcher
$this->clientStorage->expects($this->at(1))
->method('getClient')
->with($storageId)
Expand Down Expand Up @@ -133,35 +134,31 @@ public function testAllConnectionsForAUserCanBeFoundByUsername(): void
->method('getUsername')
->willReturn($username2);

$this->clientStorage->expects($this->at(0))
$this->clientStorage->expects($this->exactly(3))
->method('getStorageId')
->with($connection1)
->willReturn((string) $storageId1);

$this->clientStorage->expects($this->at(1))
->withConsecutive(
[$connection1],
[$connection2],
[$connection3]
)
->willReturnOnConsecutiveCalls(
(string) $storageId1,
(string) $storageId2,
(string) $storageId3
);

$this->clientStorage->expects($this->exactly(3))
->method('getClient')
->with($storageId1)
->willReturn($client1);

$this->clientStorage->expects($this->at(2))
->method('getStorageId')
->with($connection2)
->willReturn((string) $storageId2);

$this->clientStorage->expects($this->at(3))
->method('getClient')
->with($storageId2)
->willReturn($client2);

$this->clientStorage->expects($this->at(4))
->method('getStorageId')
->with($connection3)
->willReturn((string) $storageId3);

$this->clientStorage->expects($this->at(5))
->method('getClient')
->with($storageId3)
->willReturn($client3);
->withConsecutive(
[$storageId1],
[$storageId2],
[$storageId3]
)
->willReturnOnConsecutiveCalls(
$client1,
$client2,
$client3
);

/** @var MockObject|Topic $topic */
$topic = $this->createMock(Topic::class);
Expand Down Expand Up @@ -253,34 +250,27 @@ public function testFetchingAllConnectionsByDefaultOnlyReturnsAuthenticatedUsers
$authenticatedClient = $this->createMock(TokenInterface::class);
$guestClient = $this->createMock(AnonymousToken::class);

/*
* $this->at() uses the index of all calls to the mocked object, the indexing is:
*
* 0: getStorageId
* 1: getClient
* 2: getStorageId
* 3: getClient
*/

$this->clientStorage->expects($this->at(0))
->method('getStorageId')
->with($connection1)
->willReturn((string) $storageId1);

$this->clientStorage->expects($this->at(1))
->method('getClient')
->with($storageId1)
->willReturn($authenticatedClient);

$this->clientStorage->expects($this->at(2))
$this->clientStorage->expects($this->exactly(2))
->method('getStorageId')
->with($connection2)
->willReturn((string) $storageId2);
->withConsecutive(
[$connection1],
[$connection2]
)
->willReturnOnConsecutiveCalls(
(string) $storageId1,
(string) $storageId2
);

$this->clientStorage->expects($this->at(3))
$this->clientStorage->expects($this->exactly(2))
->method('getClient')
->with($storageId2)
->willReturn($guestClient);
->withConsecutive(
[$storageId1],
[$storageId2]
)
->willReturnOnConsecutiveCalls(
$authenticatedClient,
$guestClient
);

$topic = $this->createMock(Topic::class);
$topic->expects($this->once())
Expand Down Expand Up @@ -312,34 +302,27 @@ public function testFetchingAllConnectionsWithAnonymousFlagReturnsAllConnectedUs
/** @var MockObject|AnonymousToken $guestClient */
$guestClient = $this->createMock(AnonymousToken::class);

/*
* $this->at() uses the index of all calls to the mocked object, the indexing is:
*
* 0: getStorageId
* 1: getClient
* 2: getStorageId
* 3: getClient
*/

$this->clientStorage->expects($this->at(0))
->method('getStorageId')
->with($connection1)
->willReturn((string) $storageId1);

$this->clientStorage->expects($this->at(1))
->method('getClient')
->with($storageId1)
->willReturn($authenticatedClient);

$this->clientStorage->expects($this->at(2))
$this->clientStorage->expects($this->exactly(2))
->method('getStorageId')
->with($connection2)
->willReturn((string) $storageId2);
->withConsecutive(
[$connection1],
[$connection2]
)
->willReturnOnConsecutiveCalls(
(string) $storageId1,
(string) $storageId2
);

$this->clientStorage->expects($this->at(3))
$this->clientStorage->expects($this->exactly(2))
->method('getClient')
->with($storageId2)
->willReturn($guestClient);
->withConsecutive(
[$storageId1],
[$storageId2]
)
->willReturnOnConsecutiveCalls(
$authenticatedClient,
$guestClient
);

/** @var MockObject|Topic $topic */
$topic = $this->createMock(Topic::class);
Expand Down Expand Up @@ -391,46 +374,31 @@ public function testFetchingAllUsersWithDefinedRolesOnlyReturnsMatchingUsers():

$guestClient = $this->createMock(AnonymousToken::class);

/*
* $this->at() uses the index of all calls to the mocked object, the indexing is:
*
* 0: getStorageId
* 1: getClient
* 2: getStorageId
* 3: getClient
* 4: getStorageId
* 5: getClient
*/

$this->clientStorage->expects($this->at(0))
->method('getStorageId')
->with($connection1)
->willReturn((string) $storageId1);

$this->clientStorage->expects($this->at(1))
->method('getClient')
->with($storageId1)
->willReturn($authenticatedClient1);

$this->clientStorage->expects($this->at(2))
->method('getStorageId')
->with($connection2)
->willReturn((string) $storageId2);

$this->clientStorage->expects($this->at(3))
->method('getClient')
->with($storageId2)
->willReturn($authenticatedClient2);

$this->clientStorage->expects($this->at(4))
$this->clientStorage->expects($this->exactly(3))
->method('getStorageId')
->with($connection3)
->willReturn((string) $storageId3);

$this->clientStorage->expects($this->at(5))
->withConsecutive(
[$connection1],
[$connection2],
[$connection3]
)
->willReturnOnConsecutiveCalls(
(string) $storageId1,
(string) $storageId2,
(string) $storageId3
);

$this->clientStorage->expects($this->exactly(3))
->method('getClient')
->with($storageId3)
->willReturn($guestClient);
->withConsecutive(
[$storageId1],
[$storageId2],
[$storageId3]
)
->willReturnOnConsecutiveCalls(
$authenticatedClient1,
$authenticatedClient2,
$guestClient
);

$topic = $this->createMock(Topic::class);
$topic->expects($this->once())
Expand Down
35 changes: 10 additions & 25 deletions Tests/Client/Driver/DoctrineCacheDriverDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,40 @@ protected function setUp(): void

public function testDataIsRetrievedFromStorage(): void
{
$this->cache->expects($this->at(0))
$this->cache->expects($this->exactly(2))
->method('fetch')
->with('abc')
->willReturn('foo');

$this->cache->expects($this->at(1))
->method('fetch')
->with('def')
->willReturn(false);
->withConsecutive(['abc'], ['def'])
->willReturnOnConsecutiveCalls('foo', false);

$this->assertSame('foo', $this->driver->fetch('abc'));
$this->assertFalse($this->driver->fetch('def'));
}

public function testStorageContainsData(): void
{
$this->cache->expects($this->at(0))
->method('contains')
->with('abc')
->willReturn(true);

$this->cache->expects($this->at(1))
$this->cache->expects($this->exactly(2))
->method('contains')
->with('def')
->willReturn(false);
->withConsecutive(['abc'], ['def'])
->willReturnOnConsecutiveCalls(true, false);

$this->assertTrue($this->driver->contains('abc'));
$this->assertFalse($this->driver->contains('def'));
}

public function testDataIsSavedInStorage(): void
{
$this->cache->expects($this->at(0))
->method('save')
->with('abc')
->willReturn(true);

$this->cache->expects($this->at(1))
$this->cache->expects($this->exactly(2))
->method('save')
->with('def')
->willReturn(true);
->withConsecutive(['abc'], ['def'])
->willReturnOnConsecutiveCalls(true, true);

$this->assertTrue($this->driver->save('abc', 'data', 0));
$this->assertTrue($this->driver->save('def', 'data', 60));
}

public function testDataIsDeletedFromStorage(): void
{
$this->cache->expects($this->at(0))
$this->cache->expects($this->once())
->method('delete')
->with('abc')
->willReturn(true);
Expand Down
35 changes: 10 additions & 25 deletions Tests/Client/Driver/PredisDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,40 @@ protected function setUp(): void

public function testDataIsRetrievedFromStorage(): void
{
$this->predis->expects($this->at(0))
$this->predis->expects($this->exactly(2))
->method('__call')
->with('get', ['abc'])
->willReturn('foo');

$this->predis->expects($this->at(1))
->method('__call')
->with('get', ['def'])
->willReturn(null);
->withConsecutive(['get', ['abc']], ['get', ['def']])
->willReturnOnConsecutiveCalls('foo', null);

$this->assertSame('foo', $this->driver->fetch('abc'));
$this->assertNull($this->driver->fetch('def'));
}

public function testStorageContainsData(): void
{
$this->predis->expects($this->at(0))
->method('__call')
->with('exists', ['abc'])
->willReturn(1);

$this->predis->expects($this->at(1))
$this->predis->expects($this->exactly(2))
->method('__call')
->with('exists', ['def'])
->willReturn(0);
->withConsecutive(['exists', ['abc']], ['exists', ['def']])
->willReturnOnConsecutiveCalls(1, 0);

$this->assertTrue($this->driver->contains('abc'));
$this->assertFalse($this->driver->contains('def'));
}

public function testDataIsSavedInStorage(): void
{
$this->predis->expects($this->at(0))
$this->predis->expects($this->exactly(2))
->method('__call')
->with('set', ['abc', 'data'])
->willReturn(true);

$this->predis->expects($this->at(1))
->method('__call')
->with('setex', ['def', 60, 'data'])
->willReturn(true);
->withConsecutive(['set', ['abc', 'data']], ['setex', ['def', 60, 'data']])
->willReturnOnConsecutiveCalls(true, true);

$this->assertTrue($this->driver->save('abc', 'data', 0));
$this->assertTrue($this->driver->save('def', 'data', 60));
}

public function testDataIsDeletedFromStorage(): void
{
$this->predis->expects($this->at(0))
$this->predis->expects($this->once())
->method('__call')
->with('del', [['abc']])
->willReturn(true);
Expand Down
Loading

0 comments on commit dad12df

Please sign in to comment.