PHPackages                             ion-bazan/phpunit-extras - 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. ion-bazan/phpunit-extras

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

ion-bazan/phpunit-extras
========================

Java-style test automation for PHPUnit - using PHP 8.1+ attributes

v0.2.0(6mo ago)10MITPHPPHP ^8.1CI passing

Since Nov 14Pushed 6mo agoCompare

[ Source](https://github.com/IonBazan/phpunit-extras)[ Packagist](https://packagist.org/packages/ion-bazan/phpunit-extras)[ RSS](/packages/ion-bazan-phpunit-extras/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

phpunit-extras
==============

[](#phpunit-extras)

[![PHP 8.1+](https://camo.githubusercontent.com/45d36955804bf3f4f17097b05a7f41a28e578dc24e0d3ad0d21ae9d9762f44c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312b2d626c75652e737667)](https://packagist.org/packages/ion-bazan/phpunit-extras)[![Latest version](https://camo.githubusercontent.com/6250669127cba2d5a0e731e433ecbdc7f1a8c10f388ab859143752d56937b72b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696f6e2d62617a616e2f706870756e69742d6578747261732e737667)](https://packagist.org/packages/ion-bazan/phpunit-extras)[![GitHub Workflow Status](https://camo.githubusercontent.com/433f34fdbc966ef4e191fa2334f8e0f99a5a725e1dbd9c55c7fe0fbf2bc81fd1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f496f6e42617a616e2f706870756e69742d6578747261732f746573742e796d6c)](https://github.com/IonBazan/phpunit-extras/actions)[![Codecov](https://camo.githubusercontent.com/cc5400199ed9b15b5736e521a4620f1922a9d3a085c745be9fda047799ada713/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f496f6e42617a616e2f706870756e69742d657874726173)](https://codecov.io/gh/IonBazan/phpunit-extras)[![Downloads](https://camo.githubusercontent.com/0fa22516c0a206f54da08b91b55eb89e65a9a727101cb6abbebd3d602c71b7dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696f6e2d62617a616e2f706870756e69742d6578747261732e737667)](https://packagist.org/packages/ion-bazan/phpunit-extras)[![License](https://camo.githubusercontent.com/46c0f76ac4c91bb385b26bf52838741faf4233243171f812f08c71979bb58b0e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696f6e2d62617a616e2f706870756e69742d6578747261732e737667)](https://packagist.org/packages/ion-bazan/phpunit-extras)

> **Java-style test automation for PHPUnit** - using **PHP 8.1+ attributes**.

Write **cleaner, declarative, and expressive** unit tests with:

```
#[Mock]
private Logger $logger;
#[Stub]
private Payment $paymentService;
#[InjectMocks]
private OrderService $service;
#[Captor]
private ArgumentCaptor $message;
```

Inspired by **Mockito**, **JUnit 5**, and **Spring Boot Testing**.

Installation
------------

[](#installation)

```
composer require ion-bazan/phpunit-extras
```

Features
--------

[](#features)

FeatureStatusJava Equivalent`#[Mock]`Done`@Mock``#[Stub]`Done`@Mock``#[InjectMocks]`Done`@InjectMocks``#[Captor]`Done`ArgumentCaptor``#[Spy]`Planned`@Spy``#[TempDir]`Planned`@TempDir``#[ValueSource]`Planned`@ValueSource`Usage
-----

[](#usage)

### 1. Use `WithExtras` trait

[](#1-use-withextras-trait)

```
use IonBazan\PHPUnitExtras\WithExtras;

class OrderServiceTest extends TestCase
{
    use WithExtras;

    #[Stub]
    private Payment $payment;
    #[Mock]
    private Logger $logger;
    #[Captor]
    private ArgumentCaptor $message;
    #[InjectMocks]
    private OrderService $service;

    public function testOrderLogsCharge(): void
    {
        $this->logger->expects($this->once())
            ->method('log')
            ->with($this->message);

        $this->service->place(150);

        $this->assertSame('Charged 150', $this->message->getValue());
    }
}
```

> All attributes are processed automatically via `WithExtras` trait.

### 2. Manual Processing (for fine control) TBD

[](#2-manual-processing-for-fine-control-tbd)

### `#[Captor]` – Capture Method Arguments

[](#captor--capture-method-arguments)

```
#[Captor]
private ArgumentCaptor $message;

$this->logger->expects($this->once())
    ->method('log')
    ->with($this->message);

$this->logger->log('hello world');

$this->assertSame('hello world', $this->message->getValue());
$this->assertSame(['hello world'], $this->message->getAllValues());
```

- `getValue()` → first call
- `getLastValue()` → last call
- `getAllValues()` → all calls
- `count()` → number of calls

Requirements
------------

[](#requirements)

- PHP 8.1+
- PHPUnit 10+

Why phpunit-extras?
-------------------

[](#why-phpunit-extras)

BenefitDescriptionLess boilerplateNo `setUp()`, no manual mocksDeclarativeIntent in attributesIDE-friendlyAutocomplete, refactoringExtensibleAdd new handlers easilyRoadmap
-------

[](#roadmap)

- `#[Spy]` – partial mocks
- `#[TempDir]` – auto-cleaned temp dirs
- `#[TestFactory]` – dynamic tests

License
-------

[](#license)

MIT © [Ion Bazan](https://github.com/IonBazan)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance69

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

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

Total

2

Last Release

183d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1985514?v=4)[Ion Bazan](/maintainers/IonBazan)[@IonBazan](https://github.com/IonBazan)

---

Top Contributors

[![IonBazan](https://avatars.githubusercontent.com/u/1985514?v=4)](https://github.com/IonBazan "IonBazan (5 commits)")

### Embed Badge

![Health badge](/badges/ion-bazan-phpunit-extras/health.svg)

```
[![Health](https://phpackages.com/badges/ion-bazan-phpunit-extras/health.svg)](https://phpackages.com/packages/ion-bazan-phpunit-extras)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M775](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)

PHPackages © 2026

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