diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 821a8fa..e7d3465 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -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 diff --git a/.github/workflows/static-code-analysis.yml b/.github/workflows/static-code-analysis.yml index 9c03042..3a0228a 100644 --- a/.github/workflows/static-code-analysis.yml +++ b/.github/workflows/static-code-analysis.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 56092bc..a535c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/composer.json b/composer.json index 2d0545e..2c42d3b 100644 --- a/composer.json +++ b/composer.json @@ -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" @@ -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", diff --git a/tests/Feature/BlockTest.php b/tests/Feature/BlockTest.php index 7affd75..c4d529e 100644 --- a/tests/Feature/BlockTest.php +++ b/tests/Feature/BlockTest.php @@ -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"); @@ -27,20 +30,18 @@ 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(); @@ -48,39 +49,43 @@ 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); }); diff --git a/tests/Unit/LoadJsonObjectHttpTest.php b/tests/Unit/LoadJsonObjectHttpTest.php new file mode 100644 index 0000000..29b7d87 --- /dev/null +++ b/tests/Unit/LoadJsonObjectHttpTest.php @@ -0,0 +1,41 @@ +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")); + } +}