-
Notifications
You must be signed in to change notification settings - Fork 32
/
StringTest.php
59 lines (54 loc) · 1.86 KB
/
StringTest.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
56
57
58
59
<?php
use Eris\Generators;
use Eris\Listeners;
function string_concatenation($first, $second)
{
if (strlen($second) > 5) {
$second .= 'ERROR';
}
return $first . $second;
}
class StringTest extends \PHPUnit\Framework\TestCase
{
use Eris\TestTrait;
public function testRightIdentityElement()
{
$this
->forAll(
Generators::string()
)
->then(function ($string) {
$this->assertEquals(
$string,
string_concatenation($string, ''),
"Concatenating '$string' to ''"
);
});
}
public function testLengthPreservation()
{
$this
->forAll(
Generators::string(),
Generators::string()
)
->hook(Listeners::log(sys_get_temp_dir().'/eris-string-shrinking.log'))
->then(function ($first, $second) {
$result = string_concatenation($first, $second);
$this->assertEquals(
strlen($first) + strlen($second),
strlen($result),
"Concatenating '$first' to '$second' gives '$result'" . PHP_EOL
. var_export($first, true) . PHP_EOL
. "strlen(): " . strlen($first) . PHP_EOL
. var_export($second, true) . PHP_EOL
. "strlen(): " . strlen($second) . PHP_EOL
. var_export($result, true) . PHP_EOL
. "strlen(): " . strlen($result) . PHP_EOL
. "First hex: " . var_export(bin2hex($first), true) . PHP_EOL
. "Second hex: " . var_export(bin2hex($second), true) . PHP_EOL
. "Result hex: " . var_export(bin2hex($result), true) . PHP_EOL
);
});
}
}