Skip to content

Commit 2fab267

Browse files
committed
Update to support PHPUnit 7, PHPUnit 6 and PHPUnit 5
1 parent 3693360 commit 2fab267

9 files changed

Lines changed: 58 additions & 53 deletions

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"autoload": {
1414
"psr-4": { "Clue\\React\\Docker\\": "src/" }
1515
},
16+
"autoload-dev": {
17+
"psr-4": { "Clue\\Tests\\React\\Docker\\": "tests/" }
18+
},
1619
"require": {
1720
"php": ">=5.3",
1821
"react/event-loop": "~0.3.0|~0.4.0",
@@ -26,6 +29,6 @@
2629
"clue/block-react": "~0.3.0",
2730
"clue/caret-notation": "~0.2.0",
2831
"clue/tar-react": "~0.1.0",
29-
"phpunit/phpunit": "^4.8.35"
32+
"phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35"
3033
}
3134
}

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/ClientTest.php

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

3+
namespace Clue\Tests\React\Docker;
4+
35
use Clue\React\Docker\Client;
46
use React\Promise\Deferred;
57
use Clue\React\Buzz\Browser;
@@ -20,13 +22,13 @@ class ClientTest extends TestCase
2022

2123
public function setUp()
2224
{
23-
$this->loop = $this->getMock('React\EventLoop\LoopInterface');
25+
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
2426
$this->sender = $this->getMockBuilder('Clue\React\Buzz\Io\Sender')->disableOriginalConstructor()->getMock();
2527
$this->browser = new Browser($this->loop, $this->sender);
2628
$this->browser = $this->browser->withBase('http://x/');
2729

28-
$this->parser = $this->getMock('Clue\React\Docker\Io\ResponseParser');
29-
$this->streamingParser = $this->getMock('Clue\React\Docker\Io\StreamingParser');
30+
$this->parser = $this->getMockBuilder('Clue\React\Docker\Io\ResponseParser')->getMock();
31+
$this->streamingParser = $this->getMockBuilder('Clue\React\Docker\Io\StreamingParser')->getMock();
3032
$this->client = new Client($this->browser, $this->parser, $this->streamingParser);
3133
}
3234

@@ -41,7 +43,7 @@ public function testPing()
4143
public function testEvents()
4244
{
4345
$json = array();
44-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
46+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
4547

4648
$this->expectRequest('GET', '/events', $this->createResponseJsonStream($json));
4749
$this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream));
@@ -53,7 +55,7 @@ public function testEvents()
5355
public function testEventsArgs()
5456
{
5557
$json = array();
56-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
58+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
5759

5860
$this->expectRequest('GET', '/events?since=10&until=20&filters=%7B%22image%22%3A%5B%22busybox%22%2C%22ubuntu%22%5D%7D', $this->createResponseJsonStream($json));
5961
$this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream));
@@ -122,7 +124,7 @@ public function testContainerExport()
122124

123125
public function testContainerExportStream()
124126
{
125-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
127+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
126128

127129
$this->expectRequest('get', '/containers/123/export', $this->createResponse(''));
128130
$this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream));
@@ -248,7 +250,7 @@ public function testContainerCopy()
248250

249251
public function testContainerCopyStream()
250252
{
251-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
253+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
252254

253255
$this->expectRequest('post', '/containers/123/copy', $this->createResponse(''));
254256
$this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream));
@@ -276,7 +278,7 @@ public function testImageListAll()
276278
public function testImageCreate()
277279
{
278280
$json = array();
279-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
281+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
280282

281283
$this->expectRequest('post', '/images/create?fromImage=busybox', $this->createResponseJsonStream($json));
282284
$this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream));
@@ -287,7 +289,7 @@ public function testImageCreate()
287289

288290
public function testImageCreateStream()
289291
{
290-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
292+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
291293

292294
$this->expectRequest('post', '/images/create?fromImage=busybox', $this->createResponseJsonStream(array()));
293295
$this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream));
@@ -314,7 +316,7 @@ public function testImageHistory()
314316
public function testImagePush()
315317
{
316318
$json = array();
317-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
319+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
318320

319321
$this->expectRequest('post', '/images/123/push', $this->createResponseJsonStream($json));
320322
$this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream));
@@ -325,7 +327,7 @@ public function testImagePush()
325327

