PHPackages                             danharper/stem - 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. danharper/stem

ActiveLibrary

danharper/stem
==============

A simple fixtures library for PHP

111PHP

Since Mar 4Pushed 13y ago1 watchersCompare

[ Source](https://github.com/danharper/Stem)[ Packagist](https://packagist.org/packages/danharper/stem)[ RSS](/packages/danharper-stem/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Stem
====

[](#stem)

A simple fixtures library for PHP. (This is mostly a practice for me to learn writing TDD with, but I think this would be useful)

[![Build Status](https://camo.githubusercontent.com/d8f073246deb50dfe19f9f1febe16c8b83216b40398de6bc690c36fb8bc2cd14/68747470733a2f2f7472617669732d63692e6f72672f64616e6861727065722f5374656d2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/danharper/Stem)

Example
-------

[](#example)

Declare what a fixture should look like:

```
Stem::fixture('User', array(
	'id' => ':int'
	'name' => '2:words',
	'email' => ':email',
	'bio' => ':string',
));
```

Then use it:

```
$fixture = Stem::attributes('User');

// array(
//   'id' => 29,
//   'name' => 'foo banana',
//   'email' => 'mascot28384@bread.example.com',
//   'bio' => 'dawn chat grandpa ballplayer cell Jill wing brainstorm chill Jills hunk ache'
// )
```

Or even create a real object directly from it:

```
$obj = Stem::make('User');

// this calls:
// new User(array( ... ))
```

In simpler cases you may just need a couple of random words:

```
Stem::run('3:words');
```

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

[](#installation)

### Laravel

[](#laravel)

- Add `"danharper/stem": "dev-master"` to your `composer.json` and update/install
- Add `'danharper\Stem\Facades\Laravel\StemServiceProvider'` to the providers array in `app/config/app.php`
- Add `'Stem' => 'danharper\Stem\Facades\Laravel\Stem'` to the aliases array in `app/config/app.php`

Use it:

```
Stem::run('3:words');
```

### Native

[](#native)

Get it from Composer with `"danharper\stem": "dev-master"`.

Then you have two ways you can use it:

```
use danharper\Stem\Facades\Native\Stem as Stem;

Stem::run('3:words');
```

```
use danharper\Stem\Stem as Stem;

$stem = new Stem;
$stem->run('3:words');
```

Provided Handlers
-----------------

[](#provided-handlers)

- `:string` and `:words` -- prefix with a number for that many words, eg. `3:words`
- `:word` -- for a single word, for clarity in your code you could even write `1:word` (`1:words` would also work)
- `:int` and `:number` -- prefix with a number for a number from 0 *up to* the given number
- `:email`

Registering your own Handlers
-----------------------------

[](#registering-your-own-handlers)

### With a Class

[](#with-a-class)

Provide `Stem::register()` with an object which responds to `register` with what it wishes to be known as, and when told `run` (with an optional modifier) returns something to display. Implent `danharper\Stem\Handlers\HandlerInterface` for clarity.

```
class CustomHandler {
	public function register() {
		return 'custom';
	}

	public function run($modifier) {
		if ($modifier)
			return "something $modifier";
		else
			return "something else";
	}
}

Stem::register(new CustomHandler);

Stem::run('lorem:custom'); // something lorem
Stem::run(':custom'); // something else
```

### With a Closure

[](#with-a-closure)

Provide `Stem::register()` with a Closure behaving as the run method in the class above, and with the second argument what it wishes to be known as.

```
Stem::register(function($modifier) {
	if ($modifier)
		return "something $modifier";
	else
		return "something else";
}, 'foobar');

Stem::run('baz:foobar'); // something baz
Stem::run(':foobar'); // something else
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

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/f85b25e3772649f8b096057162897f1052385f956e170e9cdf628c4ef72edede?d=identicon)[danharper](/maintainers/danharper)

---

Top Contributors

[![danharper](https://avatars.githubusercontent.com/u/510740?v=4)](https://github.com/danharper "danharper (40 commits)")

### Embed Badge

![Health badge](/badges/danharper-stem/health.svg)

```
[![Health](https://phpackages.com/badges/danharper-stem/health.svg)](https://phpackages.com/packages/danharper-stem)
```

PHPackages © 2026

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