Skip to content

Commit

Permalink
Merge pull request #17 from clue-labs/php8.3
Browse files Browse the repository at this point in the history
Run tests on PHP 8.3 and update test suite
  • Loading branch information
clue authored Aug 5, 2024
2 parents edd6f69 + 934d598 commit dc8c965
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 32 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ jobs:
strategy:
matrix:
php:
- 8.3
- 8.2
- 8.1
- 8.0
- 7.4
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
steps:
Expand All @@ -21,3 +32,6 @@ jobs:
coverage: xdebug
- run: composer install
- 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 }}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36"
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
},
"autoload": {
"psr-0": {
Expand Down
16 changes: 9 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

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

<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<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="Redis Protocol Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
<php>
<ini name="error_reporting" value="-1" />
</php>
</phpunit>
5 changes: 4 additions & 1 deletion tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ class FactoryTest extends TestCase
{
private $factory;

public function setUp()
/**
* @before
*/
public function setUpFactory()
{
$this->factory = new Factory();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Model/AbstractModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ abstract class AbstractModelTest extends TestCase

abstract protected function createModel($value);

public function setUp()
/**
* @before
*/
public function setUpSerializer()
{
$this->serializer = new RecursiveSerializer();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Model/ErrorReplyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ErrorReplyTest extends AbstractModelTest
{
protected function createModel($value)
{
return new ErrorReply($value);
return new ErrorReply((string) $value);
}

public function testError()
Expand Down
4 changes: 2 additions & 2 deletions tests/Model/MultiBulkReplyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public function testNullMultiBulkReply()
/**
* @param MultiBulkReply $model
* @depends testNullMultiBulkReply
* @expectedException UnexpectedValueException
*/
public function testNullMultiBulkReplyIsNotARequest(MultiBulkReply $model)
{
$this->setExpectedException('UnexpectedValueException');
$model->getRequestModel();
}

Expand Down Expand Up @@ -91,10 +91,10 @@ public function testMixedReply()
/**
* @param MultiBulkReply $model
* @depends testMixedReply
* @expectedException UnexpectedValueException
*/
public function testMixedReplyIsNotARequest(MultiBulkReply $model)
{
$this->setExpectedException('UnexpectedValueException');
$model->getRequestModel();
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Parser/AbstractParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ abstract class AbstractParserTest extends TestCase

abstract protected function createParser();

public function setUp()
/**
* @before
*/
public function setUpParser()
{
$this->parser = $this->createParser();
$this->assertInstanceOf('Clue\Redis\Protocol\Parser\ParserInterface', $this->parser);
Expand Down
8 changes: 2 additions & 6 deletions tests/Parser/RequestParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,19 @@ public function testWhitespaceInlineIsIgnored()
$this->assertEquals(array(), $this->parser->pushIncoming($message));
}

/**
* @expectedException Clue\Redis\Protocol\Parser\ParserException
*/
public function testInvalidMultiBulkMustContainBulk()
{
$message = "*1\r\n:123\r\n";

$this->setExpectedException('Clue\Redis\Protocol\Parser\ParserException');
$this->parser->pushIncoming($message);
}

/**
* @expectedException Clue\Redis\Protocol\Parser\ParserException
*/
public function testInvalidBulkLength()
{
$message = "*1\r\n$-1\r\n";

$this->setExpectedException('Clue\Redis\Protocol\Parser\ParserException');
$this->parser->pushIncoming($message);
}
}
4 changes: 1 addition & 3 deletions tests/Parser/ResponseParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@ public function testParsingMultiBulkReplyWithNullElement()
$this->assertEquals(array('foo', null, 'bar'), $data);
}

/**
* @expectedException Clue\Redis\Protocol\Parser\ParserException
*/
public function testParseError()
{
$this->setExpectedException('Clue\Redis\Protocol\Parser\ParserException');
$this->parser->pushIncoming("invalid string\r\n");
}
}
17 changes: 9 additions & 8 deletions tests/Serializer/AbstractSerializerTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<?php

use Clue\Redis\Protocol\Serializer\SerializerInterface;
//use Exception;

abstract class AbstractSerializerTest extends TestCase
{
/** @var SerializerInterface */
private $serializer;

/**
* @return SerializerInterface
*/
abstract protected function createSerializer();

public function setUp()
/**
* @before
*/
public function setUpSerializer()
{
$this->serializer = $this->createSerializer();
}
Expand Down Expand Up @@ -89,19 +94,15 @@ public function testErrorReply()
$this->assertEquals($model->getMessageSerialized($this->serializer), $this->serializer->getReplyMessage(new Exception('ERR failure')));
}

/**
* @expectedException InvalidArgumentException
*/
public function testInvalidArgument()
{
$this->setExpectedException('InvalidArgumentException');
$this->serializer->createReplyModel((object)array());
}

/**
* @expectedException InvalidArgumentException
*/
public function testInvalidReplyData()
{
$this->setExpectedException('InvalidArgumentException');
$this->serializer->getReplyMessage((object)array());
}

Expand Down
18 changes: 17 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<?php

class TestCase extends PHPUnit_Framework_TestCase
class TestCase extends \PHPUnit\Framework\TestCase
{
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5.2+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}
}

0 comments on commit dc8c965

Please sign in to comment.