Skip to content

Commit 84d1d4f

Browse files
committed
Clean up tests namespace, update to support PHPUnit 7 and PHPUnit 6
1 parent 4b6e58d commit 84d1d4f

11 files changed

Lines changed: 63 additions & 57 deletions

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
},
2020
"require-dev": {
2121
"clue/block-react": "^1.2",
22-
"phpunit/phpunit": "^5.0 || ^4.8"
22+
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35"
2323
},
2424
"autoload": {
2525
"psr-4": { "Clue\\React\\Ami\\": "src/" }
26+
},
27+
"autoload-dev": {
28+
"psr-4": { "Clue\\Tests\\React\\Ami\\": "tests/" }
2629
}
2730
}

phpunit.xml.dist

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

3-
<phpunit bootstrap="tests/bootstrap.php"
3+
<phpunit bootstrap="vendor/autoload.php"
44
colors="true"
55
convertErrorsToExceptions="true"
66
convertNoticesToExceptions="true"

tests/ActionSenderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3+
namespace Clue\Tests\React\Ami;
4+
35
use Clue\React\Ami\ActionSender;
4-
use Clue\React\Ami\Client;
56
use Clue\React\Ami\Protocol\Action;
67
use Clue\React\Ami\Protocol\Event;
78
use Clue\React\Ami\Protocol\Response;

tests/ClientTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
use React\Stream\Stream;
4-
use Clue\React\Ami\Protocol\Parser;
3+
namespace Clue\Tests\React\Ami;
4+
55
use Clue\React\Ami\Client;
6-
use React\EventLoop\Factory;
6+
use Clue\React\Ami\Protocol\Parser;
77
use Clue\React\Ami\Protocol\Response;
88

99
class ClientTest extends TestCase

tests/FactoryTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Clue\Tests\React\Ami;
4+
35
use Clue\React\Ami\Factory;
46
use React\Promise\Promise;
57

@@ -17,6 +19,9 @@ public function setUp()
1719
$this->factory = new Factory($this->loop, $this->tcp);
1820
}
1921

22+
/**
23+
* @doesNotPerformAssertions
24+
*/
2025
public function testDefaultCtor()
2126
{
2227
$this->factory = new Factory($this->loop);

tests/FunctionalTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Clue\Tests\React\Ami;
4+
35
use Clue\React\Ami\Factory;
46
use Clue\React\Ami\Client;
57
use Clue\React\Ami\ActionSender;
@@ -14,7 +16,7 @@ class FunctionalTest extends TestCase
1416
public static function setUpBeforeClass()
1517
{
1618
self::$address = getenv('LOGIN');
17-
self::$loop = React\EventLoop\Factory::create();
19+
self::$loop = \React\EventLoop\Factory::create();
1820
}
1921

2022
public function setUp()
@@ -45,7 +47,8 @@ public function testPing(Client $client)
4547
$sender = new ActionSender($client);
4648

4749
$pong = $this->waitFor($sender->ping());
48-
/* @var $pong Response */
50+
51+
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $pong);
4952
}
5053

5154
/**
@@ -67,7 +70,8 @@ public function testActionSenderLogoffDisconnects(Client $client)
6770
$sender = new ActionSender($client);
6871

6972
$ret = $this->waitFor($sender->logoff());
70-
/* @var $ret Response */
73+
74+
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $ret);
7175

7276
$this->assertFalse($client->isBusy());
7377

tests/Protocol/ActionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3+
namespace Clue\Tests\React\Ami\Protocol;
4+
35
use Clue\React\Ami\Protocol\Action;
6+
use Clue\Tests\React\Ami\TestCase;
47

