dentelis / phpunit-json-assert
PhpUnit extension for asserting json structure with dentelis/php-structure-validator
Installs: 32
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/dentelis/phpunit-json-assert
Requires
- php: ~8.2
- ext-mbstring: *
- dentelis/php-json-structure-validator: ^2.0.0
Requires (Dev)
- phpunit/phpunit: ^10.2@dev
This package is auto-updated.
Last update: 2025-12-01 00:08:49 UTC
README
PHPUnit data structure validation for JSON documents
Installation
Use the package manager composer to install Validator.
composer require dentelis/phpunit-json-assert:dev-master
Usage
Add JsonAssertions trait to your test file
<?php declare(strict_types=1); use Dentelis\PhpUnitJsonAssert\JsonAssertions; use Dentelis\StructureValidator\Type\ObjectType; use Dentelis\StructureValidator\Type\StringType; use PHPUnit\Framework\TestCase; final class CustomTest extends TestCase { use JsonAssertions; public function test(): void { $this->assertJsonStructure( '{"name":"user","email":"user@example.com"}', (new ObjectType()) ->addProperty('name', (new StringType())->assertNotEmpty()) ->addProperty('email', (new StringType())->assertEmail()) ); } }