PHPackages                             sebastianknott/test-utils - 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. sebastianknott/test-utils

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

sebastianknott/test-utils
=========================

Some classes i like to use for testing

0.2(4mo ago)0199GPL-3.0-onlyPHPPHP ~8.4

Since May 21Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/sebastianknott/test-utils)[ Packagist](https://packagist.org/packages/sebastianknott/test-utils)[ RSS](/packages/sebastianknott-test-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (14)Versions (4)Used By (0)

test-utils
==========

[](#test-utils)

Some classes i like to use for testing purposes

System Under Test (SUT) Factory
-------------------------------

[](#system-under-test-sut-factory)

I don't like to do tedious work, so I created a factory that creates the System Under Test (SUT) for me. The factory creates a new instance of the SUT and mocks its constructor dependencies as good as it can.

It returns a `Bundle` object that contains the SUT and the mocks.

```
class SomeClass
{
    public function __construct(Dependency $myDependency)
    {
        // ...
    }
}

class Dependency{
    public function someMethod()
    {
        // ...
    }
}

$facade = new BundleFacade();
$bundle = $facade->build(SomeClass::class);

// Get the SUT
$sut = $bundle->sut;
// Access the mocked dependencies by parameter name
$bundle['myDependency']->expects()->someMethod()->once();
```

### Type of Mocks

[](#type-of-mocks)

It supports multiple types of mocking libraries ([Mockery](https://github.com/mockery/mockery), [Phake](https://github.com/phake/phake), [Prophecy](https://github.com/phpspec/prophecy)). Just use the provided build method. The default mocking library is Mockery.

```
[...]
$factory->build(SomeClass::class); // Returns MockeryBundle
$factory->buildMockeryBundle(SomeClass::class); // Returns MockeryBundle
$factory->buildPhakeBundle(SomeClass::class); // Returns PhakeBundle
$factory->buildProphecyBundle(SomeClass::class); // Returns ProphecyBundle
[...]
```

### Prebuild Parameters

[](#prebuild-parameters)

If the SUT has dependencies that are not mockable, you can pass them as a prebuild parameter to the factory. The prebuild parameter is an associative array where the key is the name of the parameter in the suts constructor and the value is the instance.

```
[...]
$prebuildParameters = [
    'myDependency' => new Dependency()
];
$bundel = $factory->build(
    SomeClass::class,
    prebuildParameters: $prebuildParameters
);
[...]
```

TestToolsCase
-------------

[](#testtoolscase)

I found myself writing the same boilerplate code over and over again. So I condensed it into a base class that I can extend from.

It does the following:

- Make a sut factory available `self::$bundleFactory`
- Make faker available `self::$faker`
- Require hamcrest and Mockery

So instead of writing this:

```
class SomeTest extends \PHPUnit\Framework\TestCase
{
    private $bundleFactory;
    private $faker;
    private $mockedDependency;

    public function setUp()
    {
        $this->bundleFactory = new BundleFactory();
        $this->faker = \Faker\Factory::create();
        $this->faker->seed(9876543255);
        $this->mockedDependency = \Mockery::mock(Dependency::class);
        $this->subject = new SomeClass($this->mockedDependency);
    }

    public function testSomething()
{
        $this->mockedDependency->expects()
            ->someMethod(Matchers::stringValue())
            ->andReturn($this->faker->word());
        $sut->run();
    }

    public function tearDown()
    {
        \Mockery::close();
    }
}
```

I write that:

```
class SomeTest extends TestToolsCase
{
    public function testSomething()
    {
        $bundle = self::$bundleFactory->build(SomeClass::class);
        $bundle['myDependency']->expects()
            ->someMethod(stringValue())->andReturn(self::$faker->word());

        $bundle->sut->run();
    }
}
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance76

Regular maintenance activity

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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.

###  Release Activity

Cadence

Every ~598 days

Total

2

Last Release

129d ago

PHP version history (2 changes)0.1PHP ^8.3

0.2PHP ~8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c6fe88d259b4f88b5b40dc180b4674ece3e8b6dc7fcf4d417c537c86aed191f?d=identicon)[sebastianknott](/maintainers/sebastianknott)

---

Top Contributors

[![sebastianknott](https://avatars.githubusercontent.com/u/6544387?v=4)](https://github.com/sebastianknott "sebastianknott (6 commits)")

###  Code Quality

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sebastianknott-test-utils/health.svg)

```
[![Health](https://phpackages.com/badges/sebastianknott-test-utils/health.svg)](https://phpackages.com/packages/sebastianknott-test-utils)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[phpspec/prophecy-phpunit

Integrating the Prophecy mocking library in PHPUnit test cases

19454.9M1.4k](/packages/phpspec-prophecy-phpunit)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2021.0M277](/packages/drupal-core-dev)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

31252.7k5](/packages/webmozarts-strict-phpunit)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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