Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / diffusion / ssh / __tests__ / DiffusionMercurialWireSSHTestCase.php
blob0154805dd3a587a4d8e7e4c7d19f0d8c71fe95aa
1 <?php
3 final class DiffusionMercurialWireSSHTestCase extends PhabricatorTestCase {
5 public function testMercurialClientWireProtocolParser() {
6 $data = dirname(__FILE__).'/hgwiredata/';
7 $dir = Filesystem::listDirectory($data, $include_hidden = false);
8 foreach ($dir as $file) {
9 $raw = Filesystem::readFile($data.$file);
10 $raw = explode("\n~~~~~~~~~~\n", $raw, 2);
11 $this->assertEqual(2, count($raw));
12 $expect = phutil_json_decode($raw[1]);
13 $this->assertTrue(is_array($expect), $file);
15 $this->assertParserResult($expect, $raw[0], $file);
19 private function assertParserResult(array $expect, $input, $file) {
20 list($x, $y) = PhutilSocketChannel::newChannelPair();
21 $xp = new DiffusionMercurialWireClientSSHProtocolChannel($x);
23 $y->write($input);
24 $y->flush();
25 $y->closeWriteChannel();
27 $messages = array();
28 for ($ii = 0; $ii < count($expect); $ii++) {
29 try {
30 $messages[] = $xp->waitForMessage();
31 } catch (Exception $ex) {
32 // This is probably the parser not producing as many messages as
33 // we expect. Log the exception, but continue to the assertion below
34 // since that will often be easier to diagnose.
35 phlog($ex);
36 break;
40 $this->assertEqual($expect, $messages, $file);
42 // Now, make sure the channel doesn't have *more* messages than we expect.
43 // Specifically, it should throw when we try to read another message.
44 $caught = null;
45 try {
46 $xp->waitForMessage();
47 } catch (Exception $ex) {
48 $caught = $ex;
51 $this->assertTrue(
52 ($caught instanceof Exception),
53 pht("No extra messages for '%s'.", $file));