Skip to content

Run tests on PHPUnit 9 and update PHPUnit configuration schema for PHPUnit 9.3 #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2020
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 @@
/.travis.yml export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests/ export-ignore
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
# lock distro so new future defaults will not break the build
dist: trusty

matrix:
jobs:
include:
- php: 5.3
dist: precise
Expand All @@ -24,9 +24,10 @@ install:
- sudo apt-get --no-install-recommends -qq install -y asterisk
- sudo cp tests/username.conf /etc/asterisk/manager.d/username.conf
- sudo /etc/init.d/asterisk reload
- composer install --no-interaction
- composer install

script:
- sudo /etc/init.d/asterisk status || sudo /etc/init.d/asterisk start
- sudo /etc/init.d/asterisk status || sleep 2
- vendor/bin/phpunit --coverage-text
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"require-dev": {
"clue/block-react": "^1.2",
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35"
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
},
"autoload": {
"psr-4": { "Clue\\React\\Ami\\": "src/" }
Expand Down
17 changes: 11 additions & 6 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="Asterisk AMI 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="Asterisk AMI Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
8 changes: 7 additions & 1 deletion tests/ActionSenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ private function createClientMock()
{
$stream = $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->getMock();

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

return $client;
}
Expand Down
8 changes: 7 additions & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public function testUnexpectedResponseEmitsErrorAndClosesClient()

private function createStreamMock()
{
return $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'onlyMethods')) {
// PHPUnit 9+
return $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->onlyMethods(array('write', 'close'))->getMock();
} else {
// legacy PHPUnit 4 - PHPUnit 8
return $this->getMockBuilder('React\Socket\Connection')->disableOriginalConstructor()->setMethods(array('write', 'close'))->getMock();
}
}
}
5 changes: 4 additions & 1 deletion tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class FactoryTest extends TestCase
private $tcp;
private $factory;

public function setUp()
/**
* @before
*/
public function setUpFactory()
{
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$this->tcp = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
Expand Down
14 changes: 10 additions & 4 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ class FunctionalTest extends TestCase
private static $address = false;
private static $loop;

public static function setUpBeforeClass()
/**
* @beforeClass
*/
public static function setUpLoopBeforeClass()
{
self::$address = getenv('LOGIN');
self::$loop = \React\EventLoop\Factory::create();
}

public function setUp()
/**
* @before
*/
public function setUpSkipTest()
{
if (self::$address === false) {
$this->markTestSkipped('No ENV named LOGIN found. Please use "export LOGIN=\'user:pass@host\'.');
Expand Down Expand Up @@ -54,10 +60,10 @@ public function testPing(Client $client)
/**
* @depends testConnection
* @param Client $client
* @expectedException Exception
*/
public function testInvalidCommandGetsRejected(Client $client)
{
$this->setExpectedException('Exception');
$this->waitFor($client->request($client->createAction('Invalid')));
}

Expand Down Expand Up @@ -85,10 +91,10 @@ public function testActionSenderLogoffDisconnects(Client $client)
/**
* @depends testActionSenderLogoffDisconnects
* @param Client $client
* @expectedException Exception
*/
public function testSendRejectedAfterClose(Client $client)
{
$this->setExpectedException('Exception');
$this->waitFor($client->request($client->createAction('Ping')));
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Protocol/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ public function testParsingResponseIsNotCommandResponse()
$this->assertEquals('Some message--END COMMAND--', $first->getFieldValue('Message'));
}

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

$this->setExpectedException('UnexpectedValueException');
$parser->push("invalid response\r\n\r\n");
}

Expand Down
25 changes: 24 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ protected function expectCallableOnce()

protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
// PHPUnit 9+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
} else {
// legacy PHPUnit 4 - PHPUnit 8
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}

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