PHPackages                             milanowicz/php-testing - 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. milanowicz/php-testing

ActivePhp-library[Testing &amp; Quality](/categories/testing)

milanowicz/php-testing
======================

Library for PHPUnit testing

1.2.3(1y ago)03.9k[3 PRs](https://github.com/milanowicz/php-testing/pulls)1GPL-3.0-or-laterPHPPHP ^8.0CI passing

Since Mar 1Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/milanowicz/php-testing)[ Packagist](https://packagist.org/packages/milanowicz/php-testing)[ RSS](/packages/milanowicz-php-testing/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (21)Used By (1)

PHP Testing
===========

[](#php-testing)

[![Test](https://github.com/milanowicz/php-testing/workflows/Testing/badge.svg?branch=master)](https://github.com/milanowicz/php-testing/workflows/Testing/badge.svg?branch=master)[![Mutation testing](https://camo.githubusercontent.com/664f0364d458e7958b1142538dd9bfb460b52e1030fe38f5a75aa87db5990bda/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532466d696c616e6f7769637a2532467068702d74657374696e672532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/milanowicz/php-testing/master)[![codecov](https://camo.githubusercontent.com/b280261fefeb08e31c59773287ba8ce9b2749bba4a6307a6d36e9187d0c45d9d/68747470733a2f2f636f6465636f762e696f2f67682f6d696c616e6f7769637a2f7068702d74657374696e672f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d34324736455449394e56)](https://codecov.io/gh/milanowicz/php-testing)

[![](https://camo.githubusercontent.com/6f22bb3205f8f1f353b3cf5e6ff273f66e99dcc596106e525c6159d00139c698/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d696c616e6f7769637a2f7068702d74657374696e67)](https://camo.githubusercontent.com/6f22bb3205f8f1f353b3cf5e6ff273f66e99dcc596106e525c6159d00139c698/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d696c616e6f7769637a2f7068702d74657374696e67)[![](https://camo.githubusercontent.com/7fd9bbb70b69faf7ee1b5afdfbaade6fafae13a965ce9850e6d304866b0f1de7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f6d696c616e6f7769637a2f7068702d74657374696e67)](https://camo.githubusercontent.com/7fd9bbb70b69faf7ee1b5afdfbaade6fafae13a965ce9850e6d304866b0f1de7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f6d696c616e6f7769637a2f7068702d74657374696e67)

[![](https://camo.githubusercontent.com/0127439eca37446987e4a7ca43720c3c6ea21805b82d06fa250b9729b8372257/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6d696c616e6f7769637a2f7068702d74657374696e67)](https://camo.githubusercontent.com/0127439eca37446987e4a7ca43720c3c6ea21805b82d06fa250b9729b8372257/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6d696c616e6f7769637a2f7068702d74657374696e67)[![](https://camo.githubusercontent.com/7d9817bfa20eeec41ff47b3643ee77f4d685b93dac1aa75d0425e540e67636e8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f6d696c616e6f7769637a2f7068702d74657374696e67)](https://camo.githubusercontent.com/7d9817bfa20eeec41ff47b3643ee77f4d685b93dac1aa75d0425e540e67636e8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f6d696c616e6f7769637a2f7068702d74657374696e67)[![](https://camo.githubusercontent.com/88da77f3407386f17c5f7187347b062069531e1989ef72167c95af709ead147c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6d696c616e6f7769637a2f7068702d74657374696e67)](https://camo.githubusercontent.com/88da77f3407386f17c5f7187347b062069531e1989ef72167c95af709ead147c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6d696c616e6f7769637a2f7068702d74657374696e67)

[![](https://camo.githubusercontent.com/e5e3d8d6b1f1e4d031b7ad17c4f28cef982e14fba00ad4775a4a681dabe44c74/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696c616e6f7769637a2f7068702d74657374696e67)](https://camo.githubusercontent.com/e5e3d8d6b1f1e4d031b7ad17c4f28cef982e14fba00ad4775a4a681dabe44c74/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696c616e6f7769637a2f7068702d74657374696e67)[![](https://camo.githubusercontent.com/b9aaf0dc790345bac61d757455b5d06c4a55126401c96ccc73a186464e11c267/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d696c616e6f7769637a2f7068702d74657374696e67)](https://camo.githubusercontent.com/b9aaf0dc790345bac61d757455b5d06c4a55126401c96ccc73a186464e11c267/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d696c616e6f7769637a2f7068702d74657374696e67)[![](https://camo.githubusercontent.com/da69e4da1d01d10a10a66b1053e7a61f92c9805effe1bf6063399df93a30b775/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f6d696c616e6f7769637a2f7068702d74657374696e67)](https://camo.githubusercontent.com/da69e4da1d01d10a10a66b1053e7a61f92c9805effe1bf6063399df93a30b775/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f6d696c616e6f7769637a2f7068702d74657374696e67)[![](https://camo.githubusercontent.com/34dd7ebb5596dbb7eb24b7edca0b1f69a34938080a38c4104330e15d80cb57f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d696c616e6f7769637a2f7068702d74657374696e67)](https://camo.githubusercontent.com/34dd7ebb5596dbb7eb24b7edca0b1f69a34938080a38c4104330e15d80cb57f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d696c616e6f7769637a2f7068702d74657374696e67)

Library for PHPUnit testing.

Usage
-----

[](#usage)

Install by Composer

```
> composer require --dev milanowicz/php-testing
```

### Methods

[](#methods)

Example for using abstract class in your ClassTest:

```
class UnitTest extends Milanowicz\Testing\TestCase
{
    public function testMethod(): void
    {
        // All Traits in abstract Milanowicz\Testing\TestCase are extends!
        // See below for further details from Trait methods
    }
}
```

OR import Trait(s) for use them:

```
class UnitTest extends What\Ever\TestCase
{
    use Milanowicz\Testing\TestTrait;

    public function testMethod(): void
    {
        // Access to private or protected Method
        $this->accessMethod((object) Class, (string) Method);
        // Run test(s) in it and when an assertion failed would throw, see message and data for the reason
        $this->catchAssertionFailing((array) $data, function ($data) {
            $this->assertEquals('whatEver', $data['whatEver']);
        }, (string) $catchData = ExpectationFailedException::class);
        // Create class without constructor
        $this->createInstanceWithoutConstructor((string) Class);
        // Call a private or protected Method with argument(s)
        $this->invokeMethod((object) Class, (string) Method, (mixed) ArgumentsForMethod);
        // Set a value to private or protected property
        $this->setProperty((object) Class, (string) Property, (mixed) PropertyValue);
        // Get a value from a private or protected property back
        $this->getProperty((object) Class, (string) Property);
        // Execute test of number tries to check, if it runs multiply times successfully
        $this->testLoops((callable) Function, (int) NumberOfTries, (int) NumberOfErrors);
        // Execute test and when it's throw an exception, then try it again
        $this->tryTest((callable) Function, (int) NumberOfTries);
    }
}
```

TestPerformanceTrait is to execute two functions and see which was faster of those:

```
class UnitTest extends What\Ever\TestCase
{
    use Milanowicz\Testing\TestPerformanceTrait;

    public function testMethod(): void
    {
        // Example functions
        $cb1 = static function () {
            usleep(100);
        };
        $cb2 = static function () {
            usleep(200);
        };

        // Call both methods after each other and save run times from them
        $this->measureTime((callable) $cb1, (callable) $cb2, (int) $n = 20);
        // Check AVG and Student-Test
        $this->checkPerformance((bool) $function1 = true, (float) $pValue = 0.05);
        // $cb1 should be faster
        $this->checkMeanTime((bool) $function1 = true);
        // $cb2 should be slower and throw an Exception
        $this->checkMeanTime((bool) false);
        // Check if $cb1 is significant faster
        $this->checkStudentTest((float) $pValue = 0.05);
        // Get all time measures
        $this->getTimeMeasures();
        // Get both in array with AVG, STD and Median
        $this->getTimeStats();
        // Get result from Student-T test
        $this->getTimeSignificance();
        // Clear all times and measures
        $this->clearTimes();
    }
}
```

### Exception

[](#exception)

Usage for AssertionFailedException to get data in Exception message:

```
$e = new AssertionFailedException(
    (string) $message = 'Testing',
    (array) $data = [1],
    (int) $code = 1,
    (null|Throwable) $previous = null,
);
$e->toArray(); // => [1]
$e->count(); // => 1
$e->toString(); // => Message and Data as String

// and all Exception methods are available:
$e->getMessage(); // => Message and Data as String
$e->getCode(); // => 1
$e->getPrevious(); // => null OR a Throwable object
```

Development
-----------

[](#development)

Run all test suites

```
> composer tests
```

Run PHP Code Styling

```
> composer style
```

Run PHPStan to analyze code

```
> composer analyze
```

Run PHPUnit tests

```
> composer test
```

Run Mutation tests by Infection

```
> composer infection
```

License
-------

[](#license)

[GNU GPL Version 3](http://www.gnu.org/copyleft/gpl.html)

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance69

Regular maintenance activity

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 76.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 ~98 days

Recently: every ~267 days

Total

12

Last Release

458d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/717cb11cf3478a2c0893028c749e9659881770a1af71a2a98764fac08a081ae7?d=identicon)[milanowicz](/maintainers/milanowicz)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (303 commits)")[![milanowicz](https://avatars.githubusercontent.com/u/1786103?v=4)](https://github.com/milanowicz "milanowicz (92 commits)")

---

Tags

phpphpunittestingtesting-toolsunit-testing

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/milanowicz-php-testing/health.svg)

```
[![Health](https://phpackages.com/badges/milanowicz-php-testing/health.svg)](https://phpackages.com/packages/milanowicz-php-testing)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[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)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

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