58
class ActionTest extends TestCase
69
{

tests/Protocol/ParserTest.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3+
namespace Clue\Tests\React\Ami\Protocol;
4+
35
use Clue\React\Ami\Protocol\Parser;
6+
use Clue\Tests\React\Ami\TestCase;
47

58
class ParserTest extends TestCase
69
{
@@ -13,7 +16,7 @@ public function testParseResponse()
1316
$this->assertCount(1, $ret);
1417

1518
$first = reset($ret);
16-
/* @var $first Clue\React\Ami\Protocol\Response */
19+
/* @var $first \Clue\React\Ami\Protocol\Response */
1720

1821
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
1922
$this->assertEquals('Success', $first->getFieldValue('Response'));
@@ -28,7 +31,7 @@ public function testParseResponseSpace()
2831
$this->assertCount(1, $ret);
2932

3033
$first = reset($ret);
31-
/* @var $first Clue\React\Ami\Protocol\Response */
34+
/* @var $first \Clue\React\Ami\Protocol\Response */
3235

3336
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
3437
$this->assertEquals(' spaces ', $first->getFieldValue('Message'));
@@ -43,7 +46,7 @@ public function testParsingMultipleEvents()
4346
$this->assertCount(2, $ret);
4447

4548
$first = reset($ret);
46-
/* @var $first Clue\React\Ami\Protocol\Event */
49+
/* @var $first \Clue\React\Ami\Protocol\Event */
4750

4851
$this->assertInstanceOf('Clue\React\Ami\Protocol\Event', $first);
4952
$this->assertEquals('TestA', $first->getName());
@@ -58,7 +61,7 @@ public function testParseResponseMultipleValues()
5861
$this->assertCount(1, $ret);
5962

6063
$first = reset($ret);
61-
/* @var $first Clue\React\Ami\Protocol\Response */
64+
/* @var $first \Clue\React\Ami\Protocol\Response */
6265

6366
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
6467
$this->assertEquals('one', $first->getFieldValue('Message'));
@@ -74,7 +77,7 @@ public function testParsingCommandResponse()
7477
$this->assertCount(1, $ret);
7578

7679
$first = reset($ret);
77-
/* @var $first Clue\React\Ami\Protocol\Response */
80+
/* @var $first \Clue\React\Ami\Protocol\Response */
7881

7982
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
8083
$this->assertEquals('Follows', $first->getFieldValue('Response'));
@@ -90,7 +93,7 @@ public function testParsingCommandResponseEmpty()
9093
$this->assertCount(1, $ret);
9194

9295
$first = reset($ret);
93-
/* @var $first Clue\React\Ami\Protocol\Response */
96+
/* @var $first \Clue\React\Ami\Protocol\Response */
9497

9598
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
9699
$this->assertEquals('Follows', $first->getFieldValue('Response'));
@@ -106,7 +109,7 @@ public function testParsingResponseIsNotCommandResponse()
106109
$this->assertCount(1, $ret);
107110

108111
$first = reset($ret);
109-
/* @var $first Clue\React\Ami\Protocol\Response */
112+
/* @var $first \Clue\React\Ami\Protocol\Response */
110113

111114
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
112115
$this->assertEquals('Success', $first->getFieldValue('Response'));
@@ -133,7 +136,7 @@ public function testParsingMissingSpaceWithValue()
133136
$this->assertCount(1, $ret);
134137

135138
$first = reset($ret);
136-
/* @var $first Clue\React\Ami\Protocol\Response */
139+
/* @var $first \Clue\React\Ami\Protocol\Response */
137140

138141
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
139142
$this->assertEquals('NoSpace', $first->getFieldValue('Response'));
@@ -148,7 +151,7 @@ public function testParsingMissingSpaceEmptyValue()
148151
$this->assertCount(1, $ret);
149152

150153
$first = reset($ret);
151-
/* @var $first Clue\React\Ami\Protocol\Response */
154+
/* @var $first \Clue\React\Ami\Protocol\Response */
152155

153156
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $first);
154157
$this->assertEquals('', $first->getFieldValue('Response'));

tests/Protocol/UnexpectedMessageExceptionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
22

3+
namespace Clue\Tests\React\Ami\Protocol;
4+
35
use Clue\React\Ami\Protocol\Response;
46
use Clue\React\Ami\Protocol\UnexpectedMessageException;
7+
use Clue\Tests\React\Ami\TestCase;
58

69
class UnexpectedMessageExceptionTest extends TestCase
710
{

tests/TestCase.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Clue\Tests\React\Ami;
4+
5+
use PHPUnit\Framework\TestCase as BaseTestCase;
6+
7+
class TestCase extends BaseTestCase
8+
{
9+
protected function expectCallableOnce()
10+
{
11+
$mock = $this->createCallableMock();
12+
$mock
13+
->expects($this->once())
14+
->method('__invoke');
15+
16+
return $mock;
17+
}
18+
19+
protected function createCallableMock()
20+
{
21+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
22+
}
23+
}

0 commit comments

Comments
 (0)