Skip to content

Commit 2a94112

Browse files
committed
Merge branch 'master' into v3
2 parents ad730d4 + be64a52 commit 2a94112

4 files changed

Lines changed: 22 additions & 26 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017-2019 amphp
3+
Copyright (c) 2017-2021 amphp (Niklas Keller, Aaron Piotrowski, and contributors)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
**Required PHP Version**
88

9-
- PHP 7.0+
9+
- PHP 7.1+
1010

1111
## Installation
1212

@@ -32,26 +32,8 @@ class BarTest extends AsyncTestCase
3232
{
3333
$socket = yield Socket\connect('tcp://localhost:12345');
3434
yield $socket->write('foobar');
35-
35+
3636
$this->assertSame('foobar', yield ByteStream\buffer($socket));
3737
}
3838
}
3939
```
40-
41-
#### Deprecated Functionality
42-
43-
This package also provides a PHPUnit `TestListener` to reset the global event loop after each test, but this is deprecated.
44-
45-
```xml
46-
<phpunit>
47-
<!-- ... -->
48-
49-
<!-- DEPRECATED, use AsyncTestCase instead -->
50-
<listeners>
51-
<!-- DEPRECATED, use AsyncTestCase instead -->
52-
<listener class="Amp\PHPUnit\LoopReset" />
53-
</listeners>
54-
55-
<!-- ... -->
56-
</phpunit>
57-
```

src/AsyncTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ final protected function setMinimumRuntime(float $seconds): void
153153
*/
154154
final protected function setTimeout(float $seconds): void
155155
{
156+
if (isset($this->timeoutId)) {
157+
EventLoop::cancel($this->timeoutId);
158+
}
159+
156160
$this->timeoutId = EventLoop::delay($seconds, function () use ($seconds): void {
157161
EventLoop::setErrorHandler(null);
158162

test/AsyncTestCaseTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,20 @@ public function testReturnValueFromDependentTest(string $value = null): void
123123

124124
public function testSetTimeout(): void
125125
{
126-
$this->setTimeout(0.1);
126+
$this->setTimeout(0.5);
127127
$this->expectNotToPerformAssertions();
128128

129-
delay(0.05);
129+
delay(0.25);
130+
}
131+
132+
public function testSetTimeoutReplace(): void
133+
{
134+
$this->setTimeout(0.5);
135+
$this->setTimeout(1);
136+
137+
delay(0.75);
138+
139+
$this->expectNotToPerformAssertions();
130140
}
131141

132142
public function testSetTimeoutWithFuture(): Future
@@ -155,12 +165,12 @@ public function testSetTimeoutWithAwait(): void
155165

156166
public function testSetMinimumRunTime(): void
157167
{
158-
$this->setMinimumRuntime(0.1);
168+
$this->setMinimumRuntime(1);
159169

160170
$this->expectException(AssertionFailedError::class);
161-
$this->expectExceptionMessageMatches("/Expected test to take at least 0.100s but instead took 0.\d{3}s/");
171+
$this->expectExceptionMessageMatches("/Expected test to take at least 1.000s but instead took 0.\d{3}s/");
162172

163-
delay(0.05);
173+
delay(0.5);
164174
}
165175

166176
public function testCreateCallback(): void

0 commit comments

Comments
 (0)