Files
DomFramework/Tests/TcpclientTest.php

90 lines
2.5 KiB
PHP

<?php
/**
* DomFramework - Tests
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD
*/
namespace Domframework\Tests;
use Domframework\Tcpclient;
/**
* Test the TCP client
*/
class TcpclientTest extends \PHPUnit_Framework_TestCase
{
public function testFournier38IPv4()
{
$tcpclient = new Tcpclient("ipv4.fournier38.fr", 80);
$tcpclient->preferIPv4(true);
$tcpclient->connect();
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: ip.fournier38.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
$res = "";
while (($read = $tcpclient->read()) !== "") {
$res .= $read . "\r\n";
}
$tcpclient->disconnect();
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
public function testFournier38IPv4orIpv6()
{
$tcpclient = new Tcpclient("ip.fournier38.fr", 80);
$tcpclient->connect();
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: ip.fournier38.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
$res = "";
while (($read = $tcpclient->read()) !== "") {
$res .= $read . "\r\n";
}
$tcpclient->disconnect();
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
public function testFournier38SSL()
{
$tcpclient = new Tcpclient("ip.fournier38.fr", 443);
$tcpclient->connect();
$tcpclient->cryptoEnable(true);
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: ip.fournier38.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
$res = "";
while (($read = $tcpclient->read()) !== "") {
$res .= $read . "\r\n";
}
$tcpclient->disconnect();
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
public function testFournier38SSLIPv6()
{
$tcpclient = new Tcpclient("ipv6.fournier38.fr", 443);
$tcpclient->connect();
$tcpclient->cryptoEnable(true);
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: ipv6.fournier38.f\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
$res = "";
while (($read = $tcpclient->read()) !== "") {
$res .= $read . "\r\n";
}
$tcpclient->disconnect();
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
}