[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/ssh/__tests__/ -> DiffusionSSHMercurialWireTestCase.php (source)

   1  <?php
   2  
   3  final class DiffusionSSHMercurialWireTestCase
   4    extends PhabricatorTestCase {
   5  
   6    public function testMercurialClientWireProtocolParser() {
   7      $data = dirname(__FILE__).'/hgwiredata/';
   8      $dir = Filesystem::listDirectory($data, $include_hidden = false);
   9      foreach ($dir as $file) {
  10        $raw = Filesystem::readFile($data.$file);
  11        $raw = explode("\n~~~~~~~~~~\n", $raw, 2);
  12        $this->assertEqual(2, count($raw));
  13        $expect = json_decode($raw[1], true);
  14        $this->assertTrue(is_array($expect), $file);
  15  
  16        $this->assertParserResult($expect, $raw[0], $file);
  17      }
  18    }
  19  
  20    private function assertParserResult(array $expect, $input, $file) {
  21      list($x, $y) = PhutilSocketChannel::newChannelPair();
  22      $xp = new DiffusionSSHMercurialWireClientProtocolChannel($x);
  23  
  24      $y->write($input);
  25      $y->flush();
  26      $y->closeWriteChannel();
  27  
  28      $messages = array();
  29      for ($ii = 0; $ii < count($expect); $ii++) {
  30        try {
  31          $messages[] = $xp->waitForMessage();
  32        } catch (Exception $ex) {
  33          // This is probably the parser not producing as many messages as
  34          // we expect. Log the exception, but continue to the assertion below
  35          // since that will often be easier to diagnose.
  36          phlog($ex);
  37          break;
  38        }
  39      }
  40  
  41      $this->assertEqual($expect, $messages, $file);
  42  
  43      // Now, make sure the channel doesn't have *more* messages than we expect.
  44      // Specifically, it should throw when we try to read another message.
  45      $caught = null;
  46      try {
  47        $xp->waitForMessage();
  48      } catch (Exception $ex) {
  49        $caught = $ex;
  50      }
  51  
  52      $this->assertTrue(
  53        ($caught instanceof Exception),
  54        "No extra messages for '{$file}'.");
  55    }
  56  
  57  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1