Skip to content

Commit cde9533

Browse files
committed
Move test skeleton to tests/bootstrap.php
1 parent 577b126 commit cde9533

File tree

3 files changed

+62
-57
lines changed

3 files changed

+62
-57
lines changed

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 colors="true">
3+
<phpunit colors="true" bootstrap="./tests/bootstrap.php">
44
<testsuites>
55
<testsuite name="Datagram Test Suite">
66
<directory>./tests/</directory>

tests/FactoryTest.php

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<?php
22

33
use Datagram\Socket;
4-
54
use React\Promise\When;
6-
75
use React\Promise\PromiseInterface;
86

9-
require __DIR__.'/../vendor/autoload.php';
10-
11-
class FactoryTest extends PHPUnit_Framework_TestCase
7+
class FactoryTest extends TestCase
128
{
139
private $factory;
1410

@@ -57,55 +53,4 @@ public function testCreateServer()
5753

5854
$capturedServer->close();
5955
}
60-
61-
protected function getValueFromResolvedPromise($promise)
62-
{
63-
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
64-
65-
$loop = $this->loop;
66-
$capturedValue = null;
67-
$promise->then(function ($value) use (&$capturedValue, $loop) {
68-
$capturedValue = $value;
69-
$loop->stop();
70-
}, $this->expectCallableNever());
71-
72-
// future-turn resolutions are not enforced, so the value MAY be known here already
73-
if ($capturedValue === null) {
74-
$loop->run();
75-
}
76-
77-
return $capturedValue;
78-
}
79-
80-
protected function expectCallableOnce()
81-
{
82-
$mock = $this->createCallableMock();
83-
$mock
84-
->expects($this->once())
85-
->method('__invoke');
86-
87-
return $mock;
88-
}
89-
90-
protected function expectCallableNever()
91-
{
92-
$mock = $this->createCallableMock();
93-
$mock
94-
->expects($this->never())
95-
->method('__invoke');
96-
97-
return $mock;
98-
}
99-
100-
protected function createCallableMock()
101-
{
102-
return $this->getMock('React\Tests\Socket\Stub\CallableStub');
103-
}
104-
105-
private function createResolverMock()
106-
{
107-
return $this->getMockBuilder('React\Dns\Resolver\Resolver')
108-
->disableOriginalConstructor()
109-
->getMock();
110-
}
11156
}

tests/bootstrap.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
use React\Promise\When;
4+
use React\Promise\PromiseInterface;
5+
6+
require __DIR__.'/../vendor/autoload.php';
7+
8+
abstract class TestCase extends PHPUnit_Framework_TestCase
9+
{
10+
protected function getValueFromResolvedPromise($promise)
11+
{
12+
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
13+
14+
$loop = $this->loop;
15+
$capturedValue = null;
16+
$promise->then(function ($value) use (&$capturedValue, $loop) {
17+
$capturedValue = $value;
18+
$loop->stop();
19+
}, $this->expectCallableNever());
20+
21+
// future-turn resolutions are not enforced, so the value MAY be known here already
22+
if ($capturedValue === null) {
23+
$loop->run();
24+
}
25+
26+
return $capturedValue;
27+
}
28+
29+
protected function expectCallableOnce()
30+
{
31+
$mock = $this->createCallableMock();
32+
$mock
33+
->expects($this->once())
34+
->method('__invoke');
35+
36+
return $mock;
37+
}
38+
39+
protected function expectCallableNever()
40+
{
41+
$mock = $this->createCallableMock();
42+
$mock
43+
->expects($this->never())
44+
->method('__invoke');
45+
46+
return $mock;
47+
}
48+
49+
protected function createCallableMock()
50+
{
51+
return $this->getMock('React\Tests\Socket\Stub\CallableStub');
52+
}
53+
54+
protected function createResolverMock()
55+
{
56+
return $this->getMockBuilder('React\Dns\Resolver\Resolver')
57+
->disableOriginalConstructor()
58+
->getMock();
59+
}
60+
}

0 commit comments

Comments
 (0)