public function testBadSocket() { $socket = new SimpleSocket('bad_url', 111, 5); $this->assertTrue($socket->isError()); $this->assertPattern('/Cannot open \\[bad_url:111\\] with \\[/', $socket->getError()); $this->assertFalse($socket->isOpen()); $this->assertFalse($socket->write('A message')); }
function invoke($method) { ob_start(); parent::invoke($method); $output = ob_get_contents(); ob_end_clean(); $sock = new SimpleSocket("127.0.0.1", $this->_port, 5); $sock->write($output); $sock->close(); echo $sock->getError(); }
function testSocket() { $socket = new SimpleSocket("www.lastcraft.com", 80); $this->assertFalse($socket->isError(), "Error [" . $socket->getError() . "]"); $this->assertTrue($socket->isOpen()); $this->assertTrue($socket->write("GET www.lastcraft.com/test/network_confirm.php HTTP/1.0\r\n")); $socket->write("Host: localhost\r\n"); $socket->write("Connection: close\r\n\r\n"); $this->assertEqual($socket->read(8), "HTTP/1.1"); $socket->close(); $this->assertEqual($socket->read(8), ""); }
/** * Runs the test methods in the test case, or not if the * scorer blocks it. * @param SimpleTest $test_case Test case to run test on. * @param string $method Name of test method. * @access public */ function run() { $methods = get_class_methods(get_class($this->_test_case)); $invoker =& $this->_test_case->createInvoker(); foreach ($methods as $method) { if (!$this->_isTest($method)) { continue; } if ($this->_isConstructor($method)) { continue; } ob_start(); echo $this->_start; $this->_scorer->paintMethodStart($method); if ($this->_scorer->shouldInvoke($this->_test_case->getLabel(), $method)) { $invoker->invoke($method); } $this->_scorer->paintMethodEnd($method); echo $this->_end; $output = ob_get_contents(); ob_end_clean(); $sock = new SimpleSocket("127.0.0.1", $this->_port, 5); $sock->write($output); $sock->close(); echo $sock->getError(); } }