Skip to content

Commit

Permalink
Fix unit test for php 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Jun 26, 2024
1 parent 526fb9a commit 1562254
Showing 1 changed file with 23 additions and 42 deletions.
65 changes: 23 additions & 42 deletions tests/Goridge/RPCTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,61 +250,42 @@ public function testJsonException(): void
$conn->call('Service.Process', random_bytes(256));
}

/**
* @doesNotPerformAssertions
*/
public function testCallSequence(): void
{
$relay1 = $this->getMockBuilder(Relay::class)->onlyMethods(['waitFrame', 'send'])->getMock();
$relay1
->method('waitFrame')
->willReturnCallback(function () {
static $series = [
[new Frame('Service.Process{}', [1, 15])],
[new Frame('Service.Process{}', [2, 15])],
[new Frame('Service.Process{}', [3, 15])],
];

[$return] = \array_shift($series);

return $return;
});
->willReturnOnConsecutiveCalls(
new Frame('Service.Process{}', [1, 15]),
new Frame('Service.Process{}', [2, 15]),
new Frame('Service.Process{}', [3, 15])
);
$relay1
->method('send')
->willReturnCallback(function (Frame $frame) {
static $series = [
[new Frame('Service.Process{"Name":"foo","Value":18}', [1, 15], 8)],
[new Frame('Service.Process{"Name":"foo","Value":18}', [2, 15], 8)],
[new Frame('Service.Process{"Name":"foo","Value":18}', [3, 15], 8)],
];

[$expectedArgs] = \array_shift($series);
self::assertEquals($expectedArgs, $frame);
});
->withConsecutive(
[new Frame('Service.Process{"Name":"foo","Value":18}', [1, 15], 8)],
[new Frame('Service.Process{"Name":"foo","Value":18}', [2, 15], 8)],
[new Frame('Service.Process{"Name":"foo","Value":18}', [3, 15], 8)]
);

$relay2 = $this->getMockBuilder(Relay::class)->onlyMethods(['waitFrame', 'send'])->getMock();
$relay2
->method('waitFrame')
->willReturnCallback(function () {
static $series = [
[new Frame('Service.Process{}', [1, 15])],
[new Frame('Service.Process{}', [2, 15])],
[new Frame('Service.Process{}', [3, 15])],
];

[$return] = \array_shift($series);

return $return;
});
->willReturnOnConsecutiveCalls(
new Frame('Service.Process{}', [1, 15]),
new Frame('Service.Process{}', [2, 15]),
new Frame('Service.Process{}', [3, 15])
);
$relay2
->method('send')
->willReturnCallback(function (Frame $frame) {
static $series = [
[new Frame('Service.Process{"Name":"bar","Value":18}', [1, 15], 8)],
[new Frame('Service.Process{"Name":"bar","Value":18}', [2, 15], 8)],
[new Frame('Service.Process{"Name":"bar","Value":18}', [3, 15], 8)],
];

[$expectedArgs] = \array_shift($series);
self::assertEquals($expectedArgs, $frame);
});
->withConsecutive(
[new Frame('Service.Process{"Name":"bar","Value":18}', [1, 15], 8)],
[new Frame('Service.Process{"Name":"bar","Value":18}', [2, 15], 8)],
[new Frame('Service.Process{"Name":"bar","Value":18}', [3, 15], 8)]
);

$conn1 = new RPC($relay1);
$conn2 = new RPC($relay2);
Expand Down

0 comments on commit 1562254

Please sign in to comment.