PHPackages                             gong023/assert\_chain - 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. gong023/assert\_chain

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

gong023/assert\_chain
=====================

enable you to use phpunit assert with method chain

0.2.0(8y ago)1478.9k43MITPHPPHP &gt;=5.4.0

Since Dec 24Pushed 8y ago1 watchersCompare

[ Source](https://github.com/gong023/assert_chain)[ Packagist](https://packagist.org/packages/gong023/assert_chain)[ RSS](/packages/gong023-assert-chain/feed)WikiDiscussions master Synced 1mo ago

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

AssertChain
===========

[](#assertchain)

[![Build Status](https://camo.githubusercontent.com/ebb2a284b9f7c0f2a7034874e854cf69d57aa899a79a80a6b7a21bb656251005/68747470733a2f2f7472617669732d63692e6f72672f676f6e673032332f6173736572745f636861696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gong023/assert_chain)

AssertChain is PHPUnit helper. It enables you to write PHPUnit assert with method chain.

Setup
=====

[](#setup)

Install AssertChain by composer.

```
composer require --dev gong023/assert_chain:dev-master
# install phpunit if you do not install yet.
# composer require --dev phpunit/phpunit:4.*
```

Import AssertChain trait to your test class.

```
class YourTestClass extends \PHPUnit_Framework_TestCase
{
    use AssertChain\AssertChain;
}
```

Usage
=====

[](#usage)

First you call `assert`, and keep asserting as you like.

You can use all assertions in PHPUnit\_Framework\_Assert.

```
public function testWithArray()
{
    $arr = [
        'intKey'    => 1,
        'stringKey' => 'foo',
        'boolKey'   => true,
    ];

    $this->assert()
      ->notEmpty($arr)
      ->arrayHasKey('intKey', $arr)
      ->same(1, $arr['intKey'])
      ->arrayHasKey('stringKey', $arr)
      ->same('foo', $arr['stringKey'])
      ->arrayHasKey('boolKey', $arr)
      ->true($arr['boolKey']);

    /*
     * above code is equal to this.
     *
     * $this->assertNotEmpty($arr);
     * $this->assertArrayHasKey('intKey', $arr);
     * $this->assertSame(1, $arr['intKey']);
     * $this->assertArrayHasKey('stringKey', $arr);
     * $this->assertSame('foo', $arr['stringKey']);
     * $this->assertArrayHasKey('boolKey', $arr);
     * $this->assertTrue($arr['boolKey']);
     */
}
```

If you are sick of writing `$actual` value too many times, you can use `centralizedAssert`.

```
public function testWithArray()
{
    $arr = ['key' => 'value'];

    $this->centralizedAssert($arr)
      ->notNull()
      ->notEmpty()
      ->notCount(0)
      ->count(1)
      ->arrayNotHasKey('no existing key')
      ->arrayHasKey('key')
      ->notContains('no existing value')
      ->contains('value')
      ->equals(['key' => 'value']);

    /*
     * above code is equal to this.
     *
     * $this->assertNotNull($arr);
     * $this->assertNotEmpty($arr);
     * $this->assertNotCount(0, $arr);
     * $this->assertCount(1, $arr);
     * $this->assertArrayNotHasKey('no existing key', $arr);
     * $this->assertNotContains('no existing value', $arr);
     * $this->assertContains('value', $arr);
     * $this->assertEquals(['key' => 'value']);
     */
}
```

`centralizedAssert` automatically sets `$actual` value to every assertions in PHPUnit\_Framework\_Assert.

You need not type `$actual` value too many times.

If you want to get more idea with centralizedAssert, [AssertChain test class will help you](https://github.com/gong023/assert_chain/blob/master/test/AssertChain/Container/AggregaterTest.php).

IDE friendly
============

[](#ide-friendly)

AssertChain is IDE friendly. You can get method autocomplete.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 72.7% 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 ~1023 days

Total

2

Last Release

3137d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/034b987bca6692b17b6a5923eca68302fec17cd13f09f8d2f0a45c6d38125c03?d=identicon)[gong023](/maintainers/gong023)

---

Top Contributors

[![gong023](https://avatars.githubusercontent.com/u/1222856?v=4)](https://github.com/gong023 "gong023 (16 commits)")[![DQNEO](https://avatars.githubusercontent.com/u/188741?v=4)](https://github.com/DQNEO "DQNEO (5 commits)")[![travail](https://avatars.githubusercontent.com/u/52314?v=4)](https://github.com/travail "travail (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gong023-assert-chain/health.svg)

```
[![Health](https://phpackages.com/badges/gong023-assert-chain/health.svg)](https://phpackages.com/packages/gong023-assert-chain)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

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