Skip to content

Commit 6c40daf

Browse files
authored
Merge pull request #142 from SimonFrings/phpunit
2 parents 156a3c3 + 248b00e commit 6c40daf

File tree

9 files changed

+82
-33
lines changed

9 files changed

+82
-33
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
php:
14+
- 8.0
1415
- 7.4
1516
- 7.3
1617
- 7.2
@@ -28,7 +29,10 @@ jobs:
2829
- run: composer install
2930
- run: docker run -d --name mysql --net=host -e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_DATABASE=test -e MYSQL_USER=test -e MYSQL_PASSWORD=test mysql:5
3031
- run: bash tests/wait-for-mysql.sh
31-
- run: MYSQL_USER=test MYSQL_PASSWORD=test vendor/bin/phpunit
32+
- run: MYSQL_USER=test MYSQL_PASSWORD=test vendor/bin/phpunit --coverage-text
33+
if: ${{ matrix.php >= 7.3 }}
34+
- run: MYSQL_USER=test MYSQL_PASSWORD=test vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
35+
if: ${{ matrix.php < 7.3 }}
3236

3337
PHPUnit-hhvm:
3438
name: PHPUnit (HHVM)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ $ composer require react/mysql:^0.5.5
509509
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
510510

511511
This project aims to run on any platform and thus does not require any PHP
512-
extensions and supports running on legacy PHP 5.4 through current PHP 7+ and
512+
extensions and supports running on legacy PHP 5.4 through current PHP 8+ and
513513
HHVM.
514514
It's *highly recommended to use the latest supported PHP version* for this project.
515515

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"require-dev": {
1616
"clue/block-react": "^1.2",
17-
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35"
17+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
1818
},
1919
"autoload": {
2020
"psr-4": {

phpunit.xml.dist

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit backupGlobals="false"
3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
backupGlobals="false"
46
backupStaticAttributes="false"
5-
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
cacheResult="false"
69
convertErrorsToExceptions="true"
710
convertNoticesToExceptions="true"
811
convertWarningsToExceptions="true"
12+
colors="true"
913
processIsolation="false"
1014
stopOnFailure="false"
11-
bootstrap="vendor/autoload.php"
12-
>
15+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
1316
<testsuites>
1417
<testsuite name="React.MySQL Test Suite">
1518
<directory>./tests/</directory>
1619
</testsuite>
1720
</testsuites>
18-
19-
<filter>
20-
<whitelist>
21+
<coverage>
22+
<include>
2123
<directory>./src/</directory>
22-
</whitelist>
23-
</filter>
24+
</include>
25+
</coverage>
2426
<php>
2527
<env name="DB_HOST" value="127.0.0.1"/>
2628
<env name="DB_PORT" value="3306"/>
27-
<env name="DB_USER" value="test" />
28-
<env name="DB_PASSWD" value="test" />
29-
<env name="DB_DBNAME" value="test" />
29+
<env name="DB_USER" value="test"/>
30+
<env name="DB_PASSWD" value="test"/>
31+
<env name="DB_DBNAME" value="test"/>
3032
</php>
3133
</phpunit>

phpunit.xml.legacy

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
bootstrap="vendor/autoload.php"
8+
colors="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnFailure="false"
14+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd">
15+
<testsuites>
16+
<testsuite name="React.MySQL Test Suite">
17+
<directory>./tests/</directory>
18+
</testsuite>
19+
</testsuites>
20+
<filter>
21+
<whitelist>
22+
<directory>./src/</directory>
23+
</whitelist>
24+
</filter>
25+
<php>
26+
<env name="DB_HOST" value="127.0.0.1"/>
27+
<env name="DB_PORT" value="3306"/>
28+
<env name="DB_USER" value="test"/>
29+
<env name="DB_PASSWD" value="test"/>
30+
<env name="DB_DBNAME" value="test"/>
31+
</php>
32+
</phpunit>

tests/BaseTestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,21 @@ protected function expectCallableNever()
7777

7878
return $mock;
7979
}
80+
81+
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
82+
{
83+
if (method_exists($this, 'expectException')) {
84+
// PHPUnit 5.2+
85+
$this->expectException($exception);
86+
if ($exceptionMessage !== '') {
87+
$this->expectExceptionMessage($exceptionMessage);
88+
}
89+
if ($exceptionCode !== null) {
90+
$this->expectExceptionCode($exceptionCode);
91+
}
92+
} else {
93+
// legacy PHPUnit 4 - PHPUnit 5.1
94+
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
95+
}
96+
}
8097
}

