PHPackages                             namshi/ab - 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. namshi/ab

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

namshi/ab
=========

A library to run AB tests within your code.

1.1.3(8y ago)69314.3k↓19.6%7[3 issues](https://github.com/namshi/AB/issues)1MITPHP

Since Jul 13Pushed 8y ago26 watchersCompare

[ Source](https://github.com/namshi/AB)[ Packagist](https://packagist.org/packages/namshi/ab)[ RSS](/packages/namshi-ab/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (9)Used By (1)

NAMSHI | AB
===========

[](#namshi--ab)

[![Build Status](https://camo.githubusercontent.com/57f0ae6ed4c69202580d6d27f3b0132de936769e767047b02910cac4a2cebc78/68747470733a2f2f7472617669732d63692e6f72672f6e616d7368692f41422e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/namshi/AB)

[![SensioLabsInsight](https://camo.githubusercontent.com/979929995025efab73935c27d42529f6a0ca66db552a78d3592a420c40c8f448/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f38326532306239642d653934332d346431392d613964332d6238356132613438383631612f6d696e692e706e67)](https://insight.sensiolabs.com/projects/82e20b9d-e943-4d19-a9d3-b85a2a48861a)

This library provides a layer to run AB tests on your applications.

AB testing is useful when you want to change anything on your application but want to benchmark different variations of the change (ie. display a button that says "Buy now", "Go to checkout" or "PAY, DUDE!").

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

[](#installation)

This library is available through composer, as you can see from its [packagist page](https://packagist.org/packages/namshi/ab).

Just require it in your `composer.json`:

```
"namshi/ab": "1.0.*"

```

Creating and running a test
---------------------------

[](#creating-and-running-a-test)

Creating tests is very simple, as you only need to define the test name and the variations, with their absolute probability:

```
use Namshi\AB\Test;

$homepageColorTest = new Test('homepage_color', array(
    'blue' => 1,
    'red' => 1,
));
```

and at this point you can change the color of the homepage by simply running the test and checking which variation has been picked:

```

  ...
  ...
