forked from Hi-Folks/data-block
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUrlTest.php
More file actions
67 lines (51 loc) · 2.07 KB
/
UrlTest.php
File metadata and controls
67 lines (51 loc) · 2.07 KB
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
<?php
use HiFolks\DataType\Block;
use Symfony\Component\HttpClient\HttpClient;
it('remote json', function (): void {
$url = "https://api.github.com/repos/hi-folks/data-block/commits";
$commits = Block::fromJsonUrl($url);
expect($commits)->toBeInstanceOf(Block::class);
expect($commits)->toHaveCount(30);
$myCommits = $commits->where("commit.author.name", "like", "Roberto");
foreach ($myCommits as $value) {
expect($value->get("commit.message"))->toBeString();
}
})->group("url");
it('remote json (Symfony\Contracts\HttpClient\HttpClientInterface)', function (): void {
$url = "https://api.github.com/repos/hi-folks/data-block/commits";
$commits = Block::fromHttpJsonUrl($url, HttpClient::create());
expect($commits)->toBeInstanceOf(Block::class);
expect($commits)->toHaveCount(30);
$myCommits = $commits->where("commit.author.name", "like", "Roberto");
foreach ($myCommits as $value) {
expect($value->get("commit.message"))->toBeString();
}
})->group("url");
it('remote dummyjson post', function (): void {
$url = "https://dummyjson.com/posts";
$response = Block::fromJsonUrl($url);
$posts = $response->getBlock("posts");
expect($posts)->toBeInstanceOf(Block::class);
expect($posts)->toHaveCount(30);
$lovePosts = $posts->where("tags", "has", "love");
expect($lovePosts)->toHaveCount(9);
})->group("url");
it('remote foreach', function (): void {
$url = "https://dummyjson.com/posts";
$posts = Block::fromJsonUrl($url)
->getBlock("posts")
->where(
field: "tags",
operator: "has",
value: "love",
preseveKeys: false,
)
->forEach(fn($element): array => [
"title" => strtoupper((string) $element->get("title")),
"tags" => count($element->get("tags")),
]);
expect($posts)->toBeInstanceOf(Block::class);
expect($posts)->toHaveCount(9);
expect($posts->get("0.title"))->toBe("HOPES AND DREAMS WERE DASHED THAT DAY.");
expect($posts->get("0.tags"))->toBe(3);
})->group("url");