-
Notifications
You must be signed in to change notification settings - Fork 32
/
ShrinkingTimeLimitTest.php
55 lines (50 loc) · 1.47 KB
/
ShrinkingTimeLimitTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
use Eris\Attributes\ErisShrink;
use Eris\Generator;
use Eris\Generators;
function very_slow_concatenation($first, $second)
{
if (strlen($second) > 10) {
sleep(2);
$second .= 'ERROR';
}
return $first . $second;
}
class ShrinkingTimeLimitTest extends \PHPUnit\Framework\TestCase
{
use Eris\TestTrait;
public function testLengthPreservation()
{
$this
->shrinkingTimeLimit(2)
->forAll(
Generators::string(),
Generators::string()
)
->then(function ($first, $second) {
$result = very_slow_concatenation($first, $second);
$this->assertEquals(
strlen($first) + strlen($second),
strlen($result),
"Concatenating '$first' to '$second' gives '$result'" . PHP_EOL
);
});
}
#[ErisShrink(shrink: 2)]
public function testLengthPreservationFromAnnotation()
{
$this
->forAll(
Generator\string(),
Generator\string()
)
->then(function ($first, $second) {
$result = very_slow_concatenation($first, $second);
$this->assertEquals(
strlen($first) + strlen($second),
strlen($result),
"Concatenating '$first' to '$second' gives '$result'" . PHP_EOL
);
});
}
}