Skip to content

Commit bf10b89

Browse files
authored
Merge pull request #65 from SimonFrings/tests
Run tests on PHPUnit 9 and update PHPUnit configuration schema for PHPUnit 9.3
2 parents 18ddeb3 + 1ff05a5 commit bf10b89

11 files changed

+88
-21
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/.travis.yml export-ignore
44
/examples/ export-ignore
55
/phpunit.xml.dist export-ignore
6+
/phpunit.xml.legacy export-ignore
67
/tests/ export-ignore

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: php
33
# lock distro so new future defaults will not break the build
44
dist: trusty
55

6-
matrix:
6+
jobs:
77
include:
88
- php: 5.3
99
dist: precise
@@ -24,9 +24,10 @@ install:
2424
- sudo apt-get --no-install-recommends -qq install -y asterisk
2525
- sudo cp tests/username.conf /etc/asterisk/manager.d/username.conf
2626
- sudo /etc/init.d/asterisk reload
27-
- composer install --no-interaction
27+
- composer install
2828

2929
script:
3030
- sudo /etc/init.d/asterisk status || sudo /etc/init.d/asterisk start
3131
- sudo /etc/init.d/asterisk status || sleep 2
32-
- vendor/bin/phpunit --coverage-text
32+
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
33+
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"require-dev": {
2121
"clue/block-react": "^1.2",
22-
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35"
22+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
2323
},
2424
"autoload": {
2525
"psr-4": { "Clue\\React\\Ami\\": "src/" }

phpunit.xml.dist

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

3-
<phpunit bootstrap="vendor/autoload.php" colors="true">
3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
cacheResult="false">
49
<testsuites>
510
<testsuite name="Asterisk AMI Test Suite">
611
<directory>./tests/</directory>
712
</testsuite>
813
</testsuites>
9-
<filter>
10-
<whitelist>
14+
<coverage>
15+
<include>
1116
<directory>./src/</directory>
12-
</whitelist>
13-
</filter>
14-
</phpunit>
17+
</include>
18+
</coverage>
19+
</phpunit>

phpunit.xml.legacy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true">
8+
<testsuites>
9+
<testsuite name="Asterisk AMI Test Suite">
10+
<directory>./tests/</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist>
15+
<directory>./src/</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

tests/ActionSenderTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ private function createClientMock()
5353
{
5454
$stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->getMock();
5555

56-
$client = $this->getMockBuilder('Clue\React\Ami\Client')->setMethods(array('createAction'))->setConstructorArgs(array($stream))->getMock();
56+
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'onlyMethods')) {
57+
// PHPUnit 9+
58+
$client = $this->getMockBuilder('Clue\React\Ami\Client')->onlyMethods(array('createAction'))->setConstructorArgs(array($stream))->getMock();
59+
} else {
60+
// legacy PHPUnit 4 - PHPUnit 8
61+
$client = $this->getMockBuilder('Clue\React\Ami\Client')->setMethods(array('createAction'))->setConstructorArgs(array($stream))->getMock();
62+
}
5763

5864
return $client;
5965
}

tests/ClientTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public function testUnexpectedResponseEmitsErrorAndClosesClient()
4545

4646
private function createStreamMock()
4747
{
48-
return $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();
48+
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'onlyMethods')) {
49+
// PHPUnit 9+
50+
return $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->onlyMethods(array('write', 'close'))->getMock();
51+
} else {
52+
// legacy PHPUnit 4 - PHPUnit 8
53+
return $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();
54+
}
4955
}
5056
}

tests/FactoryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class FactoryTest extends TestCase
1111
private $tcp;
1212
private $factory;
1313

14-
public function setUp()
14+
/**
15+
* @before
16+
*/
17+
public function setUpFactory()
1518
{
1619
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
1720
$this->tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();

tests/FunctionalTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ class FunctionalTest extends TestCase
1313
private static $address = false;
1414
private static $loop;
1515

16-
public static function setUpBeforeClass()
16+
/**
17+
* @beforeClass
18+
*/
19+
public static function setUpLoopBeforeClass()
1720
{
1821
self::$address = getenv('LOGIN');
1922
self::$loop = \React\EventLoop\Factory::create();
2023
}
2124

22-
public function setUp()
25+
/**
26+
* @before
27+
*/
28+
public function setUpSkipTest()
2329
{
2430
if (self::$address === false) {
2531
$this->markTestSkipped('No ENV named LOGIN found. Please use "export LOGIN=\'user:pass@host\'.');
@@ -54,10 +60,10 @@ public function testPing(Client $client)
5460
/**
5561
* @depends testConnection
5662
* @param Client $client
57-
* @expectedException Exception
5863
*/
5964
public function testInvalidCommandGetsRejected(Client $client)
6065
{
66+
$this->setExpectedException('Exception');
6167
$this->waitFor($client->request($client->createAction('Invalid')));
6268
}
6369

@@ -85,10 +91,10 @@ public function testActionSenderLogoffDisconnects(Client $client)
8591
/**
8692
* @depends testActionSenderLogoffDisconnects
8793
* @param Client $client
88-
* @expectedException Exception
8994
*/
9095
public function testSendRejectedAfterClose(Client $client)
9196
{
97+
$this->setExpectedException('Exception');
9298
$this->waitFor($client->request($client->createAction('Ping')));
9399
}
94100

tests/Protocol/ParserTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,12 @@ public function testParsingResponseIsNotCommandResponse()
132132
$this->assertEquals('Some message--END COMMAND--', $first->getFieldValue('Message'));
133133
}
134134

135-
/**
136-
* @expectedException UnexpectedValueException
137-
*/
138135
public function testParsingInvalidResponseFails()
139136
{
140137
$parser = new Parser();
141138
$this->assertEquals(array(), $parser->push("Asterisk Call Manager/1.3\r\n"));
142139

140+
$this->setExpectedException('UnexpectedValueException');
143141
$parser->push("invalid response\r\n\r\n");
144142
}
145143

0 commit comments

Comments
 (0)