326328
public function testImagePushStream()
327329
{
328-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
330+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
329331

330332
$this->expectRequest('post', '/images/123/push', $this->createResponseJsonStream(array()));
331333
$this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream));
@@ -338,7 +340,7 @@ public function testImagePushCustomRegistry()
338340
// TODO: verify headers
339341
$auth = array();
340342
$json = array();
341-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
343+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
342344

343345
$this->expectRequest('post', '/images/demo.acme.com%3A5000/123/push?tag=test', $this->createResponseJsonStream($json));
344346
$this->streamingParser->expects($this->once())->method('parseJsonStream')->will($this->returnValue($stream));
@@ -411,7 +413,7 @@ public function testExecStart()
411413
{
412414
$data = 'hello world';
413415
$config = array();
414-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
416+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
415417

416418
$this->expectRequest('POST', '/exec/123/start', $this->createResponse($data));
417419
$this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream));
@@ -424,7 +426,7 @@ public function testExecStart()
424426
public function testExecStartStreamWithoutTtyWillDemultiplex()
425427
{
426428
$config = array();
427-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
429+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
428430

429431
$this->expectRequest('POST', '/exec/123/start', $this->createResponse());
430432
$this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream));
@@ -436,7 +438,7 @@ public function testExecStartStreamWithoutTtyWillDemultiplex()
436438
public function testExecStartStreamWithTtyWillNotDemultiplex()
437439
{
438440
$config = array('Tty' => true);
439-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
441+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
440442

441443
$this->expectRequest('POST', '/exec/123/start', $this->createResponse());
442444
$this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream));
@@ -448,7 +450,7 @@ public function testExecStartStreamWithTtyWillNotDemultiplex()
448450
public function testExecStartStreamWithCustomStderrEvent()
449451
{
450452
$config = array();
451-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
453+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
452454

453455
$this->expectRequest('POST', '/exec/123/start', $this->createResponse());
454456
$this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream));

tests/FactoryTest.php

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

3+
namespace Clue\Tests\React\Docker;
4+
35
use Clue\React\Docker\Factory;
46
use React\EventLoop\Factory as LoopFactory;
57

@@ -16,9 +18,12 @@ public function setUp()
1618
$this->factory = new Factory($this->loop, $this->browser);
1719
}
1820

21+
/**
22+
* @doesNotPerformAssertions
23+
*/
1924
public function testCtorDefaultBrowser()
2025
{
21-
$factory = new Factory($this->loop);
26+
new Factory($this->loop);
2227
}
2328

2429
public function testCreateClientUsesCustomUnixSender()

tests/FunctionalClientTest.php

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

3+
namespace Clue\Tests\React\Docker;
4+
35
use Clue\React\Docker\Client;
46
use React\EventLoop\Factory as LoopFactory;
57
use Clue\React\Docker\Factory;
@@ -22,7 +24,7 @@ public function setUp()
2224

2325
try {
2426
Block\await($promise, $this->loop);
25-
} catch (Exception $e) {
27+
} catch (\Exception $e) {
2628
$this->markTestSkipped('Unable to connect to docker ' . $e->getMessage());
2729
}
2830
}
@@ -337,6 +339,9 @@ public function testImageSearch()
337339
$this->assertGreaterThan(9, count($ret));
338340
}
339341

