Skip to content

Commit

Permalink
Found a workaround for the stream sending problem in later PHP versions;
Browse files Browse the repository at this point in the history
Reorganized tests so that they use groups;
Tweaked composer.json and .travis.yml files, so that "pear2/cache_shm" is installed separately, while allowing the build to continue without it.
  • Loading branch information
boenrobot committed Dec 13, 2015
1 parent 031fbb6 commit 589a23e
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 79 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ language: php
php:
# The earliest PHP 5.3 version that can run the test suit
# AND is supported by Travis-CI.
#- 5.3.3
- 5.3.3
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
before_script:
- composer self-update
- composer install --dev
script:
- composer require pear2/cache_shm:dev-develop | cat -
- cd tests
- ../vendor/bin/phpunit --configuration secondaryPeer.xml > secondaryPeer.out.txt &
- sleep 2
script:
- ../vendor/bin/phpunit --configuration phpunit.xml
## Code coverage seems to be causing a failure currently.
#- ../vendor/bin/phpunit --coverage-clover=coverage.clover --configuration phpunit.xml
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
"php": ">=5.3.0"
},
"require-dev": {
"pear2/cache_shm": "dev-develop",
"phpunit/phpunit": "@stable"
},
"suggest": {
"pear2/cache_shm": ">=0.1.3",
"ext-apc": ">=3.0.13",
"ext-wincache": ">=1.1.0",
"ext-openssl": "*"
"pear2/cache_shm": "Enables persistent connections",
"ext-apc": "This or Wincache is required for persistent connections.",
"ext-wincache": "This or APC is required for persistent connections. Reccomended instead of APC on Windows.",
"ext-openssl": "Enables encrypted connections."
},
"autoload": {
"psr-0": {
Expand Down
30 changes: 18 additions & 12 deletions src/PEAR2/Net/Transmitter/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ public function getChunk($direction = self::DIRECTION_ALL)
public function send($contents, $offset = null, $length = null)
{
$bytes = 0;
$fails = 0;
$chunkSize = $this->chunkSize[self::DIRECTION_SEND];
$lengthIsNotNull = null !== $length;
$offsetIsNotNull = null !== $offset;
Expand All @@ -316,19 +317,24 @@ public function send($contents, $offset = null, $length = null)
) {
break;
}
$bytesNow = @fwrite(
$this->stream,
fread($contents, $chunkSize)
);
if (0 != $bytesNow) {
$bytes += $bytesNow;
} elseif ($this->isBlocking || false === $bytesNow) {
throw $this->createException(
'Failed while sending stream.',
2,
null,
$bytes
$contentsToSend = fread($contents, $chunkSize);
if ('' != $contentsToSend) {
$bytesNow = @fwrite(
$this->stream,
$contentsToSend
);
if (0 != $bytesNow) {
$bytes += $bytesNow;
} elseif ($this->isBlocking || false === $bytesNow) {
//if (1 < ++$fails) {
throw $this->createException(
'Failed while sending stream.',
2,
null,
$bytes
);
//}
}
}
$this->isAcceptingData(null);
}
Expand Down
12 changes: 9 additions & 3 deletions tests/ClientEncryptedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@

require_once 'ClientTest.php';

/**
* @group Client
* @group Encrypted
*
* @requires extension openssl
*/
class ClientEncryptedTest extends ClientTest
{
public function setUp()
public function setUp($persist = false)
{
$this->client = new TcpClient(
return $this->client = new TcpClient(
REMOTE_HOSTNAME,
REMOTE_PORT,
false,
$persist,
null,
'',
NetworkStream::CRYPTO_TLS,
Expand Down
78 changes: 64 additions & 14 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php
namespace PEAR2\Net\Transmitter;

/**
* @group Client
* @group Unencrypted
*/
class ClientTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TcpClient
*/
protected $client;

public function setUp()
public function setUp($persist = false)
{
$this->client = new TcpClient(REMOTE_HOSTNAME, REMOTE_PORT);
return $this->client = new TcpClient(REMOTE_HOSTNAME, REMOTE_PORT, $persist);
}

public function tearDown()
Expand Down Expand Up @@ -58,6 +62,9 @@ public function testOneByteDelayedEchoFail()
$this->assertFalse($this->client->isDataAwaiting($timeout));
}

/**
* @group BigData
*/
public function test3MegaBytesEcho()
{
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
Expand All @@ -71,6 +78,9 @@ public function test3MegaBytesEcho()
);
}

/**
* @group BigData
*/
public function test3MegaBytesDelayedEcho()
{
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
Expand All @@ -87,6 +97,9 @@ public function test3MegaBytesDelayedEcho()
}
}

/**
* @group BigData
*/
public function test3MegaBytesLongDelayedEcho()
{
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
Expand Down Expand Up @@ -125,6 +138,9 @@ public function testOneByteDelayedEchoSend()
}
*/

/**
* @group BigData
*/
public function test3MegaBytesLongDelayedEchoSend()
{
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
Expand All @@ -140,6 +156,9 @@ public function test3MegaBytesLongDelayedEchoSend()
}
}

/**
* @group StreamSend
*/
public function testOneByteEchoStreamSend()
{
$stream = fopen('php://temp', 'r+b');
Expand All @@ -153,6 +172,10 @@ public function testOneByteEchoStreamSend()
);
}

/**
* @group StreamSend
* @group BigData
*/
public function test3MegaBytesEchoStreamSend()
{
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
Expand All @@ -167,6 +190,9 @@ public function test3MegaBytesEchoStreamSend()
);
}

/**
* @group StreamReceive
*/
public function testOneByteEchoStreamReceive()
{
$byte = '5';
Expand All @@ -178,6 +204,10 @@ public function testOneByteEchoStreamReceive()
);
}

