Skip to content

Commit 589a23e

Browse files
committed
Found a workaround for the stream sending problem in later PHP versions;
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.
1 parent 031fbb6 commit 589a23e

File tree

11 files changed

+260
-79
lines changed

11 files changed

+260
-79
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ language: php
22
php:
33
# The earliest PHP 5.3 version that can run the test suit
44
# AND is supported by Travis-CI.
5-
#- 5.3.3
5+
- 5.3.3
66
- 5.3
77
- 5.4
88
- 5.5
99
- 5.6
10+
- 7.0
1011
before_script:
1112
- composer self-update
1213
- composer install --dev
14+
script:
15+
- composer require pear2/cache_shm:dev-develop | cat -
1316
- cd tests
1417
- ../vendor/bin/phpunit --configuration secondaryPeer.xml > secondaryPeer.out.txt &
1518
- sleep 2
16-
script:
1719
- ../vendor/bin/phpunit --configuration phpunit.xml
1820
## Code coverage seems to be causing a failure currently.
1921
#- ../vendor/bin/phpunit --coverage-clover=coverage.clover --configuration phpunit.xml

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
"php": ">=5.3.0"
2020
},
2121
"require-dev": {
22-
"pear2/cache_shm": "dev-develop",
2322
"phpunit/phpunit": "@stable"
2423
},
2524
"suggest": {
26-
"pear2/cache_shm": ">=0.1.3",
27-
"ext-apc": ">=3.0.13",
28-
"ext-wincache": ">=1.1.0",
29-
"ext-openssl": "*"
25+
"pear2/cache_shm": "Enables persistent connections",
26+
"ext-apc": "This or Wincache is required for persistent connections.",
27+
"ext-wincache": "This or APC is required for persistent connections. Reccomended instead of APC on Windows.",
28+
"ext-openssl": "Enables encrypted connections."
3029
},
3130
"autoload": {
3231
"psr-0": {

src/PEAR2/Net/Transmitter/Stream.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ public function getChunk($direction = self::DIRECTION_ALL)
302302
public function send($contents, $offset = null, $length = null)
303303
{
304304
$bytes = 0;
305+
$fails = 0;
305306
$chunkSize = $this->chunkSize[self::DIRECTION_SEND];
306307
$lengthIsNotNull = null !== $length;
307308
$offsetIsNotNull = null !== $offset;
@@ -316,19 +317,24 @@ public function send($contents, $offset = null, $length = null)
316317
) {
317318
break;
318319
}
319-
$bytesNow = @fwrite(
320-
$this->stream,
321-
fread($contents, $chunkSize)
322-
);
323-
if (0 != $bytesNow) {
324-
$bytes += $bytesNow;
325-
} elseif ($this->isBlocking || false === $bytesNow) {
326-
throw $this->createException(
327-
'Failed while sending stream.',
328-
2,
329-
null,
330-
$bytes
320+
$contentsToSend = fread($contents, $chunkSize);
321+
if ('' != $contentsToSend) {
322+
$bytesNow = @fwrite(
323+
$this->stream,
324+
$contentsToSend
331325
);
326+
if (0 != $bytesNow) {
327+
$bytes += $bytesNow;
328+
} elseif ($this->isBlocking || false === $bytesNow) {
329+
//if (1 < ++$fails) {
330+
throw $this->createException(
331+
'Failed while sending stream.',
332+
2,
333+
null,
334+
$bytes
335+
);
336+
//}
337+
}
332338
}
333339
$this->isAcceptingData(null);
334340
}

tests/ClientEncryptedTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44

55
require_once 'ClientTest.php';
66

7+
/**
8+
* @group Client
9+
* @group Encrypted
10+
*
11+
* @requires extension openssl
12+
*/
713
class ClientEncryptedTest extends ClientTest
814
{
9-
public function setUp()
15+
public function setUp($persist = false)
1016
{
11-
$this->client = new TcpClient(
17+
return $this->client = new TcpClient(
1218
REMOTE_HOSTNAME,
1319
REMOTE_PORT,
14-
false,
20+
$persist,
1521
null,
1622
'',
1723
NetworkStream::CRYPTO_TLS,

tests/ClientTest.php

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<?php
22
namespace PEAR2\Net\Transmitter;
33

4+
/**
5+
* @group Client
6+
* @group Unencrypted
7+
*/
48
class ClientTest extends \PHPUnit_Framework_TestCase
59
{
610
/**
711
* @var TcpClient
812
*/
913
protected $client;
1014

11-
public function setUp()
15+
public function setUp($persist = false)
1216
{
13-
$this->client = new TcpClient(REMOTE_HOSTNAME, REMOTE_PORT);
17+
return $this->client = new TcpClient(REMOTE_HOSTNAME, REMOTE_PORT, $persist);
1418
}
1519

1620
public function tearDown()
@@ -58,6 +62,9 @@ public function testOneByteDelayedEchoFail()
5862
$this->assertFalse($this->client->isDataAwaiting($timeout));
5963
}
6064

65+
/**
66+
* @group BigData
67+
*/
6168
public function test3MegaBytesEcho()
6269
{
6370
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
@@ -71,6 +78,9 @@ public function test3MegaBytesEcho()
7178
);
7279
}
7380

81+
/**
82+
* @group BigData
83+
*/
7484
public function test3MegaBytesDelayedEcho()
7585
{
7686
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
@@ -87,6 +97,9 @@ public function test3MegaBytesDelayedEcho()
8797
}
8898
}
8999

100+
/**
101+
* @group BigData
102+
*/
90103
public function test3MegaBytesLongDelayedEcho()
91104
{
92105
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
@@ -125,6 +138,9 @@ public function testOneByteDelayedEchoSend()
125138
}
126139
*/
127140

141+
/**
142+
* @group BigData
143+
*/
128144
public function test3MegaBytesLongDelayedEchoSend()
129145
{
130146
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
@@ -140,6 +156,9 @@ public function test3MegaBytesLongDelayedEchoSend()
140156
}
141157
}
142158

159+
/**
160+
* @group StreamSend
161+
*/
143162
public function testOneByteEchoStreamSend()
144163
{
145164
$stream = fopen('php://temp', 'r+b');
@@ -153,6 +172,10 @@ public function testOneByteEchoStreamSend()
153172
);
154173
}
155174

175+
/**
176+
* @group StreamSend
177+
* @group BigData
178+
*/
156179
public function test3MegaBytesEchoStreamSend()
157180
{
158181
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
@@ -167,6 +190,9 @@ public function test3MegaBytesEchoStreamSend()
167190
);
168191
}
169192

193+
/**
194+
* @group StreamReceive
195+
*/
170196
public function testOneByteEchoStreamReceive()
171197
{
172198
$byte = '5';
@@ -178,6 +204,10 @@ public function testOneByteEchoStreamReceive()
178204
);
179205
}
180206

207+
/**
208+
* @group StreamReceive
209+
* @group BigData
210+
*/
181211
public function test3MegaBytesEchoStreamReceive()
182212
{
183213
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
@@ -194,7 +224,14 @@ public function testOffsetSend()
194224
{
195225
$contents = 'abcd';
196226
$this->assertSame(3, $this->client->send($contents, 1));
197-
227+
}
228+
229+
/**
230+
* @group StreamSend
231+
*/
232+
public function testOffsetStreamSend()
233+
{
234+
$contents = 'abcd';
198235
$stream = fopen('php://temp', 'r+b');
199236
fwrite($stream, $contents);
200237
rewind($stream);
@@ -208,7 +245,14 @@ public function testLengthSend()
208245
{
209246
$contents = 'abcd';
210247
$this->assertSame(1, $this->client->send($contents, null, 1));
211-
248+
}
249+
250+
/**
251+
* @group StreamSend
252+
*/
253+
public function testLengthStreamSend()
254+
{
255+
$contents = 'abcd';
212256
$stream = fopen('php://temp', 'r+b');
213257
fwrite($stream, $contents);
214258
rewind($stream);
@@ -231,19 +275,13 @@ public function testClientReceivingFilterCollection()
231275

232276
/**
233277
* @requires PHP 5.3.9
278+
*
279+
* @group Persistent
234280
*/
235281
public function testPersistentClientConnection()
236282
{
237-
$this->client = new TcpClient(
238-
REMOTE_HOSTNAME,
239-
REMOTE_PORT,
240-
true
241-
);
242-
$client = new TcpClient(
243-
REMOTE_HOSTNAME,
244-
REMOTE_PORT,
245-
true
246-
);
283+
$client = $this->setUp(true);
284+
$this->setUp(true);
247285
$this->assertTrue($this->client->isFresh());
248286
$this->assertTrue($client->isFresh());
249287
$this->assertTrue($this->client->isPersistent());
@@ -264,6 +302,9 @@ public function testClientReceivingIncompleteData()
264302
}
265303
}
266304

305+
/**
306+
* @group StreamReceive
307+
*/
267308
public function testClientReceivingIncompleteDataStream()
268309
{
269310
try {
@@ -280,6 +321,9 @@ public function testServerReceivingIncompleteData()
280321
$this->assertSame(1, $this->client->send('t'), 'Wrong amount sent.');
281322
}
282323

324+
/**
325+
* @group StreamReceive
326+
*/
283327
public function testServerReceivingIncompleteDataStream()
284328
{
285329
$this->assertSame(1, $this->client->send('t'), 'Wrong amount sent.');
@@ -302,6 +346,9 @@ public function testClientSendingIncompleteData()
302346
}
303347
}
304348

349+
/**
350+
* @group StreamSend
351+
*/
305352
public function testClientSendingIncompleteDataStream()
306353
{
307354
$size = 3/*m*/ * 1024/*k*/ * 1024/*b*/;
@@ -333,6 +380,9 @@ public function testClientTimingOut()
333380
}
334381
}
335382

383+
/**
384+
* @group StreamReceive
385+
*/
336386
public function testClientTimingOutStream()
337387
{
338388
$this->assertSame('aaa', $this->client->receive(3));

tests/ServerEncryptedTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
require_once 'ServerTest.php';
66

77
/**
8+
* @group Server
9+
* @group Encrypted
10+
*
811
* @requires extension openssl
912
*/
1013
class ServerEncryptedTest extends ServerTest

0 commit comments

Comments
 (0)