Permalink
Browse files

Created testing environment.

  • Loading branch information...
1 parent 7b2f520 commit f59f8f5fcd3ef7273794405756a05935facc1dc1 @boenrobot boenrobot committed Oct 8, 2011
View
2 nbproject/project.properties
@@ -4,7 +4,7 @@ include.path=\
php.version=PHP_53
phpunit.bootstrap=
phpunit.bootstrap.create.tests=false
-phpunit.configuration=tests/configuration.xml
+phpunit.configuration=tests/phpunit.xml
phpunit.run.test.files=false
phpunit.suite=
source.encoding=UTF-8
View
2 src/PEAR2/Net/Transmitter/SocketClientTransmitter.php
@@ -57,7 +57,7 @@ class SocketClientTransmitter extends StreamTransmitter
* connection.
* @param resource $context A context for the socket.
*/
- public function __construct($host, $port = 8728, $persist = false,
+ public function __construct($host, $port, $persist = false,
$timeout = null, $key = '', $context = null
) {
$flags = STREAM_CLIENT_CONNECT;
View
15 src/PEAR2/Net/Transmitter/SocketServerConnectionTransmitter.php
@@ -56,7 +56,7 @@ class SocketServerConnectionTransmitter extends StreamTransmitter
*/
public function __construct($server, $timeout = null)
{
- if (!self::isServer($server)) {
+ if (!self::isStream($server)) {
throw $this->createException('Invalid server supplied.', 8);
}
$timeout
@@ -75,19 +75,6 @@ public function __construct($server, $timeout = null)
}
/**
- * Checks whether a cetain variable is a socket server.
- *
- * @param mixed $var The variable to check.
- *
- * @return bool TRUE on success, FALSE on failure.
- */
- public static function isServer($var)
- {
- return is_resource($var)
- && (bool) preg_match('#\s?server\s?#sm', get_resource_type($var));
- }
-
- /**
* Gets the IP address of the connected client.
*
* @return string The IP address of the connected client.
View
32 tests/ClientTest.php
@@ -0,0 +1,32 @@
+<?php
+namespace PEAR2\Net\Transmitter;
+
+class ClientTest extends \PHPUnit_Framework_TestCase
+{
+
+ /**
+ * @var SocketClientTransmitter
+ */
+ protected $client;
+
+ public function setUp()
+ {
+ $this->client = new SocketClientTransmitter(
+ REMOTE_HOSTNAME, REMOTE_PORT
+ );
+ }
+
+ public function tearDown()
+ {
+ unset($this->client);
+ }
+
+ public function testOneByteEcho()
+ {
+ $byte = 't';
+ $this->client->send($byte);
+ $this->assertEquals(
+ $byte, $this->client->receive(1), 'Wrong byte echoed.'
+ );
+ }
+}
View
58 tests/ServerTest.php
@@ -0,0 +1,58 @@
+<?php
+namespace PEAR2\Net\Transmitter;
+
+class ServerTest extends \PHPUnit_Framework_TestCase
+{
+
+ /**
+ * @var resource
+ */
+ protected static $server;
+
+ /**
+ * @var int
+ */
+ protected static $errorno;
+
+ /**
+ * @var string
+ */
+ protected static $errstr;
+
+ /**
+ * @var SocketServerConnectionTransmitter
+ */
+ protected $conn;
+
+ public static function setUpBeforeClass()
+ {
+ self::$server = stream_socket_server(
+ 'tcp://' . LOCAL_HOSTNAME . ':' . LOCAL_PORT,
+ self::$errorno, self::$errstr
+ );
+ }
+
+ public static function tearDownAfterClass()
+ {
+ fclose(self::$server);
+ }
+
+ public function setUp()
+ {
+ $this->conn = new SocketServerConnectionTransmitter(
+ self::$server, 1/*h*/ * 60/*m*/ * 60/*s*/
+ );
+ }
+
+ public function tearDown()
+ {
+ unset($this->conn);
+ }
+
+ public function testOneByteEcho()
+ {
+ $this->assertEquals(
+ 1, $this->conn->send($this->conn->receive(1)), 'Wrong byte echoed.'
+ );
+ }
+}
View
4 tests/StreamTransmitterTest.php
@@ -1,14 +1,14 @@
<?php
namespace PEAR2\Net\Transmitter;
-class RequestHandlingTest extends \PHPUnit_Framework_TestCase
+class StreamTransmitterTest extends \PHPUnit_Framework_TestCase
{
public function testDefaultStreamTransmitterException()
{
try {
$trans = new StreamTransmitter('invalid arg');
$this->fail('Transmitter initialization had to fail.');
- } catch (\Exception $e) {
+ } catch (StreamException $e) {
$this->assertEquals(1, $e->getCode(), 'Improper exception code.');
}
}
View
14 tests/configuration.xml → tests/phpunit.xml
@@ -16,8 +16,22 @@
convertWarningsToExceptions="false"
>
-->
+ <php>
+ <!--
+ The name and port of secondaryPeer.xml
+ -->
+ <const name="REMOTE_HOSTNAME" value="127.0.0.1" />
+ <const name="REMOTE_PORT" value="6666" />
+ <!--
+ The name and port secondaryPeer.xml must use.
+ -->
+ <const name="LOCAL_HOSTNAME" value="127.0.0.1" />
+ <const name="LOCAL_PORT" value="6667" />
+ </php>
<testsuites>
<testsuite name="All tests">
+ <file>ClientTest.php</file>
+ <file>ServerTest.php</file>
<file>StreamTransmitterTest.php</file>
</testsuite>
</testsuites>
View
1 tests/secondaryPeer.bat
@@ -0,0 +1 @@
+phpunit --configuration secondaryPeer.xml
View
42 tests/secondaryPeer.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit
+ bootstrap="bootstrap.php"
+ colors="false"
+ stopOnFailure="false"
+ verbose="true"
+ strict="true"
+
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+>
+ <!--
+ convertErrorsToExceptions="false"
+ convertNoticesToExceptions="false"
+ convertWarningsToExceptions="false"
+>
+ -->
+ <php>
+ <!--
+ The name and port of phpunit.xml
+ -->
+ <const name="REMOTE_HOSTNAME" value="127.0.0.1" />
+ <const name="REMOTE_PORT" value="6667" />
+ <!--
+ The name and port phpunit.xml must use.
+ -->
+ <const name="LOCAL_HOSTNAME" value="127.0.0.1" />
+ <const name="LOCAL_PORT" value="6666" />
+ </php>
+ <testsuites>
+ <testsuite name="All tests">
+ <file>ServerTest.php</file>
+ <file>ClientTest.php</file>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist>
+ <directory suffix=".php">../src/PEAR2/Net/Transmitter</directory>
+ </whitelist>
+ </filter>
+</phpunit>

0 comments on commit f59f8f5

Please sign in to comment.