<commit_before><?php

/**
 * @file
 * Tests for Ping.
 */

// TODO - Use autoloading someday.
include_once('Ping.php');
use JJG\Ping as Ping;

class PingTest extends PHPUnit_Framework_TestCase {
  private $reachable_host = 'www.google.com';
  private $unreachable_host = 'www.osdifjaosdg.com';

  public function testHost() {
    $first = $this->reachable_host;
    $ping = new Ping($first);
    $this->assertEquals($first, $ping->getHost());

    $second = 'www.apple.com';
    $ping->setHost($second);
    $this->assertEquals($second, $ping->getHost());
  }

  public function testTtl() {
    $first = 220;
    $ping = new Ping($this->reachable_host, $first);
    $this->assertEquals($first, $ping->getTtl());

    $second = 128;
    $ping->setTtl($second);
    $this->assertEquals($second, $ping->getTtl());
  }

  public function testPort() {
    $port = 2222;
    $ping = new Ping($this->reachable_host);
    $ping->setPort($port);
    $this->assertEquals($port, $ping->getPort());
  }

  public function testPingExec() {
    $ping = new Ping('www.google.com');
    $latency = $ping->ping('exec');
    $this->assertNotEquals(FALSE, $latency);

    $ping->setHost('www.sioajdsfonasdgiojsd.com');
    $latency = $ping->ping('exec');
    $this->assertEquals(FALSE, $latency);
  }

  public function testPingFsockopen() {
    $ping = new Ping($this->reachable_host);
    $latency = $ping->ping('fsockopen');
    $this->assertNotEquals(FALSE, $latency);

    $ping = new Ping($this->unreachable_host);
    $latency = $ping->ping('fsockopen');
    $this->assertEquals(FALSE, $latency);
  }

  /**
   * These tests require sudo/root so socket can be opened.
   */
  public function testPingSocket() {
    $ping = new Ping($this->reachable_host);
    $latency = $ping->ping('socket');
    $this->assertNotEquals(FALSE, $latency);

    $ping = new Ping($this->unreachable_host);
    $latency = $ping->ping('socket');
    $this->assertEquals(FALSE, $latency);
  }<commit_msg>Add test for timeout.<commit_after><?php

/**
 * @file
 * Tests for Ping.
 */

// TODO - Use autoloading someday.
include_once('Ping.php');
use JJG\Ping as Ping;

class PingTest extends PHPUnit_Framework_TestCase {
  private $reachable_host = 'www.google.com';
  private $unreachable_host = '254.254.254.254';

  public function testHost() {
    $first = $this->reachable_host;
    $ping = new Ping($first);
    $this->assertEquals($first, $ping->getHost());

    $second = 'www.apple.com';
    $ping->setHost($second);
    $this->assertEquals($second, $ping->getHost());
  }

  public function testTtl() {
    $first = 220;
    $ping = new Ping($this->reachable_host, $first);
    $this->assertEquals($first, $ping->getTtl());

    $second = 128;
    $ping->setTtl($second);
    $this->assertEquals($second, $ping->getTtl());
  }

  public function testTimeout() {
    $timeout = 5;
    $startTime = microtime(true);
    $ping = new Ping($this->unreachable_host, 255, $timeout);
    $ping->ping('exec');
    $time = floor(microtime(true) - $startTime);
    $this->assertEquals($timeout, $time);
  }
  
  public function testPort() {
    $port = 2222;
    $ping = new Ping($this->reachable_host);
    $ping->setPort($port);
    $this->assertEquals($port, $ping->getPort());
  }

  public function testPingExec() {
    $ping = new Ping($this->reachable_host );
    $latency = $ping->ping('exec');
    $this->assertNotEquals(FALSE, $latency);

    $ping->setHost($this->unreachable_host);
    $latency = $ping->ping('exec');
    $this->assertEquals(FALSE, $latency);
  }

  public function testPingFsockopen() {
    $ping = new Ping($this->reachable_host);
    $latency = $ping->ping('fsockopen');
    $this->assertNotEquals(FALSE, $latency);

    $ping = new Ping($this->unreachable_host);
    $latency = $ping->ping('fsockopen');
    $this->assertEquals(FALSE, $latency);
  }

  /**
   * These tests require sudo/root so socket can be opened.
   */
  public function testPingSocket() {
    $ping = new Ping($this->reachable_host);
    $latency = $ping->ping('socket');
    $this->assertNotEquals(FALSE, $latency);

    $ping = new Ping($this->unreachable_host);
    $latency = $ping->ping('socket');
    $this->assertEquals(FALSE, $latency);
  }
{'fraction_non_alphanumeric': 0.18434163701067616, 'fraction_numerical': 0.008540925266903915, 'mean_word_length': 3.7531003382187147, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 7, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6225487', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1440, 'n_words': 269}