PHPackages                             snailweb/php-tests-helpers - 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. snailweb/php-tests-helpers

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

snailweb/php-tests-helpers
==========================

PHP tests helpers

1.0.3(7y ago)091PHP

Since Mar 6Pushed 7y ago1 watchersCompare

[ Source](https://github.com/xavier-rodet/php-tests-helpers)[ Packagist](https://packagist.org/packages/snailweb/php-tests-helpers)[ RSS](/packages/snailweb-php-tests-helpers/feed)WikiDiscussions master Synced 2mo ago

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

php-tests-helpers
=================

[](#php-tests-helpers)

Helpers for PHP tests

Usage
-----

[](#usage)

### AccessProtectedTrait

[](#accessprotectedtrait)

Helper to invoke methods and to get/set attributes values with private/protected visibility

```
class MyClassTest
{
    use Snailweb\Helpers\Tests\AccessProtectedTrait;

    public function testMyMethod()
    {
        // Invoke method
        $returnValue = $this->invokeMethod($object, 'methodName', ['arg1', 'arg2']);

        // Get attribute
        $attributeValue = $this->getAttribute($object, 'attributeName');

        // Set attribute
        $this->setAttribute($object, 'attributeName', $attributeValue);
    }
}
```

### TestIteratorTrait

[](#testiteratortrait)

Helper to automatically apply Iterator tests for a class.

Requirements :

- The tested class must implement Iterator (that's the point of doing this ...)
- The tested class constructor must accept no parameters
- The test class must call setUpInterator() with class name, and optionally key name and array name (example shows defaults)

```
class MyClassTest extends TestCase
{
    use Snailweb\Helpers\Tests\TestIteratorTrait;

    public function setUp(): void
    {
        $this->setUpIterator(MyClass::class, 'key', 'array');
    }

    // Do your methods tests
    // ...
}
```

Note: if you need to test the constructor of your class you must do this :

```
class MyClassTest extends TestCase
{
    use Snailweb\Helpers\Tests\TestIteratorTrait{
        testConstruct as testIteratorConstruct;
    }

    public function setUp(): void
    {
        $this->setUpIterator(MyClass::class, 'key', 'array');
    }

    public function testConstruct()
    {
        $this->testIteratorConstruct();

        // Do your constructor tests
        // ...
    }

    // Do your methods tests
    // ...
}
```

### TestSplSubjectTrait

[](#testsplsubjecttrait)

Helper to automatically apply SplSubject tests for a class.

Requirements :

- The tested class must implement SplSubject (that's the point of doing this ...)
- The tested class constructor must accept no parameters
- The test class must call setUpSplSubject() with class name, and optionally observers name (example shows defaults)

```
class MyClassTest extends TestCase
{
    use Snailweb\Helpers\Tests\TestSplSubjectTrait;

    public function setUp(): void
    {
        $this->setUpSplSubject(MyClass::class, 'observers');
    }

    // Do your methods tests
    // ...
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

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

Total

4

Last Release

2627d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d517fd68c868e68f4d47de1b46db8046495d44cee43e79fc9635e35218ae5657?d=identicon)[xavier-rodet](/maintainers/xavier-rodet)

---

Top Contributors

[![xavier-rodet](https://avatars.githubusercontent.com/u/2737842?v=4)](https://github.com/xavier-rodet "xavier-rodet (19 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/snailweb-php-tests-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/snailweb-php-tests-helpers/health.svg)](https://phpackages.com/packages/snailweb-php-tests-helpers)
```

###  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)
