Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.2, 8.3, 8.4]

php: [8.3, 8.4, 8.5]

name: P${{ matrix.php }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.3]
php: [8.4]
stability: [prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Changelog

## 1.0.3 - WIP
## 1.1.0 - 2026-01-02
- Add Symfony HttpClient support for loading JSON from URL. Thanks to @sonnymilton
- Update to PHP 8.5 support.
- Adding the `extractWhere()` method that allows you to recursively query data elements and extract all elements that match a given property/value pair.
- Fix `offsetAccess.invalidOffset` phpstan warning
- Upgrade to `actions/checkout@v6` for GitHub Actions

## 1.0.2 - 2025-10-05
- Adding `getIntStrict()` method for returning strict int.
Expand Down
17 changes: 11 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
}
],
"require": {
"php": "^8.2|^8.3|^8.4",
"php": "^8.3|^8.4|^8.5",
"swaggest/json-schema": "^0.12.42",
"symfony/http-client-contracts": "^3.4.4",
"symfony/yaml": "^6.4|^7.1"
"symfony/yaml": "^6.4|^7.1|^8.0"
},
"require-dev": {
"laravel/pint": "^1.2",
"pestphp/pest": "^3.0",
"pestphp/pest": "^4.0",
"phpstan/phpstan": "^2",
"rector/rector": "^2",
"symfony/http-client": "^7.4"
"symfony/http-client": "^7.4|^8.0"
},
"suggest": {
"symfony/http-client": "HTTP client implementation"
Expand All @@ -45,10 +45,15 @@
},
"scripts": {
"all": [
"@test", "@format", "@phpstan", "@rector"
"@test",
"@format",
"@phpstan",
"@rector"
],
"complete": [
"@test-with-url", "@format", "@phpstan"
"@test-with-url",
"@format",
"@phpstan"
],
"test": "vendor/bin/pest --exclude-group=url",
"test-with-url": "vendor/bin/pest",
Expand Down
49 changes: 27 additions & 22 deletions tests/Feature/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

use HiFolks\DataType\Block;

test('load JSON object HTTP', function (): void {
test("load JSON object HTTP", function (): void {
$jsonString = file_get_contents("./tests/data/story.json");

$composerContent = Block::fromJsonString($jsonString);
expect($composerContent->get("story.name"))->toBe("Home");
expect($composerContent->getBlock("story.content"))->toBeInstanceOf(Block::class);
expect($composerContent->getBlock("story.content"))->toBeInstanceOf(
Block::class,
);
expect($composerContent->get("story.content"))->toHaveKey("body");
$bodyComponents = $composerContent->getBlock("story.content.body");
expect($bodyComponents)->toHaveCount(10);
expect($bodyComponents->get("0.headline"))->toBe("New banner");
expect($bodyComponents->get("1.headline"))->toBe("Hello Everyone");
expect($bodyComponents->get("2.headline"))->toBe("We don't know what we don't know.");
expect($bodyComponents->get("2.headline"))->toBe(
"We don't know what we don't know.",
);
expect($composerContent->get("cv"))->toBe(1717763755);
});


it('load JSON object', function (): void {
it("load JSON object", function (): void {
$file = "./composer.json";
$composerContent = Block::fromJsonFile($file);
expect($composerContent->get("name"))->toBe("hi-folks/data-block");
Expand All @@ -27,60 +30,62 @@
expect($composerContent->get("authors.0.name"))->toBe("Test");
});

it('export to array', function (): void {
it("export to array", function (): void {
$file = "./composer.json";
$composerContent = Block::fromJsonFile($file);
$array = $composerContent->toArray();
expect($array)->toBeArray();
expect($array)->toHaveKeys(["name","authors"]);
expect($array)->toHaveKeys(["name", "authors"]);
expect($array["authors"])->toHaveKeys([0]);
expect($array["authors"][0])->toHaveKeys(["name"]);
expect($array["authors"][0]["name"])->toBe("Roberto B.");

});


it('load YAML object', function (): void {
it("load YAML object", function (): void {
$file = "./.github/workflows/run-tests.yml";
$workflow = Block::fromYamlFile($file);
expect($workflow->get("on"))->toBeArray();
expect($workflow->get("on"))->toHaveCount(2);
expect($workflow->get("on.0"))->toBe("push");
expect($workflow->get("on.1"))->toBe("pull_request");
expect($workflow->get("jobs.test.runs-on"))->toBe('${{ matrix.os }}');


});

it('Convert Json to Yaml', function (): void {
it("Convert Json to Yaml", function (): void {
$file = "./composer.json";
$composer1 = Block::fromJsonFile($file);
$yaml = $composer1->toYaml();
$composer2 = Block::fromYamlString($yaml);
expect($composer2->get("name"))->toBe("hi-folks/data-block");
expect($composer2->get("authors.0.name"))->toBe("Roberto B.");


});

it('has some value', function (): void {
it("has some value", function (): void {
$file = "./composer.json";
$composer = Block::fromJsonFile($file);
expect($composer->getBlock("require"))->toBeInstanceOf(Block::class);
expect($composer->getBlock("require.php"))->toBeInstanceOf(Block::class);
expect($composer->get("require.php"))->toBeString();

expect($composer->getBlock("require")->has("^8.2|^8.3|^8.4"))->toBeTrue();
expect($composer->getBlock("require")->has("^8.3|^8.4|^8.5"))->toBeTrue();
expect($composer->getBlock("require")->hasKey("php"))->toBeTrue();
expect($composer->getBlock("require-dev")->hasKey("pestphp/pest"))->toBeTrue();
expect(
$composer->getBlock("require-dev")->hasKey("pestphp/pest"),
)->toBeTrue();
});

it('tests some value for composer.lock', function (): void {
it("tests some value for composer.lock", function (): void {
$file = "./tests/data/dummy-composer.lock";
$composer = Block::fromJsonFile($file);
expect($composer->getBlock("packages"))->toBeInstanceOf(Block::class);
expect($composer->getBlock("packages"))->toHaveCount(7);
expect($composer->getBlock("packages")->where("dist.type", "zip"))->toHaveCount(7);
expect($composer->getBlock("packages")->where("dist.type", "zip"))->toHaveCount(7);
expect($composer->getBlock("packages")->where("source.type", "git"))->toHaveCount(7);
expect(
$composer->getBlock("packages")->where("dist.type", "zip"),
)->toHaveCount(7);
expect(
$composer->getBlock("packages")->where("dist.type", "zip"),
)->toHaveCount(7);
expect(
$composer->getBlock("packages")->where("source.type", "git"),
)->toHaveCount(7);
});
41 changes: 41 additions & 0 deletions tests/Unit/LoadJsonObjectHttpTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use PHPUnit\Framework\TestCase;
use HiFolks\DataType\Block;

class LoadJsonObjectHttpTest extends TestCase
{
public function testLoadJsonObjectHttp(): void
{
$jsonString = file_get_contents(__DIR__ . "/../data/story.json");

$composerContent = Block::fromJsonString($jsonString);

$this->assertSame("Home", $composerContent->get("story.name"));

$this->assertInstanceOf(
Block::class,
$composerContent->getBlock("story.content"),
);

$this->assertArrayHasKey(
"body",
$composerContent->get("story.content"),
);

$bodyComponents = $composerContent->getBlock("story.content.body");

$this->assertCount(10, $bodyComponents);

$this->assertSame("New banner", $bodyComponents->get("0.headline"));

$this->assertSame("Hello Everyone", $bodyComponents->get("1.headline"));

$this->assertSame(
"We don't know what we don't know.",
$bodyComponents->get("2.headline"),
);

$this->assertSame(1717763755, $composerContent->get("cv"));
}
}