-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconditionCtxTest.php
62 lines (57 loc) · 1.82 KB
/
conditionCtxTest.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
<?php declare(strict_types=1);
namespace Acelot\AutoMapper\Tests\Functional;
use Acelot\AutoMapper\AutoMapper as a;
use Acelot\AutoMapper\Context\Context;
use Acelot\AutoMapper\ContextInterface;
use PHPUnit\Framework\TestCase;
final class conditionCtxTest extends TestCase
{
public function testFunction(): void
{
$source = [
'id' => 10,
'title' => 'Hello, world!',
'tags' => ['one', 'two', 'three'],
];
$result = a::marshalArray(
new Context([
'id_less_than' => 10,
'title_letters' => 13,
'two_index' => 1,
]),
$source,
a::toKey('id_less_than_10', a::pipe(
a::get('[id]'),
a::conditionCtx(
fn(ContextInterface $c, $v) => $v < $c->get('id_less_than'),
a::value(true),
a::value(false)
)
)),
a::toKey('title_letters_count_is_13', a::pipe(
a::get('[title]'),
a::conditionCtx(
fn(ContextInterface $c, $v) => strlen($v) === $c->get('title_letters'),
a::value('yes'),
a::value('no')
)
)),
a::toKey('tags_index_1_is_two', a::pipe(
a::get('[tags]'),
a::conditionCtx(
fn(ContextInterface $c, $v) => $v[$c->get('two_index')] === 'two',
a::value('yes'),
a::value('no')
)
)),
);
self::assertSame(
[
'id_less_than_10' => false,
'title_letters_count_is_13' => 'yes',
'tags_index_1_is_two' => 'yes',
],
$result
);
}
}