Skip to content

Commit

Permalink
Added RawFramePicker test
Browse files Browse the repository at this point in the history
  • Loading branch information
edefimov committed Jul 23, 2015
1 parent 505a286 commit 9a6a475
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/unit/Frame/RawFramePickerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* async-sockets
*
* @copyright Copyright (c) 2015, Efimov Evgenij <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Tests\AsyncSockets\Frame;

use AsyncSockets\Frame\FramePickerInterface;
use AsyncSockets\Frame\RawFramePicker;

/**
* Class RawFramePickerTest
*/
class RawFramePickerTest extends AbstractFramePickerTest
{
/** {@inheritdoc} */
protected function createFramePicker()
{
return new RawFramePicker();
}

/**
* testReadSingleFrame
*
* @return void
*/
public function testReadSingleFrame()
{
$data = md5(microtime(true));
$picker = $this->createFramePicker();
$result = $picker->pickUpData($data);

self::assertEmpty($result, 'Raw frame picker must always collect data on first call');
self::assertEquals($data, (string) $picker->createFrame(), 'Incorrect frame data');
self::assertTrue($picker->isEof(), 'EOF flag is not set');
}

/**
* testCantReadSecondTime
*
* @return void
*/
public function testCantReadSecondTime()
{
$data = md5(microtime(true));
$picker = $this->createFramePicker();
$picker->pickUpData($data);

$secondData = sha1(microtime(true));
$result = $picker->pickUpData($secondData);
self::assertEquals($secondData, $result, 'Raw frame picker must ignore data on second call');
self::assertEquals($data, (string) $picker->createFrame(), 'Incorrect frame data');
}
}
40 changes: 40 additions & 0 deletions tests/unit/Socket/Io/DatagramClientIoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,46 @@ function ($handle, $size, $flags, &$address) use (&$data) {
self::assertEquals($expectedData, (string) $frame, 'Incorrect frame');
}

/**
* testReadUnreachedFrame
*
* @param string|null $remoteAddress Remote address for I/O object
*
* @return void
* @dataProvider remoteAddressDataProvider
* @expectedException \AsyncSockets\Exception\FrameSocketException
*/
public function testReadUnreachedFrame($remoteAddress)
{
$this->setUpIoObject($remoteAddress);

$data = '1';
$picker = $this->getMockForAbstractClass(
'AsyncSockets\Frame\FramePickerInterface',
[],
'',
true,
true,
true,
['isEof']
);
$picker->expects(self::any())->method('isEof')->willReturn(false);

PhpFunctionMocker::getPhpFunctionMocker('stream_socket_recvfrom')->setCallable(
function ($handle, $size, $flags, &$address) use (&$data) {
$address = $this->address;
$result = $data;

if (!($flags & MSG_PEEK)) {
$data = '';
}
return $result;
}
);

$this->object->read($picker);
}

/**
* testWriteData
*
Expand Down

0 comments on commit 9a6a475

Please sign in to comment.