PHPackages                             sammaye/yii2-abtest - 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. sammaye/yii2-abtest

ActiveYii2-extension[Testing &amp; Quality](/categories/testing)

sammaye/yii2-abtest
===================

A generic A/B test handler for Yii2

2.0.0(9y ago)21.3k2[1 PRs](https://github.com/Sammaye/yii2-abtest/pulls)PHPPHP &gt;=5.4.0

Since Nov 3Pushed 2y ago2 watchersCompare

[ Source](https://github.com/Sammaye/yii2-abtest)[ Packagist](https://packagist.org/packages/sammaye/yii2-abtest)[ RSS](/packages/sammaye-yii2-abtest/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (6)DependenciesVersions (7)Used By (0)

yii2-abtest
===========

[](#yii2-abtest)

A simple extension for writing A/B Tests in Yii2.

This extension does not include the hooks for various programs, but does allow you to `list()` so you can quickly add it to your analytics code.

Installing
----------

[](#installing)

Simply include it from composer:

```
php ./composer.phar require sammaye/yii2-abtest:"@stable"

```

Adding it to your configuration
-------------------------------

[](#adding-it-to-your-configuration)

Easiest thing is to just show an example of my configuration:

```
'test' => [
	'class' => 'sammaye\abtest\Test',
	'filter' => [
		'rules' => [
			[
				'allow' => false,
				'roles' => ['staff']
			]
		]
	],
	'tests' => [
		[
			'name' => 'Beta Search',
			'values' => ['old', 'new'],
			'default' => 'new'
		]
	]
],

```

The configuration breaks down into two parameters:- `filter` and `tests`.

**Only `tests` is required.**

`filter` allows you to use the `AccessControl` like you would on any controller and provide a set of rules whereby the tests should not take effect.

When an `'allow' => false` filter is matched the test will return the `default` parameter from the test you are looking at and will not not record it in `$_SESSION`.

This way, when you come to `list()` at the end of the page to push onwards for analytics, these tests **will not appear** in that list.

Using it
--------

[](#using-it)

Once it is fully configured you can just use it to detect which path a user takes:

```
Yii::$app->test->value('Beta Search')

```

This function will return either `old` or `new` depending on whether I am a staff member or lady random chooses me.

In order to add it to your analytics code you need to list all active tests and their values:

```
Yii::$app->test->list()

```

This will then print out a list of (for me):

```
[
    'Old Search' => [
    	'name' => 'Old Search',
    	'value' => 'old' // active
    	// custom data could be housed
    	// here from the configuration like "goal"
    ]
]

```

So, the key is name of the test and the value is the configuration object but with `values` replaced with only the active `value`.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

6

Last Release

3511d ago

Major Versions

1.4.0 → 2.0.02016-11-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/7357836d822160350576f98b85244f4d5f960be303a2fcaa15a330187966cbd4?d=identicon)[Sammaye](/maintainers/Sammaye)

---

Top Contributors

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

---

Tags

testyii2AB

### Embed Badge

![Health badge](/badges/sammaye-yii2-abtest/health.svg)

```
[![Health](https://phpackages.com/badges/sammaye-yii2-abtest/health.svg)](https://phpackages.com/packages/sammaye-yii2-abtest)
```

###  Alternatives

[phpab/phpab

A PHP library to create A/B tests.

8442.7k3](/packages/phpab-phpab)[vierge-noire/cakephp-test-suite-light

A test suite for CakePHP application based on Sql queries

13989.9k15](/packages/vierge-noire-cakephp-test-suite-light)[sofa/eloquent-testsuite

Helpers for fast and reliable UNIT tests for your Eloquent Models with PHPUnit

10106.6k](/packages/sofa-eloquent-testsuite)[yegor256/phprack

Light framework for automation of integration tests

254.7k](/packages/yegor256-phprack)

PHPackages © 2026

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