Skip to content

Commit a9607b5

Browse files
committed
add test
1 parent b497d95 commit a9607b5

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/CollectorTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ArrayLookup\Tests;
6+
7+
use ArrayLookup\Collector;
8+
use PHPUnit\Framework\TestCase;
9+
use stdClass;
10+
11+
use function is_string;
12+
use function trim;
13+
14+
final class CollectorTest extends TestCase
15+
{
16+
public function testWithoutLimit(): void
17+
{
18+
$data = [
19+
' a ',
20+
' b ',
21+
' c ',
22+
new stdClass(),
23+
];
24+
25+
$results = Collector::setUp($data)
26+
->when(fn (mixed $datum): bool => is_string($datum))
27+
->withTransform(fn (string $datum): string => trim($datum))
28+
->getResults();
29+
30+
$this->assertSame(['a', 'b', 'c'], $results);
31+
}
32+
33+
public function testWithLimit(): void
34+
{
35+
$data = [
36+
' a ',
37+
' b ',
38+
' c ',
39+
new stdClass(),
40+
];
41+
42+
$results = Collector::setUp($data)
43+
->when(fn (mixed $datum): bool => is_string($datum))
44+
->withTransform(fn (string $datum): string => trim($datum))
45+
->withLimit(1)
46+
->getResults();
47+
48+
$this->assertSame(['a'], $results);
49+
}
50+
}

0 commit comments

Comments
 (0)