PHPackages                             grano22/test-kit - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. grano22/test-kit

ActiveLibrary[Testing &amp; Quality](/categories/testing)

grano22/test-kit
================

Test kit contains some utils to help you write your test in nice fashion

00PHPCI passing

Since Aug 3Pushed 11mo agoCompare

[ Source](https://github.com/Grano22/test-kit)[ Packagist](https://packagist.org/packages/grano22/test-kit)[ RSS](/packages/grano22-test-kit/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Test Kit Pack
=================

[](#php-test-kit-pack)

[![Latest Version](https://camo.githubusercontent.com/b73b7b293e2f4ea793c069c939eaa895032bcaa62cdc1ab1949d2de240676960/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772616e6f32322f746573742d6b69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grano22/test-kit)[![Total Downloads](https://camo.githubusercontent.com/4660bba91727d0c357737de6e542c5148c4fddd00e21154f5293bd6ea3900482/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772616e6f32322f746573742d6b69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grano22/test-kit)[![License](https://camo.githubusercontent.com/a411cfbb74cae5e74b7a9237ccbc3f33e01f17a1cd53fbf76534400224bc3e2b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6772616e6f32322f746573742d6b69742e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/78644e7d78dcd6306788de20f6f5e2f118ba91bffcac1ed65d3ceb544504a438/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6772616e6f32322f746573742d6b69742e7376673f7374796c653d666c61742d737175617265)](composer.json)

Reduce testing boilerplate and make your PHP tests more elegant and maintainable 🚀

[Installation](#-installation) • [Features](#-features) • [Documentation](#-documentation) • [Contributing](#-contributing)

💡 Motivation
------------

[](#-motivation)

Writing high-quality, readable tests can be time-consuming, especially without proper tooling. This package provides elegant solutions to common testing challenges, helping you write better tests with less boilerplate.

🚀 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require grano22/test-kit --dev
```

📚 Documentation
---------------

[](#-documentation)

> 🚧 **Coming Soon!** I work on comprehensive documentation.

In the meantime, you can:

- Check the [examples](#-features) below
- Browse the [source code](https://github.com/grano22/test-kit) for implementation details
- [Open an issue](https://github.com/grano22/test-kit/issues) if you have questions

✨ Features
----------

[](#-features)

### 🎯 Operating on the array with an object navigation path

[](#-operating-on-the-array-with-an-object-navigation-path)

#### Remove Elements

[](#remove-elements)

Sometimes, in the test you need to strip something from an array (most likely dates that you don't control). It frequently creates a lot of boilerplate code in the private methods. Now you can use:

```
$structure = [
    'items' => [
        [ 'title' => 'First', 'description' => 'First description lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ut venenatis arcu.' ],
        [ 'title' => 'Second', 'description' => 'Second description lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ut venenatis arcu.' ]
    ]
];

ReferenceNode::traverseByNodePath(
    static fn(ReferenceNode $node) => $node->remove(),
    $structure,
    '.items[*].description'
);
```

📝 View Result```php \[ 'items' =&gt; \[ \[ 'title' =&gt; 'First' \], \[ 'title' =&gt; 'Second' \] \] \] ``` #### Truncate Content

[](#truncate-content)

Too long meaningful description? Don't worry, you can truncate it for assertion.

```
$structure = [
    'items' => [
        [ 'title' => 'First', 'description' => 'First description lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ut venenatis arcu.' ],
        [ 'title' => 'Second', 'description' => 'Second description lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ut venenatis arcu.' ]
    ]
];

$mappedArray = ReferenceNode::mapByNodePath(
    static fn(ReferenceNode $node) => $node->trunc(18),
    $structure,
    '.items[*].description'
);
```

📝 View Result```php \[ 'items' =&gt; \[ \[ 'title' =&gt; 'First', 'description' =&gt; 'First description ...' \], \[ 'title' =&gt; 'Second', 'description' =&gt; 'Second description...' \] \] \] ``` You can also replace some content.

```
$structure = [
    'items' => [
        [ 'title' => 'First', 'description' => 'First description.' ],
        [ 'title' => 'Second', 'description' => 'Second description.' ]
    ]
];

$mappedArray = ReferenceNode::mapByNodePath(
    static fn(ReferenceNode $node) => $node->modify(str_replace("description", "test", $node->getValue())),
    $structure,
    '.items[*].description'
);
```

📝 View Result```php \[ 'items' =&gt; \[ \[ 'title' =&gt; 'First', 'description' =&gt; 'First test.' \], \[ 'title' =&gt; 'Second', 'description' =&gt; 'Second test.' \] \] \] ``` ### 🕵️ Test Doubles - CallSpy

[](#️-test-doubles---callspy)

Call spy is just a single test double (spy) to track your calls without using phpunit mocks.

```
use Grano22\TestKit\TestDoubles\CallSpy;
use PHPUnit\Framework\Assert;

$someClass = new class() extends Assert {
    use CallSpy;

    public function someMethod(): void
    {
        $this->trackEach();
    }
};

$someClass->setMaxExpectedCalls(2);
$someClass->someMethod();
$someClass->someMethod();
$someClass->someMethod();

// Will throw **AssertionFailedError**, because of Assert::fail
```

### 🏗️ DDD Tactical Patterns

[](#️-ddd-tactical-patterns)

Create a universal, in-memory repository in your kit/testDriver, use it in the unit test

```
class ExampleEntity
{
    public function __construct(public readonly string $id)
    {
    }
}

$repository = InMemoryRepository::createOfType(ExampleEntity::class);

$repository->add($entity);
$repository->add(new ExampleEntity('2'));

$foundEntity = $repository->findById('1');
```

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Feel free to:

- 🐛 Report bugs
- 💡 Suggest features
- 🔧 Submit pull requests

📄 License
---------

[](#-license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

Made with ❤️ for the PHP testing community

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25087325?v=4)[Grano22](/maintainers/Grano22)[@Grano22](https://github.com/Grano22)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/grano22-test-kit/health.svg)

```
[![Health](https://phpackages.com/badges/grano22-test-kit/health.svg)](https://phpackages.com/packages/grano22-test-kit)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M360](/packages/dms-phpunit-arraysubset-asserts)

PHPackages © 2026

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