tests/Io/BufferTest.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace React\Tests\MySQL\Io;
44

5-
use PHPUnit\Framework\TestCase;
65
use React\MySQL\Io\Buffer;
6+
use React\Tests\MySQL\BaseTestCase;
77

8-
class BufferTest extends TestCase
8+
class BufferTest extends BaseTestCase
99
{
1010
public function testAppendAndReadBinary()
1111
{
@@ -16,15 +16,13 @@ public function testAppendAndReadBinary()
1616
$this->assertSame('hello', $buffer->read(5));
1717
}
1818

19-
/**
20-
* @expectedException LogicException
21-
*/
2219
public function testReadBeyondLimitThrows()
2320
{
2421
$buffer = new Buffer();
2522

2623
$buffer->append('hi');
2724

25+
$this->setExpectedException('LogicException');
2826
$buffer->read(3);
2927
}
3028

@@ -38,27 +36,23 @@ public function testReadAfterSkipOne()
3836
$this->assertSame('i', $buffer->read(1));
3937
}
4038

41-
/**
42-
* @expectedException LogicException
43-
*/
4439
public function testSkipZeroThrows()
4540
{
4641
$buffer = new Buffer();
4742

4843
$buffer->append('hi');
4944

45+
$this->setExpectedException('LogicException');
5046
$buffer->skip(0);
5147
}
5248

53-
/**
54-
* @expectedException LogicException
55-
*/
5649
public function testSkipBeyondLimitThrows()
5750
{
5851
$buffer = new Buffer();
5952

6053
$buffer->append('hi');
6154

55+
$this->setExpectedException('LogicException');
6256
$buffer->skip(3);
6357
}
6458

@@ -203,14 +197,12 @@ public function testParseStringNullCharacterTwice()
203197
$this->assertEquals('world', $buffer->readStringNull());
204198
}
205199

206-
/**
207-
* @expectedException LogicException
208-
*/
209200
public function testParseStringNullCharacterThrowsIfNullNotFound()
210201
{
211202
$buffer = new Buffer();
212203
$buffer->append("hello");
213204

205+
$this->setExpectedException('LogicException');
214206
$buffer->readStringNull();
215207
}
216208
}

tests/Io/LazyConnectionTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,6 @@ public function testQueryReturnsRejectedPromiseAfterConnectionIsClosed()
795795
$ret->then($this->expectCallableNever(), $this->expectCallableOnce());
796796
}
797797

798-
/**
799-
* @expectedException React\MySQL\Exception
800-
*/
801798
public function testQueryStreamThrowsAfterConnectionIsClosed()
802799
{
803800
$factory = $this->getMockBuilder('React\MySQL\Factory')->disableOriginalConstructor()->getMock();
@@ -806,6 +803,8 @@ public function testQueryStreamThrowsAfterConnectionIsClosed()
806803
$connection = new LazyConnection($factory, '', $loop);
807804

808805
$connection->close();
806+
807+
$this->setExpectedException('React\MySQL\Exception');
809808
$connection->queryStream('SELECT 1');
810809
}
811810

tests/NoResultQueryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
class NoResultQueryTest extends BaseTestCase
99
{
10-
public function setUp()
10+
/**
11+
* @before
12+
*/
13+
public function setUpDataTable()
1114
{
1215
$connection = $this->createConnection(Loop::get());
1316

0 commit comments

Comments
 (0)