PHPackages                             reenexe/compare-data-structure - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. reenexe/compare-data-structure

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

reenexe/compare-data-structure
==============================

1.0.0(11y ago)15.0kPHPPHP &gt;=5.4

Since Jan 24Pushed 9y ago2 watchersCompare

[ Source](https://github.com/ReenExe/CompareDataStructure)[ Packagist](https://packagist.org/packages/reenexe/compare-data-structure)[ RSS](/packages/reenexe-compare-data-structure/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Assert Structure
================

[](#assert-structure)

[![Build Status](https://camo.githubusercontent.com/5357b1c957f1d84a036c477b0ab194e13b852328c9e8382c622d44f35cf7d4c7/68747470733a2f2f7472617669732d63692e6f72672f5265656e4578652f436f6d70617265446174615374727563747572652e737667)](https://travis-ci.org/ReenExe/CompareDataStructure)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/cf6e0d2460348ff5c2357208ee512406466c2413275aef5459629ba0fd771c54/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5265656e4578652f436f6d70617265446174615374727563747572652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ReenExe/CompareDataStructure/?branch=master)[![Code Climate](https://camo.githubusercontent.com/3fea965fb1ba7a23fd630ec6c9030dee4f2ae1adab23aabff4b94aada8bd5865/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f5265656e4578652f436f6d70617265446174615374727563747572652f6261646765732f6770612e737667)](https://codeclimate.com/github/ReenExe/CompareDataStructure/badges)[![Coverage Status](https://camo.githubusercontent.com/12d63b24f6e3472f33df5866159ec5d990bfe6d49c8543cc5686777013f6f852/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f5265656e4578652f436f6d70617265446174615374727563747572652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/ReenExe/CompareDataStructure?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/9c53fd20b2182cc5c31658a3d84d359eae5bc18ee306a09f41bb779d995b2e7f/68747470733a2f2f706f7365722e707567782e6f72672f7265656e6578652f636f6d706172652d646174612d7374727563747572652f762f737461626c65)](https://packagist.org/packages/reenexe/compare-data-structure) [![Total Downloads](https://camo.githubusercontent.com/3a6b77c39878c0d557992cf968dba6652c5964d66444adeed746de07640d8f2a/68747470733a2f2f706f7365722e707567782e6f72672f7265656e6578652f636f6d706172652d646174612d7374727563747572652f646f776e6c6f616473)](https://packagist.org/packages/reenexe/compare-data-structure)[![License](https://camo.githubusercontent.com/630629d66231d4e23584aa846aed6e42e54b765719a6c9bb7517df6e6b785385/68747470733a2f2f706f7365722e707567782e6f72672f7265656e6578652f636f6d706172652d646174612d7374727563747572652f6c6963656e7365)](https://packagist.org/packages/reenexe/compare-data-structure)

Native PHP assert for testing REST API JSON response

Include a dependency in your `composer.json` file:

```
{
    "require": {
        "reenexe/compare-data-structure": "1.0.0"
    }
}

```

Example:
--------

[](#example)

You have REST API method that return response like:

```
{
    "id": 3,
    "name": "Alex",
    "location": 3,
    "gender": "men",
    "joined": {
        "source": 1,
        "at": "2011-11-11 11:11:11"
    },
    "friends": [
        {
            "id": 7,
            "name": "Alice"
        },
        {
            "id": 8,
            "name": "Bob"
        }
    ],
    "interests": ["programming", "books", "sport"],
    "games": null,
    "books": [
        {
            "author": "Достоевский Фёдор Михайлович",
            "title": "Преступление и наказание"
        },
        {
            "author": "Steve McConnell",
            "title": "Code Complete"
        }
    ],
    "social": ["GitHub", "LinkedIn"]
}
```

And we want to check these structures through the settings:

```
[
    'assoc' => [
        'id'    => 'integer',
        'name'  => 'string',
        'location'  => 'integer',
        'gender'    => [
            'set' => ['men', 'women', null]
        ],
        'joined'    => [
            'assoc' => [
                'source'    => 'integer|null',
                'at'        => 'string'
            ]
        ],
        'friends' => [
            'type' => 'null',
            'values' => [
                'id'    => 'integer',
                'name'  => 'string'
            ]
        ],
        'interests' => [
            'type' => 'null',
            'values' => 'string'
        ],
        'games' => [
            'type'  => 'null',
            'values' => [
                'title' => 'string'
            ]
        ],
        'books' => [
            'values' => [
                'author' => 'string',
                'title'  => 'string',
            ]
        ],
        'social' => [
            'set' => [
                'GitHub', 'LinkedIn', 'Facebook', 'Google', 'Twitter',
            ]
        ]
    ]
]
```

In this example, tried to describe the full scope

Also:
-----

[](#also)

We can test the simple types

```
1
```

```
'integer'
```

or

```
array_merge(
    range(1, 100),
    range('a', 'z'),
    [true, false]
)
```

```
['values' => 'integer|string|boolean']
```

Use:
----

[](#use)

```
/**
 * @return StructureDiffInfo
 */
Comparator::check($data, $structure)

/**
 * @method public bool StructureDiffInfo::isEqual
 * @method public string StructureDiffInfo::getMessage
 * @method public string StructureDiffInfo::getPath
 */
```

in PHPUnit easy:

```
use ReenExe\CompareDataStructure\Comparator;

class Test extends PHPUnit_Framework_TestCase{

    public function testSimple()
    {
        $diff = Comparator::check(1, 'integer');
        $this->assertTrue($diff->isEqual(), $diff);
    }
}
```

Custom types (or `user types`):
-------------------------------

[](#custom-types-or-user-types)

We can set user-defined types once and use them on:

```
    Comparator::addCustom(array $custom)
```

Example:

```
Comparator::addCustom(                [
    'profile' => [
        'assoc' => [
            'id' => 'integer',
            'name' => 'string'
        ]
    ]
]);
...
Comparator::check($profile, 'profile');
...
Comparator::check($response, 'profile');
...
```

And also to establish the types of one-time inspection:

```
Comparator::check(
    $data = [
        'value' => 1,
        'next' => [
            'value' => 3,
            'next' => [
                'value' => 5,
                'next' => null
            ]
        ]
    ],
    $structure = 'link',
    $custom = [
        'link' => [
            'assoc' => [
                'value' => 'integer',
                'next'  => 'link|null'
            ]
        ]
    ]
);
```

In `user types` - possibility of recursive checks

`@TODO` or to be continued...
-----------------------------

[](#todo-or-to-be-continued)

Together with the structures of `assoc`,` values`, `set` - there is a desire to add structure `range`Adding `strict`

Alternatives:
-------------

[](#alternatives)

AssertJsonStructure: - part of it was used to create, also `used idea of checking the structure`

json-schema:

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4132d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a976faa96ee318ce216345fd4c361eb45faa3e2ed5a98269164ebfb5f7227ecb?d=identicon)[ReenExe](/maintainers/ReenExe)

---

Top Contributors

[![ReenExe](https://avatars.githubusercontent.com/u/10358615?v=4)](https://github.com/ReenExe "ReenExe (77 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/reenexe-compare-data-structure/health.svg)

```
[![Health](https://phpackages.com/badges/reenexe-compare-data-structure/health.svg)](https://phpackages.com/packages/reenexe-compare-data-structure)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
