Fix integration tests on PHP 5.6

As stated in the documentation for "uasort", "if two members compare as
equal, their relative order in the sorted array is undefined". "uasort"
is used in "RoomController" to sort the participants of a room by their
last ping, so when two participants have the same last ping they could
be returned in any order.

Although undefined, the order is probably consistent (so, whatever the
order is, it is the same between different executions for the same
data). When using PHP 7 the participants are sorted in the same order
that currently appears in the integration test definitions. However, PHP
5.6 uses a different order, so the tests fail in that case.

This commit adds sorting of the participants in a room returned by the
server, so they can be checked against the expected participant list no
matter the order used by the server; the list is sorted by default, but
that behaviour can be prevented adding ` [exact order]` to the
participant list in a test definition, so the participant list can be
checked in the exact order returned by the server too (for example, if
needed to check the participant list after setting the last ping for
them).

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2017-09-18 17:26:14 +02:00
Родитель 5a1f0cd2fc
Коммит ee58fbeb75
1 изменённых файлов: 22 добавлений и 5 удалений

Просмотреть файл

@ -80,16 +80,33 @@ class FeatureContext implements Context, SnippetAcceptingContext {
PHPUnit_Framework_Assert::assertCount(count($formData->getHash()), $rooms, 'Room count does not match');
PHPUnit_Framework_Assert::assertEquals($formData->getHash(), array_map(function($room) {
PHPUnit_Framework_Assert::assertEquals($formData->getHash(), array_map(function($room, $expectedRoom) {
$participantNames = array_map(function($participant) {
return $participant['name'];
}, $room['participants']);
// When participants have the same last ping the order in which they
// are returned from the server is undefined. That is the most
// common case during the tests, so by default the list of
// participants returned by the server is sorted alphabetically. In
// order to check the exact order of participants returned by the
// server " [exact order]" can be appended in the test definition to
// the list of expected participants of the room.
if (strpos($expectedRoom['participants'], ' [exact order]') === false) {
sort($participantNames);
} else {
// Append " [exact order]" to the last participant so the
// imploded string is the same as the expected one.
$participantNames[end(array_keys($participantNames))] .= ' [exact order]';
}
return [
'id' => self::$tokenToIdentifier[$room['token']],
'type' => (string) $room['type'],
'participantType' => (string) $room['participantType'],
'participants' => implode(', ', array_map(function($participant) {
return $participant['name'];
}, $room['participants'])),
'participants' => implode(', ', $participantNames),
];
}, $rooms));
}, $rooms, $formData->getHash()));
}
/**