PHPackages                             settleup/can-make-or-fake - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. settleup/can-make-or-fake

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

settleup/can-make-or-fake
=========================

A simple helper for making classes easily instantiated and mocked.

1.0.1(3mo ago)0865[1 PRs](https://github.com/trysettleup/can-make-or-fake/pulls)1MITPHPPHP ^8.4CI passing

Since Apr 10Pushed 1mo agoCompare

[ Source](https://github.com/trysettleup/can-make-or-fake)[ Packagist](https://packagist.org/packages/settleup/can-make-or-fake)[ Docs](https://github.com/settleup/can-make-or-fake)[ GitHub Sponsors](https://github.com/trysettleup)[ RSS](/packages/settleup-can-make-or-fake/feed)WikiDiscussions 1.x Synced 1w ago

READMEChangelog (2)Dependencies (12)Versions (4)Used By (1)

CanMakeOrFake
=============

[](#canmakeorfake)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ee61ca04445ceade2beddd7766676160b1c6eb001fae73e534048776ce938cbd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736574746c6575702f63616e2d6d616b652d6f722d66616b652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/settleup/can-make-or-fake)[![GitHub Tests Action Status](https://camo.githubusercontent.com/3ad41333af28708cabad9751386372c698d8584712e53c4c9fbe5af6ab37b46b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f747279736574746c6575702f63616e2d6d616b652d6f722d66616b652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/trysettleup/can-make-or-fake/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/49ca12285c86d1b4ac474f6923499d4baebac6526d4da93e93529925c3c8ebab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736574746c6575702f63616e2d6d616b652d6f722d66616b652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/settleup/can-make-or-fake)

A lightweight Laravel trait that gives any class a `make()` static constructor (resolved through the container) and a `fake()` method for easy test mocking.

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

[](#installation)

```
composer require settleup/can-make-or-fake
```

Usage
-----

[](#usage)

Add the `CanMakeOrFake` trait to any class:

```
use SettleUp\CanMakeOrFake\CanMakeOrFake;

class PriceCalculator
{
    use CanMakeOrFake;

    public function calculate(int $quantity, int $unitPrice): int
    {
        return $quantity * $unitPrice;
    }
}
```

### Resolving instances with `make()`

[](#resolving-instances-with-make)

`make()` resolves the class through Laravel's service container, so any constructor dependencies are automatically injected:

```
$calculator = PriceCalculator::make();

$total = $calculator->calculate(quantity: 3, unitPrice: 500); // 1500
```

### Faking in tests with `fake()`

[](#faking-in-tests-with-fake)

`fake()` creates a Mockery partial mock and binds it into the container. Any subsequent call to `make()` (or container resolution) will return the mock:

```
use Mockery\MockInterface;

PriceCalculator::fake(function (MockInterface $mock) {
    $mock->shouldReceive('calculate')->andReturn(0);
});

// Anywhere in your application that resolves PriceCalculator will now get the fake
$calculator = PriceCalculator::make();
$calculator->calculate(3, 500); // 0
```

Because `fake()` creates a partial mock, any methods you don't explicitly mock will still call the real implementation.

### Conditionable

[](#conditionable)

The trait includes Laravel's `Conditionable` trait, so you can use `when()` and `unless()`:

```
$calculator = PriceCalculator::make();

$calculator->when($applyDiscount, function (PriceCalculator $calc) {
    // ...
});
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Andrew Leach](https://github.com/andyleach)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance87

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% 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 ~7 days

Total

3

Last Release

91d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/37b954ddfe95a6bdc825f5e679aa650f13035c7f9846afd4f88d906957d356ca?d=identicon)[Andrew Leach](/maintainers/Andrew%20Leach)

---

Top Contributors

[![andyleach](https://avatars.githubusercontent.com/u/7387639?v=4)](https://github.com/andyleach "andyleach (9 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelSettle Upcan-make-or-fakeTry Settle Up

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/settleup-can-make-or-fake/health.svg)

```
[![Health](https://phpackages.com/badges/settleup-can-make-or-fake/health.svg)](https://phpackages.com/packages/settleup-can-make-or-fake)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M48](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

330530.5k30](/packages/codewithdennis-filament-select-tree)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.8k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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