PHPackages                             friendsofcake/cakephp-test-utilities - 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. friendsofcake/cakephp-test-utilities

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

friendsofcake/cakephp-test-utilities
====================================

Package with support traits to ease unit testing.

3.0.0(2y ago)1172.2k↑33.3%517MITPHP

Since Jun 28Pushed 2y ago5 watchersCompare

[ Source](https://github.com/FriendsOfCake/cakephp-test-utilities)[ Packagist](https://packagist.org/packages/friendsofcake/cakephp-test-utilities)[ Docs](https://github.com/friendsofcake/cakephp-test-utilities)[ RSS](/packages/friendsofcake-cakephp-test-utilities/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (12)Used By (17)

Test utilities
==============

[](#test-utilities)

This package contains support traits to ease unit testing.

Installing via composer
-----------------------

[](#installing-via-composer)

You should install this package into your project using composer. To do so you can run the following command:

```
composer require friendsofcake/cakephp-test-utilities
```

Traits
------

[](#traits)

At this point there are two traits:

1. [`AccessibilityHelperTrait`](#accessibilityhelpertrait) : Gain access protected properties and methods.
2. [`CompareTrait`](#comparetrait) : Assert methods, comparing to files for: HTML, JSON, XML

### AccessibilityHelperTrait

[](#accessibilityhelpertrait)

This trait gains you access to protected properties and methods. You don't need of a new class with pass-through methods. It uses reflection to achieve this.

#### Setup

[](#setup)

Add the trait at the top of your test case:

```
use \FriendsOfCake\TestUtilities\AccessibilityHelperTrait;
```

Now that you have the trait you need to set which object you want to access. You can do this globally for the entire test in `setUp()` or in your test methods:

```
$object = new ObjectIAmGoingToTest();
$this->setReflectionClassInstance($object);
$this->defaultReflectionTarget = $object; // (optional)
```

#### Protected properties

[](#protected-properties)

You can get and set the protected properties:

```
$data = 'FriendsOfCake';
$this->setProtectedProperty('_myProperty', $data, $object);

$expected = $data;
$actual = $this->getProtectedProperty('_myProperty', $object);
$this->assertEquals($expected, $actual);
```

#### Protected methods

[](#protected-methods)

You can directly call protected methods:

```
$parameters = [$argument1, $argument2];

$expected = $expectedReturnValue;
$actual = $this->callProtectedMethod('_myMethod', $parameters, $object);
$this->assertEquals($expected, $actual);
```

### CompareTrait

[](#comparetrait)

This trait helps with comparing test results as string

#### Setup

[](#setup-1)

Add the trait at the top of your test case and define the `_compareBasePath`property so the trait knows where to look for comparison files:

```
...
use \FriendsOfCake\TestUtilities\CompareTrait;

class MyTest extends TestCase
{
    use CompareTrait;

    public function setUp(): void
    {
        parent::setUp();

        $this->_compareBasePath = 'comparisons/MyTest/';
    }
}
```

#### Usage

[](#usage)

Each of the methods acts similar to the core `assertSameAsFile` method:

```
public function testExample()
{
    $html = 'Some html';
    $xml = '...';
    $json = ['actually' => 'this is an array'];

    $this->assertHtmlSameAsFile('some.html', $html);
    $this->assertXmlSameAsFile('some.xml', $xml);
    $this->assertJsonSameAsFile('some.json', $json);
}
```

See [Cake's docs](https://book.cakephp.org/5/en/development/testing.html#comparing-test-results-to-a-file)for more details on usage of `assertSameAsFile` on which these methods are based.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community32

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~342 days

Total

11

Last Release

968d ago

Major Versions

0.0.2 → 1.0.02018-03-24

1.x-dev → 2.0.02019-12-24

2.x-dev → 3.0.02023-09-24

PHP version history (2 changes)0.0.1PHP &gt;=5.4

1.0.0PHP ^5.6 || ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e31753bdd616948c7c8978ea9b5805378f75bfa62564e69c0aa2fd67aaf418c5?d=identicon)[ADmad](/maintainers/ADmad)

![](https://www.gravatar.com/avatar/c314251d97b718e5a568b007e3657eaf807b23d315855893f872071f004ec559?d=identicon)[jippi](/maintainers/jippi)

![](https://www.gravatar.com/avatar/237fc5067f1e83628efd392da694a3f95445b4c906ec4edf69c873080e6da77d?d=identicon)[FriendsOfCake](/maintainers/FriendsOfCake)

---

Top Contributors

[![AD7six](https://avatars.githubusercontent.com/u/33387?v=4)](https://github.com/AD7six "AD7six (39 commits)")[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (25 commits)")[![jippi](https://avatars.githubusercontent.com/u/22841?v=4)](https://github.com/jippi "jippi (14 commits)")[![janhohner](https://avatars.githubusercontent.com/u/649895?v=4)](https://github.com/janhohner "janhohner (2 commits)")[![josegonzalez](https://avatars.githubusercontent.com/u/65675?v=4)](https://github.com/josegonzalez "josegonzalez (1 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (1 commits)")[![albertcansado](https://avatars.githubusercontent.com/u/4248492?v=4)](https://github.com/albertcansado "albertcansado (1 commits)")[![davidyell](https://avatars.githubusercontent.com/u/49889?v=4)](https://github.com/davidyell "davidyell (1 commits)")[![dereuromark](https://avatars.githubusercontent.com/u/39854?v=4)](https://github.com/dereuromark "dereuromark (1 commits)")

---

Tags

phpunittestunit testingunittesting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/friendsofcake-cakephp-test-utilities/health.svg)

```
[![Health](https://phpackages.com/badges/friendsofcake-cakephp-test-utilities/health.svg)](https://phpackages.com/packages/friendsofcake-cakephp-test-utilities)
```

###  Alternatives

[kenjis/ci-phpunit-test

An easier way to use PHPUnit with CodeIgniter 3.x

5861.2M3](/packages/kenjis-ci-phpunit-test)[atoum/atoum

Simple modern and intuitive unit testing framework for PHP 8.0+

1.4k2.6M311](/packages/atoum-atoum)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[zenstruck/assert

Standalone, lightweight, framework agnostic, test assertion library.

8114.9M8](/packages/zenstruck-assert)

PHPackages © 2026

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