PHPackages                             aaronhipple/sampler - 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. aaronhipple/sampler

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

aaronhipple/sampler
===================

Test inline code samples from your docblocks using PHPUnit

0.2.0(8y ago)014MITPHP

Since Nov 18Pushed 8y ago1 watchersCompare

[ Source](https://github.com/aaronhipple/sampler)[ Packagist](https://packagist.org/packages/aaronhipple/sampler)[ RSS](/packages/aaronhipple-sampler/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (6)Versions (7)Used By (0)

sampler
=======

[](#sampler)

[![Latest Stable Version](https://camo.githubusercontent.com/4cda3abf980dc572109a49db6cd94cddd134346031fc5b59445fc2423ac1e286/68747470733a2f2f706f7365722e707567782e6f72672f6161726f6e686970706c652f73616d706c65722f762f737461626c65)](https://packagist.org/packages/aaronhipple/sampler)[![Build Status](https://camo.githubusercontent.com/36682fc01c35ccceafb1ecf06e5a940cee69bc9cb9be8b156d964e2466c3ed0f/68747470733a2f2f7472617669732d63692e6f72672f6161726f6e686970706c652f73616d706c65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/aaronhipple/sampler)[![Maintainability](https://camo.githubusercontent.com/87693393ca654c31f098c45bb80eba42092cac053dcb4183da85351a96553a77/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64306238666336303738363361643434346338352f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/aaronhipple/sampler/maintainability)[![Test Coverage](https://camo.githubusercontent.com/47cd43015f3ad4f47898906937414d4fd32fefe30145ebd446fedf1c86e4042a/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64306238666336303738363361643434346338352f746573745f636f766572616765)](https://codeclimate.com/github/aaronhipple/sampler/test_coverage)

Test inline code samples from your docblocks using PHPUnit!

caveats
-------

[](#caveats)

- This is not particularly mature. Issues and pull requests welcome.
- The extracted sample code is `eval`'d for testing, with all those security implications. As always, be mindful only to run trusted code in sensitive environments.
- Right now it only works on classes, class methods, and functions. It does no magic to expose private or protected methods, so normal rules apply.

usage
-----

[](#usage)

First, install `sampler` as a dependency.

```
$ composer require aaronhipple/sampler
```

Then, in your PHPUnit suite, implement a case extending `AbstractSampleTestCase`.

```
use AaronHipple\Sampler\AbstractSampleTestCase;

class SampleTest extends AbstractSampleTestCase
{
    /**
     * Provide absolute paths to the directories to scan for samples.
     *
     * @return []string An array of folder paths.
     */
    protected function paths()
    {
        return [__DIR__ . '/../src'];
    }

    /**
     * (Optional) Provide a list of file extensions to scan.
     */
    protected function extensions()
    {
        return ['php', 'inc'];
    }
}
```

Finally, write some samples! You can use our `@sample` annotation...

```
/**
 * Say hello to someone!
 *
 * @sample
 *   use PHPUnit\Framework\Assert;
 *   Assert::assertInternalType(
 *     'string',
 *     say_hello('Frank')
 *   );
 * @sample
 *   use PHPUnit\Framework\Assert;
 *   Assert::assertEquals(
 *     'Hello, Aaron!',
 *     say_hello('Aaron')
 *   );
 */
function say_hello($name) {
  return "Hello, $name!";
}
```

...or good ol' inline markdown.

```
/**
 * Say hello to someone!
 *
 * # Examples
 *
 * ```
 * use PHPUnit\Framework\Assert;
 * Assert::assertEquals(
 *   'Hello, Aaron!',
 *   say_hello('Aaron')
 * );
 * ```
 *
 * ```
 * use PHPUnit\Framework\Assert;
 * Assert::assertEquals(
 *   'Hello, Frank!',
 *   say_hello('Frank')
 * );
 * ```
 */
function say_hello($name) {
  return "Hello, $name!";
}
```

Run your test suite as usual, with `phpunit`.

contributing
------------

[](#contributing)

- Pull requests are welcome.
- More tests please.
- PSR-2 is good. Use `phpcbf`.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

4

Last Release

3192d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/76fb1753e4e0dbabce528572721686e9c7991efc25e829fcd2bd7923aaa892be?d=identicon)[ahipple](/maintainers/ahipple)

---

Top Contributors

[![aaronhipple](https://avatars.githubusercontent.com/u/10441729?v=4)](https://github.com/aaronhipple "aaronhipple (11 commits)")

---

Tags

documentationtesting

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/aaronhipple-sampler/health.svg)

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

###  Alternatives

[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[phparkitect/phparkitect

Enforce architectural constraints in your PHP applications

9244.5M32](/packages/phparkitect-phparkitect)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)[drupal/core-dev

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

2023.2M367](/packages/drupal-core-dev)[contao/contao

Contao Open Source CMS development package

43514.5k2](/packages/contao-contao)[laraveldaily/filacheck

Static analysis for Filament projects - detect deprecated patterns and code issues

122100.1k1](/packages/laraveldaily-filacheck)

PHPackages © 2026

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