-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
I need a way to set the variation manually. Here is my original code:
class SplitTestService
{
const COOKIE_NAME = 'ab_seed';
protected $container;
public function __construct()
{
$this->container = new Container();
$this->setSeed();
}
public function getHomepageVariation(): string
{
return tap(new Test('homepage'), function (Test $test) {
$this->container->add($test);
$test->setVariations([
SplitTests::HOMEPAGE_DEFAULT => 7,
SplitTests::HOMEPAGE_NEW => 3
]);
})->getVariation();
}
private function setSeed(): void
{
$seed = request()->cookie(self::COOKIE_NAME);
if (!$seed) {
$seed = mt_rand();
Cookie::queue(self::COOKIE_NAME, (string)$seed);
}
$this->container->setSeed($seed);
}
}But now in order to ease the development and testing I need to preset the variation from GET variable, something like this:
return tap(new Test('homepage'), function (Test $test) {
$this->container->add($test);
$test->setVariations([
SplitTests::HOMEPAGE_DEFAULT => 7,
SplitTests::HOMEPAGE_NEW => 3
]);
// a code to pre-set variation if the specific request variable is passed
if (!App::environment('production') && ($homepageVariation = request()->query('homepage-variation'))) {
$test->setVariation('b' === $homepageVariation ? SplitTests::HOMEPAGE_NEW : SplitTests::HOMEPAGE_DEFAULT);
}
})->getVariation();What do you think of it @odino ?
Metadata
Metadata
Assignees
Labels
No labels