Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.gitignore export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests/ export-ignore
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
strategy:
matrix:
php:
- 8.0
- 7.4
- 7.3
- 7.2
Expand All @@ -34,6 +35,9 @@ jobs:
- run: sudo /etc/init.d/quasselcore status || sudo /etc/init.d/quasselcore start
- run: sudo /etc/init.d/quasselcore status || sleep 2
- run: vendor/bin/phpunit --coverage-text
if: ${{ matrix.php >= 7.3 }}
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}

PHPUnit-hhvm:
name: PHPUnit (HHVM)
Expand All @@ -45,7 +49,6 @@ jobs:
version: lts-3.30
- run: sudo apt-get -qq update || true # update package list and ignore temporary network errors
- run: sudo apt-get --no-install-recommends -qq install -y quassel-core
- run: hhvm $(which composer) require phpunit/phpunit:^5 --dev --no-interaction # requires legacy phpunit
- run: hhvm $(which composer) install
- run: sudo /etc/init.d/quasselcore status || sudo /etc/init.d/quasselcore start
- run: sudo /etc/init.d/quasselcore status || sleep 2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ $ composer require clue/quassel-react:^0.6
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 7+ and
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
HHVM.
It's *highly recommended to use PHP 7+* for this project.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
},
"require-dev": {
"clue/block-react": "^1.1",
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
}
}
19 changes: 12 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheResult="false">
<testsuites>
<testsuite name="Quassel React Test Suite">
<testsuite name="Quassel test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
</include>
</coverage>
</phpunit>
18 changes: 18 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Quassel Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
12 changes: 10 additions & 2 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@

class ClientTest extends TestCase
{
public function setUp()
private $stream;
private $protocol;
private $splitter;
private $client;

/**
* @before
*/
public function setUpClient()
{
$this->stream = $this->getMockBuilder('React\Stream\DuplexStreamInterface')->getMock();
$this->protocol = $this->getMockBuilder('Clue\React\Quassel\Io\Protocol')->disableOriginalConstructor()->getMock();
Expand Down Expand Up @@ -243,7 +251,7 @@ public function testWriteHeartBeatRequestWithoutTimestampSendsCurrentTimestamp()
$that->assertEquals(Protocol::REQUEST_HEARTBEAT, $value[0]);

$that->assertInstanceOf('DateTime', $value[1]);
$that->assertEquals(microtime(true), $value[1]->getTimestamp(), '', 2);
$that->assertEqualsDelta(microtime(true), $value[1]->getTimestamp(), 2);
return true;
}));
$this->splitter->expects($this->once())->method('writePacket');
Expand Down
24 changes: 6 additions & 18 deletions tests/FactoryIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ public function testCreateClientCreatesSecondConnectionWithoutProbeIfConnectionC
Block\sleep(0.1, $loop);
}

/**
* @expectedException RuntimeException
*/
public function testCreateClientRejectsIfServerRespondsWithInvalidData()
{
$loop = LoopFactory::create();
Expand All @@ -104,6 +101,7 @@ public function testCreateClientRejectsIfServerRespondsWithInvalidData()
$factory = new Factory($loop);
$promise = $factory->createClient($uri);

$this->setExpectedException('RuntimeException');
Block\await($promise, $loop, 10.0);
}

Expand Down Expand Up @@ -132,9 +130,6 @@ public function testCreateClientWithAuthSendsClientInitAfterProbe()
Block\sleep(0.1, $loop);
}

/**
* @expectedException RuntimeException
*/
public function testCreateClientWithAuthRejectsIfServerClosesAfterClientInit()
{
$loop = LoopFactory::create();
Expand All @@ -153,12 +148,10 @@ public function testCreateClientWithAuthRejectsIfServerClosesAfterClientInit()
$factory = new Factory($loop);
$promise = $factory->createClient('user:pass@' . $uri);

$this->setExpectedException('RuntimeException');
Block\await($promise, $loop, 10.0);
}

/**
* @expectedException RuntimeException
*/
public function testCreateClientWithAuthRejectsIfServerSendsClientInitRejectAfterClientInit()
{
$loop = LoopFactory::create();
Expand All @@ -182,12 +175,10 @@ public function testCreateClientWithAuthRejectsIfServerSendsClientInitRejectAfte
$factory = new Factory($loop);
$promise = $factory->createClient('user:pass@' . $uri);

$this->setExpectedException('RuntimeException');
Block\await($promise, $loop, 10.0);
}

/**
* @expectedException RuntimeException
*/
public function testCreateClientWithAuthRejectsIfServerSendsUnknownMessageAfterClientInit()
{
$loop = LoopFactory::create();
Expand All @@ -211,12 +202,10 @@ public function testCreateClientWithAuthRejectsIfServerSendsUnknownMessageAfterC
$factory = new Factory($loop);
$promise = $factory->createClient('user:pass@' . $uri);

$this->setExpectedException('RuntimeException');
Block\await($promise, $loop, 10.0);
}