/**
* @group StreamReceive
* @group BigData
*/
public function test3MegaBytesEchoStreamReceive()
{
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
Expand All @@ -194,7 +224,14 @@ public function testOffsetSend()
{
$contents = 'abcd';
$this->assertSame(3, $this->client->send($contents, 1));

}

/**
* @group StreamSend
*/
public function testOffsetStreamSend()
{
$contents = 'abcd';
$stream = fopen('php://temp', 'r+b');
fwrite($stream, $contents);
rewind($stream);
Expand All @@ -208,7 +245,14 @@ public function testLengthSend()
{
$contents = 'abcd';
$this->assertSame(1, $this->client->send($contents, null, 1));

}

/**
* @group StreamSend
*/
public function testLengthStreamSend()
{
$contents = 'abcd';
$stream = fopen('php://temp', 'r+b');
fwrite($stream, $contents);
rewind($stream);
Expand All @@ -231,19 +275,13 @@ public function testClientReceivingFilterCollection()

/**
* @requires PHP 5.3.9
*
* @group Persistent
*/
public function testPersistentClientConnection()
{
$this->client = new TcpClient(
REMOTE_HOSTNAME,
REMOTE_PORT,
true
);
$client = new TcpClient(
REMOTE_HOSTNAME,
REMOTE_PORT,
true
);
$client = $this->setUp(true);
$this->setUp(true);
$this->assertTrue($this->client->isFresh());
$this->assertTrue($client->isFresh());
$this->assertTrue($this->client->isPersistent());
Expand All @@ -264,6 +302,9 @@ public function testClientReceivingIncompleteData()
}
}

/**
* @group StreamReceive
*/
public function testClientReceivingIncompleteDataStream()
{
try {
Expand All @@ -280,6 +321,9 @@ public function testServerReceivingIncompleteData()
$this->assertSame(1, $this->client->send('t'), 'Wrong amount sent.');
}

/**
* @group StreamReceive
*/
public function testServerReceivingIncompleteDataStream()
{
$this->assertSame(1, $this->client->send('t'), 'Wrong amount sent.');
Expand All @@ -302,6 +346,9 @@ public function testClientSendingIncompleteData()
}
}

/**
* @group StreamSend
*/
public function testClientSendingIncompleteDataStream()
{
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
Expand Down Expand Up @@ -333,6 +380,9 @@ public function testClientTimingOut()
}
}

/**
* @group StreamReceive
*/
public function testClientTimingOutStream()
{
$this->assertSame('aaa', $this->client->receive(3));
Expand Down
3 changes: 3 additions & 0 deletions tests/ServerEncryptedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
require_once 'ServerTest.php';

/**
* @group Server
* @group Encrypted
*
* @requires extension openssl
*/
class ServerEncryptedTest extends ServerTest
Expand Down
Loading

0 comments on commit 589a23e

Please sign in to comment.