PHPackages                             cscfa\_tool\_division/phpunit\_test\_helper - 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. cscfa\_tool\_division/phpunit\_test\_helper

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

cscfa\_tool\_division/phpunit\_test\_helper
===========================================

013PHP

Since Jan 29Pushed 9y ago1 watchersCompare

[ Source](https://github.com/cscfaToolDivision/phpunitTestHelper)[ Packagist](https://packagist.org/packages/cscfa_tool_division/phpunit_test_helper)[ RSS](/packages/cscfa-tool-division-phpunit-test-helper/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

phpunitTestHelper
=================

[](#phpunittesthelper)

The ObjectTestCase
------------------

[](#the-objecttestcase)

The ObjectTestCase is a child of the phpunit TestCase that provide method to create

- ObjectCall instance (**newObjectCall()** method),
- SetterCall instance (**newSetterCall()** method),
- GetterCall instance (**newGetterCall()** method)

The ObjectTestTrait
-------------------

[](#the-objecttesttrait)

This trait is used to provider helper methods to test an object instance.

#### Get an instance property value :

[](#get-an-instance-property-value-)

To get an instance property value, the trait provide a **getPropertyValue(instance, property)** method. The instance is given as first parameter and the property name as second one.

This method will create a reflection, set the property accessible and return it's value. An exception will be throwed if the first parameter is not an object or if the second one is not an object property.

```
$instance = new MyInstance();
$instance->setName('instance_name');

$value = $ObjectTest->getPropertyValue($instance, 'name');

echo $value; // return 'instance_name'
```

#### Set an instance property value :

[](#set-an-instance-property-value-)

To set an instance property value, the trait provide a **setPropertyValue(instance, property, value)** method. The instance is given as first paramete, the property name as second one and the value as third one.

This method will create a reflection, set the property accessible and hydrate it's value. An exception will be throwed if the first parameter is not an object or if the second one is not an object property.

```
$instance = new MyInstance();
$instance->setName('instance_name');

$value = $ObjectTest->getPropertyValue($instance, 'name');

echo $value; // return 'instance_name'
```

The ObjectCall
--------------

[](#the-objectcall)

The **ObjectCall** allow to test a method call with argument and return value. It allow to define the method name to call and the instance. This class need a ***\\PHPUnit\_Framework\_Assert*** instance to execute the tests.

```
$instance = new MyInstance();
$caller = new ObjectCall($currentTestCase);

$call->call('setName')
            ->on($instance)
            ->with(array('instance_name'))
            ->mustReturn($instance, true)
            ->resolve('Return value mismatch');
```

#### The resolve method

[](#the-resolve-method)

This method will call the method and validate the result. It will throw a ***\\RuntimeException*** if the method call fail, a ***MethodNotFoundException*** if the method does not exist or a ***RequiredArgumentException*** if the method name to call or the instance are null.

It accept the assertion failure message as optional argument.

#### The mustReturn method

[](#the-mustreturn-method)

This method define the expected method return value. The second argument define if the expected and returned must be equals or same. To define the values as same, give true as second argument, or false for equal. Note the second argument is optional and is false by default.

#### The with method

[](#the-with-method)

This method define the arguments passed to the method at call time. It must be an array. To give none arguments to the method, simply don't call the ***with*** method.

#### The on method

[](#the-on-method)

This method define the instance on which the method must be called.

#### The call method

[](#the-call-method)

This method define the method name to call.

#### The mustThrow method

[](#the-mustthrow-method)

This method define that the called method must throw an exception.

```
$instance = new MyInstance();
$caller = new ObjectCall($currentTestCase);

$call->call('throw')
            ->on($instance)
            ->with(array('instance_name'))
            ->mustThrow(\Exception::class, 500, 'Th throw method was called')
            ->resolve();
```

The SetterCall
--------------

[](#the-settercall)

The **SetterCall** is an extension of the ObjectCall that allow to test the property injection.

```
$instance = new MyInstance();
$call->call('setName')
    ->on($instance)
    ->with(array('instance_name'))
    ->mustReturn($instance)
    ->inject('instance_name', false, function($value){return $value;})
    ->injectIn('name')
    ->resolve();
```

#### The inject method

[](#the-inject-method)

This method allow to provide a value that is expected to be injected into a property of the instance. The given boolean, as second argument tell that the equality must be tested by same (as true) or equal (as false). Finally, a **Callable** can be given as third argument to pre-process the value before equality validation.

It return a InjectExpression instance.

#### The injectIn method

[](#the-injectin-method)

This method define the property where the value is stored. It is a method of InjectExpression instance and return the parent SetterCall instance.

For multiple instance setting, it s possible to give another instance as second argument to the injectIn method to specify another instance where the value must be injected.

```
$instance = new MyInstance();
$facade = new MyFacade($instance);
$call->call('setName')
    ->on($facade)
    ->with(array('instance_name'))
    ->mustReturn($facade)
    ->inject('instance_name', false, function($value){return $value;})
    ->injectIn('name', $instance)
    ->resolve();
```

The GetterCall
--------------

[](#the-gettercall)

The **GetterCall** is an extension of the ObjectCall that allow to test the property getter.

```
$instance = new MyInstance();
$name = 'instance_name';

$call->call('getName')
    ->on($instance)
    ->mustReturn($name)
    ->from('instanceName')
    ->thatContain($name)
    ->resolve();
```

#### The from method

[](#the-from-method)

This method define the property whence the getter is expected to return a value. It only accept a string value and will throw a TypeException if a non string value is provided.

#### The thatContain method

[](#the-thatcontain-method)

This method define the value contained into the given property.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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://www.gravatar.com/avatar/e0ef3bf53db7ceb681a598fc7da7a6fa2bdbc5904a8072b2a33e7c4646243c4b?d=identicon)[cscfa](/maintainers/cscfa)

---

Top Contributors

[![matthieu88160](https://avatars.githubusercontent.com/u/11874266?v=4)](https://github.com/matthieu88160 "matthieu88160 (12 commits)")

### Embed Badge

![Health badge](/badges/cscfa-tool-division-phpunit-test-helper/health.svg)

```
[![Health](https://phpackages.com/badges/cscfa-tool-division-phpunit-test-helper/health.svg)](https://phpackages.com/packages/cscfa-tool-division-phpunit-test-helper)
```

###  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.9M571](/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)
