PHPackages                             kphoen/rusty - 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. kphoen/rusty

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

kphoen/rusty
============

Documentation as tests "à la" Rust for PHP

473.9k↑200%5[3 PRs](https://github.com/K-Phoen/Rusty/pulls)5PHPCI failing

Since Oct 10Pushed 3y ago5 watchersCompare

[ Source](https://github.com/K-Phoen/Rusty)[ Packagist](https://packagist.org/packages/kphoen/rusty)[ RSS](/packages/kphoen-rusty/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (5)

Rusty [![Build Status](https://camo.githubusercontent.com/72d8ba0241d0931145f6ae55ece9f15f529c87e336f3d69cf7a2c412588c0cb3/68747470733a2f2f7472617669732d63692e6f72672f4b2d50686f656e2f52757374792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/K-Phoen/Rusty) [![PHP7 ready](https://camo.githubusercontent.com/1bdeb491d2b30d89ec425c42b74dba8d14431e7355c551cb5a573b46f4e0bf35/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850372d72656164792d677265656e2e737667)](https://camo.githubusercontent.com/1bdeb491d2b30d89ec425c42b74dba8d14431e7355c551cb5a573b46f4e0bf35/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850372d72656164792d677265656e2e737667)
============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#rusty--)

The primary way of documenting a Rust project is through annotating the source code. These annotations can be viewed as part of the documentation, but they can also be compiled and executed. They call that "**documentation as tests**" and [their documentation](https://doc.rust-lang.org/book/documentation.html) is a goldmine.

Rusty is an attempt at implementing the same idea in the **PHP** world.

Usage
-----

[](#usage)

Rusty is able to **extract code samples from** both **PHP doc-blocks** and **Markdown files** (your documentation for instance).

### Running the tests

[](#running-the-tests)

An executable is provided to analyse the code samples scattered in your documentation and in your doc-blocks:

```
rusty check -v ./src/

```

### Writing documentation as tests

[](#writing-documentation-as-tests)

A code sample usually looks like this:

```
/**
 * Computes the n-th Fibonacci's number.
 *
 * Examples:
 *
 * ```
 * assert(fibonacci(1) === 1);
 * assert(fibonacci(2) === 1);
 * assert(fibonacci(12) === 144);
 * ```
 *
 * ```should_throw
 * // -1 is invalid, some kind of error is expected
 * fibonacci(-1);
 * ```
 *
 * ```no_execute
 * // it would take too much time to compute, we don't want to wait that long.
 * fibonacci(10000);
 * ```
 */
function fibonacci($n)
{
    if ($n < 0) {
        throw new \DomainException();
    }

    return $n
