Skip to content

Commit

Permalink
Merge branch 'unittest-16' of https://github.com/mmz-srf/stomp-php in…
Browse files Browse the repository at this point in the history
…to mmz-srf-unittest-16

Conflicts:
	src/test/bootstrap.php
  • Loading branch information
monofone committed Nov 24, 2012
2 parents aeb512f + 38aba3b commit 95ced7e
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 3 deletions.
7 changes: 5 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
syntaxCheck = "false"
bootstrap = "tests/bootstrap.php" >
<testsuites>
<testsuite name="stomp-php Test Suite">
<directory>tests/</directory>
<testsuite name="stomp-php Functional Test Suite">
<directory>tests/functional/</directory>
</testsuite>
<testsuite name="stomp-php Stubbed Test Suite">
<file>tests/stubbed</file>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/FuseSource/Stomp/Stomp.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public function readFrame ()
$data .= $read;
if (strpos($data, "\x00") !== false) {
$end = true;
$data = rtrim($data, "\n");
$data = trim($data, "\n");
}
$len = strlen($data);
} while ($len < 2 || $end == false);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected function setUp ()
*/
protected function tearDown ()
{
$this->Stomp->disconnect();
$this->Stomp = null;
parent::tearDown();
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 56 additions & 0 deletions tests/stubbed/StompUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
namespace FuseSource\Stomp;

use PHPUnit_Framework_TestCase;

// Prepare mocking function calls
require_once(__DIR__ . '/fusesource_stream_function_stubs.php');

class StompUnitTest extends PHPUnit_Framework_TestCase
{
/**
* @var Stomp
*/
private $sut;

protected function setUp()
{
$this->sut = new Stomp('tcp://localhost:61613');
}

public function testReadFrameWithTrailingLineFeed()
{
// Mock functions return values
global $fusesourceStreamFunctionStubsBuffer;
$fusesourceStreamFunctionStubsBuffer =array(
"MESSAGE\n\nbody\x00\n",
"MESSAGE\n\nbody\x00",
);

$this->sut->readFrame();
$frame = $this->sut->readFrame();
$this->assertSame(
'MESSAGE',
$frame->command
);
}

public function testReadFrameWithLeadingLineFeed()
{
$this->sut = new Stomp('tcp://localhost:61613');

// Mock functions return values
global $fusesourceStreamFunctionStubsBuffer;
$fusesourceStreamFunctionStubsBuffer =array(
"MESSAGE\n\nbody\x00",
"\nMESSAGE\n\nbody\x00",
);

$this->sut->readFrame();
$frame = $this->sut->readFrame();
$this->assertSame(
'MESSAGE',
$frame->command
);
}
}
24 changes: 24 additions & 0 deletions tests/stubbed/fusesource_stream_function_stubs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace FuseSource\Stomp;

function stream_select()
{
global $fusesourceStreamFunctionStubsBuffer;
if (count($fusesourceStreamFunctionStubsBuffer) === 0) {
return false;
}
return strlen($fusesourceStreamFunctionStubsBuffer[0]);
}

function fread($socket, $count)
{
global $fusesourceStreamFunctionStubsBuffer;
return array_shift($fusesourceStreamFunctionStubsBuffer);
}

function feof()
{
global $fusesourceStreamFunctionStubsBuffer;
return count($fusesourceStreamFunctionStubsBuffer)===0;
}

0 comments on commit 95ced7e

Please sign in to comment.