PHPackages                             vielhuber/comparehelper - 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. vielhuber/comparehelper

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

vielhuber/comparehelper
=======================

small php helper for comparing api responses in your tests.

1.2.0(1mo ago)1773↑346.7%1MITPHPPHP &gt;=7.4

Since Jul 25Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/vielhuber/comparehelper)[ Packagist](https://packagist.org/packages/vielhuber/comparehelper)[ RSS](/packages/vielhuber-comparehelper/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (22)Used By (1)

[![build status](https://github.com/vielhuber/comparehelper/actions/workflows/ci.yml/badge.svg)](https://github.com/vielhuber/comparehelper/actions)[![GitHub Tag](https://camo.githubusercontent.com/5ab6e8f4befcdf715921c076d5b217c3fec32eef7e71a4ba8e933fb8ebb0bc10/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f7669656c68756265722f636f6d7061726568656c706572)](https://github.com/vielhuber/comparehelper/tags)[![Code Style](https://camo.githubusercontent.com/1540f8ce219727155ab62506c77b818b720421c22c4cf0b18a5f160942132e2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64655f7374796c652d7073722d2d31322d6666363962342e737667)](https://www.php-fig.org/psr/psr-12/)[![License](https://camo.githubusercontent.com/60c3d93b9db9e89af8995c2062554b3c500f1dc2907ecdc9e49dd1ada0bc5dc3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7669656c68756265722f636f6d7061726568656c706572)](https://github.com/vielhuber/comparehelper/blob/main/LICENSE.md)[![Last Commit](https://camo.githubusercontent.com/002bc99eba84432218a50c4aac3d5cf720efb14e54486c87b8bf966d1f39fcf8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7669656c68756265722f636f6d7061726568656c706572)](https://github.com/vielhuber/comparehelper/commits)[![PHP Version Support](https://camo.githubusercontent.com/e38bd32563a1ad42556ebb8f40f5b50963599cfb8d626079bc0e23f0d09b6543/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7669656c68756265722f636f6d7061726568656c706572)](https://packagist.org/packages/vielhuber/comparehelper)[![Packagist Downloads](https://camo.githubusercontent.com/f403bd6eb83abd7b8ec8da0662ee36a6a4a1a5a2dc120631e9cd90fd2b6dde37/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7669656c68756265722f636f6d7061726568656c706572)](https://packagist.org/packages/vielhuber/comparehelper)

📑 comparehelper 📑
=================

[](#-comparehelper-)

comparehelper is a small php helper for comparing api responses in your tests.

installation
------------

[](#installation)

install once with composer:

```
composer require vielhuber/comparehelper

```

then add this to your files:

```
require __DIR__ . '/vendor/autoload.php';
use vielhuber\comparehelper\comparehelper;
```

usage
-----

[](#usage)

```
comparehelper::compare($var1, $var2); // true|false
```

you can use the following placeholders:

- `*`: any datatype
- `#STR#`: any string
- `#INT#`: any numeric value

examples
--------

[](#examples)

```
comparehelper::compare('foo', 'foo'); // true

comparehelper::compare(42, 42); // true

comparehelper::compare(
    [
        'foo' => 'bar'
    ],
    [
        'foo' => 'bar',
        'foo2' => 'bar'
    ]
); // false

comparehelper::compare(
    [
        'foo' => 'bar',
        'bar' => ['baz', 42]
    ],
    [
        '#STR' => '*',
        'bar' => ['#STR#', '#INT#']
    ]
); // true

// ordering is lazy
comparehelper::compare(['foo', 'bar'], ['bar', 'foo']); // true
comparehelper::compare(['#INT#', '#STR#'], [42, 'foo']); // true
comparehelper::compare(['#INT#', '#STR#'], ['foo', 42]); // false
comparehelper::compare(['foo' => 7, 'bar' => 42], ['bar' => 42, 'foo' => 7]); // true
comparehelper::compare(['#INT#' => 7, '#STR#' => 42], [7 => 7, 'foo' => 42]); // true
comparehelper::compare(['#INT#' => 7, '#STR#' => 42], ['foo' => 42, 7 => 7]); // false

// datatypes are strict
comparehelper::compare(42, '42'); // false
```

phpunit integration
-------------------

[](#phpunit-integration)

for better diff output in tests, use `assertEquals()` instead of `compare()`:

```
// instead of:
$this->assertTrue(comparehelper::compare($expected, $actual));

// use this for better diffs:
comparehelper::assertEquals($expected, $actual);

// example:
comparehelper::assertEquals(['id' => '#INT#', 'name' => '#STR#', 'status' => 'active'], $apiResponse);
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance92

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity72

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 ~143 days

Recently: every ~4 days

Total

21

Last Release

41d ago

PHP version history (3 changes)1.0.0PHP &gt;=5.6

1.0.8PHP &gt;=8.1

1.1.1PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3183737?v=4)[David Vielhuber](/maintainers/vielhuber)[@vielhuber](https://github.com/vielhuber)

---

Top Contributors

[![vielhuber](https://avatars.githubusercontent.com/u/3183737?v=4)](https://github.com/vielhuber "vielhuber (24 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vielhuber-comparehelper/health.svg)

```
[![Health](https://phpackages.com/badges/vielhuber-comparehelper/health.svg)](https://phpackages.com/packages/vielhuber-comparehelper)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

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

14429.2M361](/packages/dms-phpunit-arraysubset-asserts)[gong023/assert_chain

enable you to use phpunit assert with method chain

1478.9k3](/packages/gong023-assert-chain)

PHPackages © 2026

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