PHPackages                             star/structure-assertion - 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. star/structure-assertion

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

star/structure-assertion
========================

PHP Tool to assert array structure using the fluent interface

1.0.0(4mo ago)11221MITPHPPHP &gt;=8.2CI passing

Since Jul 8Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/yvoyer/structure-assertion)[ Packagist](https://packagist.org/packages/star/structure-assertion)[ RSS](/packages/star-structure-assertion/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

Structure assertion
===================

[](#structure-assertion)

PHP Tool for asserting array structures using the fluent interface.

[![Build Status](https://camo.githubusercontent.com/3689cb5ae747bbad0268ce7682a56d43ee54c90b25bbe535430fff19ed7b71be/68747470733a2f2f7472617669732d63692e6f72672f79766f7965722f7374727563747572652d617373657274696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yvoyer/structure-assertion)

Installation
------------

[](#installation)

Using [Composer](https://getcomposer.org/), run `composer require --dev star/structure-assertion`.

Usage
-----

[](#usage)

This library is usefull when you have [PHPUnit tests](https://phpunit.de), and you want to assert some nodes of an array.

```
StructureAssertion::fromArray(
    [
        'data' => [
            'id' => 11,
            'array' => [
                1,
                2,
                3,
            ],
        ],
    ]
)
    ->enterObjectNode('data') // Assert the node 'data' exists and is an object
    ->assertIsSame('id', 11) // Assert the object's property 'id' exists and match the exact value
    ->enterArrayNode('array') // Assert the node 'data' exists and is an array
    ->assertCount(3); // Assert the number of item is exactly 3
```

Construction methods
--------------------

[](#construction-methods)

- `StructureAssertion::fromArray($array);`: Using the given array.
- `StructureAssertion::fromJsonResponse($response);`: Build with a [Response](https://github.com/php-fig/http-message/blob/master/src/ResponseInterface.php) object that is assumed to have a JSON content.

Assertions methods
------------------

[](#assertions-methods)

By convention, all assertion methods are named `assert*`. Under the hood, StructureAssertion uses PHPUnit assertions. Many of the assertions are named after the PHPUnit's constraint.

You can use your own assertion if a specific one is not defined by using the `StructureAssertion::assertCallback()` method.

ie.

```
StructureAssertion::fromArray($data)
    ->assertCallback('property', function ($value): bool {
        // When it evaluates to false, the expectation will fail
        // return true | false
    });
```

Navigation methods
------------------

[](#navigation-methods)

To navigate the nodes, you can use the methods that starts with `enter*`. We assume that the current node is at the correct position.

- `StructureAssertion::exitNode()`: Move the internal pointer to the parent node.
- `StructureAssertion::nextArrayElement()`: Shortcut for `exitNode()->enterArrayElement($current + 1)`. Enters the next element at index + 1. Works only on integer indexed element.

Debugging methods
-----------------

[](#debugging-methods)

The lib also provide debugging method, in order to know the current position of the cursor.

- `StructureAssertion::dump($maxDepth = 2, $dumpStrategy)`: Will dump the current node using the `$strategy` and up to `$maxDepth`.
- `StructureAssertion::dumpPath($dumpStrategy)`: Will dump the current node path using the `$strategy`.
- `StructureAssertion::dumpKeys($dumpStrategy)`: Will dump the current node keys using the `$strategy`.

Contributing
------------

[](#contributing)

Any contribution is welcome, just propose a Pull request, and we'll look into it.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance77

Regular maintenance activity

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity70

Established project with proven stability

 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

Every ~2017 days

Total

2

Last Release

123d ago

Major Versions

0.1 → 1.0.02026-01-16

PHP version history (2 changes)0.1PHP ^7.1

1.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/36116f724f1bd3ed808e54e2b2de6c17209c5c2c1954685fba18958ec8d055ee?d=identicon)[yvoyer](/maintainers/yvoyer)

---

Top Contributors

[![yvoyer](https://avatars.githubusercontent.com/u/1745744?v=4)](https://github.com/yvoyer "yvoyer (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/star-structure-assertion/health.svg)

```
[![Health](https://phpackages.com/badges/star-structure-assertion/health.svg)](https://phpackages.com/packages/star-structure-assertion)
```

###  Alternatives

[bolt/forms

📦 This Bolt extension can be used to handle forms in your Bolt project.

2223.8k1](/packages/bolt-forms)[webbycrown/blog-for-bagisto

Blog for Bagisto

257.0k](/packages/webbycrown-blog-for-bagisto)

PHPackages © 2026

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