/**
* @expectedException RuntimeException
*/
public function testCreateClientWithAuthRejectsIfServerSendsInvalidTruncatedResponseAfterClientInit()
{
$loop = LoopFactory::create();
Expand All @@ -235,12 +224,10 @@ public function testCreateClientWithAuthRejectsIfServerSendsInvalidTruncatedResp
$factory = new Factory($loop);
$promise = $factory->createClient('user:pass@' . $uri);

$this->setExpectedException('RuntimeException');
Block\await($promise, $loop, 10.0);
}

/**
* @expectedException RuntimeException
*/
public function testCreateClientWithAuthRejectsIfServerSendsClientInitAckNotConfigured()
{
$loop = LoopFactory::create();
Expand All @@ -263,6 +250,7 @@ public function testCreateClientWithAuthRejectsIfServerSendsClientInitAckNotConf
$factory = new Factory($loop);
$promise = $factory->createClient('user:pass@' . $uri);

$this->setExpectedException('RuntimeException');
Block\await($promise, $loop, 10.0);
}

Expand Down
10 changes: 9 additions & 1 deletion tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@

class FactoryTest extends TestCase
{
public function setUp()
private $loop;
private $connector;
private $prober;
private $factory;

/**
* @before
*/
public function setUpFactory()
{
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
Expand Down
16 changes: 10 additions & 6 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class FunctionalTest extends TestCase
private static $loop;
private static $blocker;

public static function setUpBeforeClass()
/**
* @beforeClass
*/
public static function setUpEnvironmentAndLoop()
{
if (!getenv('QUASSEL_HOST')) {
return;
Expand All @@ -40,7 +43,10 @@ public static function setUpBeforeClass()
self::$loop = LoopFactory::create();
}

public function setUp()
/**
* @before
*/
public function setUpSkipOnMissingEnvironment()
{
if (!self::$host) {
$this->markTestSkipped('No ENV QUASSEL_HOST (plus optionally QUASSEL_USER and QUASSEL_PASS) given');
Expand Down Expand Up @@ -170,7 +176,7 @@ public function testWriteHeartBeatDefaultsToCurrentTime(Client $client)
$received = Block\await($promise, self::$loop, 10.0);

$this->assertTrue($received instanceof \DateTime);
$this->assertEquals(microtime(true), $received->getTimestamp(), '', 2.0);
$this->assertEqualsDelta(microtime(true), $received->getTimestamp(), 2.0);
}

/**
Expand Down Expand Up @@ -274,16 +280,14 @@ public function testRequestBacklogReceivesBacklog()
$client->close();
}

/**
* @expectedException RuntimeException
*/
public function testCreateClientWithInvalidAuthUrlRejects()
{
$factory = new Factory(self::$loop);

$url = rawurlencode(self::$username) . ':@' . self::$host;
$promise = $factory->createClient($url);

$this->setExpectedException('RuntimeException');
Block\await($promise, self::$loop, 10.0);
}

Expand Down
9 changes: 5 additions & 4 deletions tests/Io/DatastreamProtocolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

class DatastreamProtocolTest extends AbstractProtocolTest
{
public function setUp()
/**
* @before
*/
public function setUpProtocol()
{
$this->protocol = Protocol::createFromProbe(Protocol::TYPE_DATASTREAM);
}
Expand All @@ -19,11 +22,9 @@ public function testIsNotLegacy()
$this->assertFalse($this->protocol->isLegacy());
}

/**
* @expectedException InvalidArgumentException
*/
public function testCanNotTransportListStartingWithString()
{
$this->setExpectedException('InvalidArgumentException');
$this->protocol->serializeVariantPacket(array('does', 'not', 'work'));
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Io/LegacyProtocolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

class LegacyProtocolTest extends AbstractProtocolTest
{
public function setUp()
/**
* @before
*/
public function setUpProtocol()
{
$this->protocol = Protocol::createFromProbe(Protocol::TYPE_LEGACY);
}
Expand Down
9 changes: 5 additions & 4 deletions tests/Io/PacketSplitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ class PacketSplitterTest extends TestCase
{
private $splitter;

public function setUp()
/**
* @before
*/
public function setUpSplitter()
{
$this->splitter = new PacketSplitter();
}
Expand All @@ -29,11 +32,9 @@ public function testWriteCompletePacketToSplitterWillEmitImmediately()
$this->splitter->push($packet, $this->expectCallableOnce());
}

/**
* @expectedException OverflowException
*/
public function testWillThrowForHugePacket()
{
$this->setExpectedException('OverflowException');
$this->splitter->push("\xFF\xFF\xFF\xFF", $this->expectCallableNever());
}
}
28 changes: 28 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,32 @@ protected function expectPromiseReject($promise)

return $promise;
}

public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 6+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit 4 - PHPUnit 5
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}

public function assertEqualsDelta($expected, $actual, $delta, $message = '')
{
if (method_exists($this, 'assertEqualsWithDelta')) {
// PHPUnit 7.5+
$this->assertEqualsWithDelta($expected, $actual, $delta, $message);
} else {
// legacy PHPUnit 4 - PHPUnit 7.4
$this->assertEquals($expected, $actual, $message, $delta);
}
}
}