-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoStringTest.php
68 lines (63 loc) · 1.83 KB
/
toStringTest.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
60
61
62
63
64
65
66
67
68
<?php declare(strict_types=1);
namespace Acelot\AutoMapper\Tests\Functional;
use Acelot\AutoMapper\AutoMapper as a;
use Acelot\AutoMapper\Context\Context;
use PHPUnit\Framework\TestCase;
final class toStringTest extends TestCase
{
public function testFunction(): void
{
$source = [
'id' => 10,
'width' => 0,
'netto' => 24.345,
'available' => null,
'has_delivery' => true,
'desc' => new class() {
public function __toString(): string
{
return 'description';
}
},
];
$result = a::marshalArray(
new Context(),
$source,
a::toKey('int_to_string', a::pipe(
a::get('[id]'),
a::toString()
)),
a::toKey('zero_to_string', a::pipe(
a::get('[width]'),
a::toString()
)),
a::toKey('float_to_string', a::pipe(
a::get('[netto]'),
a::toString()
)),
a::toKey('null_to_string', a::pipe(
a::get('[available]'),
a::toString()
)),
a::toKey('bool_to_string', a::pipe(
a::get('[has_delivery]'),
a::toString()
)),
a::toKey('class_to_string', a::pipe(
a::get('[desc]'),
a::toString()
)),
);
self::assertSame(
[
'int_to_string' => '10',
'zero_to_string' => '0',
'float_to_string' => '24.345',
'null_to_string' => '',
'bool_to_string' => '1',
'class_to_string' => 'description',
],
$result
);
}
}