342+
/**
343+
* @doesNotPerformAssertions
344+
*/
340345
public function testImageTag()
341346
{
342347
// create new tag "bb:now" on "busybox:latest"

tests/Io/ReadableDemultiplexStreamTest.php

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

3-
use React\Stream\ReadableStream;
3+
namespace Clue\Tests\React\Docker\Io;
4+
45
use Clue\React\Docker\Io\ReadableDemultiplexStream;
6+
use Clue\Tests\React\Docker\TestCase;
7+
use React\Stream\ReadableStream;
58
use React\Stream\WritableStream;
69

710
class ReadableDemultiplexStreamTest extends TestCase
@@ -89,7 +92,7 @@ public function testPipeWillBeForwardedToTargetStream()
8992

9093
public function testPauseWillBeForwarded()
9194
{
92-
$this->stream = $this->getMock('React\Stream\ReadableStreamInterface');
95+
$this->stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
9396
$this->stream->expects($this->once())->method('pause');
9497
$this->parser = new ReadableDemultiplexStream($this->stream);
9598

@@ -98,7 +101,7 @@ public function testPauseWillBeForwarded()
98101

99102
public function testResumeWillBeForwarded()
100103
{
101-
$this->stream = $this->getMock('React\Stream\ReadableStreamInterface');
104+
$this->stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
102105
$this->stream->expects($this->once())->method('resume');
103106
$this->parser = new ReadableDemultiplexStream($this->stream);
104107

tests/Io/ResponseParserTest.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\Docker\Io;
4+
35
use Clue\React\Docker\Io\ResponseParser;
6+
use Clue\Tests\React\Docker\TestCase;
47
use RingCentral\Psr7\Response;
58

69
class ResponseParserTest extends TestCase

tests/Io/StreamingParserTest.php

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

3+
namespace Clue\Tests\React\Docker\Io;
4+
35
use Clue\React\Docker\Io\StreamingParser;
6+
use Clue\Tests\React\Docker\TestCase;
7+
use React\Promise;
8+
use React\Promise\CancellablePromiseInterface;
49
use React\Promise\Deferred;
510
use React\Stream\ReadableStream;
6-
use React\Promise\CancellablePromiseInterface;
7-
use React\Promise;
811

912
class StreamingParserTest extends TestCase
1013
{
@@ -31,7 +34,7 @@ public function testJsonRejectingPromiseWillEmitErrorAndCloseEvent()
3134

3235
$this->assertTrue($stream->isReadable());
3336

34-
$exception = new RuntimeException();
37+
$exception = new \RuntimeException();
3538

3639
$stream->on('error', $this->expectCallableOnceWith($exception));
3740
$stream->on('close', $this->expectCallableOnce());
@@ -67,7 +70,7 @@ public function testPlainPassingRejectedPromiseResolvesWithClosedStream()
6770

6871
public function testDeferredClosedStreamWillReject()
6972
{
70-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
73+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
7174
$stream->expects($this->once())->method('isReadable')->will($this->returnValue(false));
7275

7376
$promise = $this->parser->deferredStream($stream, 'anything');
@@ -109,7 +112,7 @@ public function testDeferredStreamErrorEventWillRejectPromise()
109112

110113
public function testDeferredCancelingPromiseWillCloseStream()
111114
{
112-
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
115+
$stream = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
113116
$stream->expects($this->once())->method('isReadable')->willReturn(true);
114117

115118
$promise = $this->parser->deferredStream($stream, 'anything');
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<?php
22

3+
namespace Clue\Tests\React\Docker;
4+
35
use React\EventLoop\LoopInterface;
46
use React\Promise\PromiseInterface;
57
use React\Promise\Deferred;
68

7-
require_once __DIR__ . '/../vendor/autoload.php';
8-
9-
error_reporting(-1);
10-
11-
class TestCase extends PHPUnit_Framework_TestCase
9+
class TestCase extends \PHPUnit\Framework\TestCase
1210
{
1311
protected function expectCallableOnce()
1412
{
@@ -28,7 +26,7 @@ protected function expectCallableOnceWith($value)
2826
$mock
2927
->expects($this->once())
3028
->method('__invoke')
31-
->with($this->equalTo($value));
29+
->with($value);
3230

3331
return $mock;
3432
}
@@ -45,21 +43,12 @@ protected function expectCallableNever()
4543

4644
protected function expectCallableOnceParameter($type)
4745
{
48-
$mock = $this->createCallableMock();
49-
$mock
50-
->expects($this->once())
51-
->method('__invoke')
52-
->with($this->isInstanceOf($type));
53-
54-
return $mock;
46+
return $this->expectCallableOnceWith($this->isInstanceOf($type));
5547
}
5648

57-
/**
58-
* @link https://github.com/reactphp/react/blob/master/tests/React/Tests/Socket/TestCase.php (taken from reactphp/react)
59-
*/
6049
protected function createCallableMock()
6150
{
62-
return $this->getMock('CallableStub');
51+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
6352
}
6453

6554
protected function expectPromiseResolve($promise)
@@ -85,11 +74,3 @@ protected function expectPromiseReject($promise)
8574
return $promise;
8675
}
8776
}
88-
89-
class CallableStub
90-
{
91-
public function __invoke()
92-
{
93-
}
94-
}
95-

0 commit comments

Comments
 (0)