-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoBoolTest.php
69 lines (64 loc) · 1.88 KB
/
toBoolTest.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
69
<?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 toBoolTest extends TestCase
{
public function testFunction(): void
{
$source = [
'id' => 10,
'parent_id' => 0,
'title' => 'Hello, world!',
'desc' => '',
'tags' => ['one', 'two', 'three'],
'attrs' => [],
'available' => null,
];
$result = a::marshalArray(
new Context(),
$source,
a::toKey('int_to_bool', a::pipe(
a::get('[id]'),
a::toBool()
)),
a::toKey('zero_to_bool', a::pipe(
a::get('[parent_id]'),
a::toBool()
)),
a::toKey('string_to_bool', a::pipe(
a::get('[title]'),
a::toBool()
)),
a::toKey('empty_string_to_bool', a::pipe(
a::get('[desc]'),
a::toBool()
)),
a::toKey('array_to_bool', a::pipe(
a::get('[tags]'),
a::toBool()
)),
a::toKey('empty_array_to_bool', a::pipe(
a::get('[attrs]'),
a::toBool()
)),
a::toKey('null_to_bool', a::pipe(
a::get('[available]'),
a::toBool()
)),
);
self::assertSame(
[
'int_to_bool' => true,
'zero_to_bool' => false,
'string_to_bool' => true,
'empty_string_to_bool' => false,
'array_to_bool' => true,
'empty_array_to_bool' => false,
'null_to_bool' => false,
],
$result
);
}
}