$dispatcher = new Dispatcher(); // And append it as a subscriber $dispatcher->addSubscriber($analyticsData); // Create a Participation filter $filter = new Percentage(50); // And a Variant Chooser $chooser = new RandomChooser(); // Create the Engine $engine = new Engine($manager, $dispatcher, $filter, $chooser); // Create a tests and its variants $test = new Test('foo_test', [], [Google::EXPERIMENT_ID => 'exp1']); $test->addVariant(new SimpleVariant('_control')); $test->addVariant(new SimpleVariant('_variant1')); $test->addVariant(new SimpleVariant('_variant2')); // Create a second test and its variants $test2 = new Test('bar_test', [], [Google::EXPERIMENT_ID => 'exp2']); $test2->addVariant(new SimpleVariant('_control')); $test2->addVariant(new SimpleVariant('_variant1')); $test2->addVariant(new SimpleVariant('_variant2')); // Add the tests to the Engine $engine->addTest($test); $engine->addTest($test2); // Pseudo: if($user->isAdmin) // If the user is admin, he should not participate at the test // $manager->participate('foo_test', null); // Pseudo: if($app->inDevelopment() and $_GET['phpab']['foo_test]) // $manager->participate('foo_test', $_GET['phpab']['foo_test]); // Start testing. Must occur before the EventCycle of the app starts // Start the engine $engine->start(); // Create the Analytics object and pass the Data Collector data to it
use PhpAb\Event\Dispatcher; use PhpAb\Participation\Filter\Percentage; use PhpAb\Variant\Chooser\RandomChooser; use PhpAb\Variant\SimpleVariant; use PhpAb\Variant\CallbackVariant; use PhpAb\Engine\Engine; use PhpAb\Test\Test; $storage = new Cookie('phpab'); $manager = new Manager($storage); $analyticsData = new Generic(); $dispatcher = new Dispatcher(); $dispatcher->addSubscriber($analyticsData); $filter = new Percentage(50); $chooser = new RandomChooser(); $engine = new Engine($manager, $dispatcher, $filter, $chooser); $test = new Test('foo_test'); $test->addVariant(new SimpleVariant('_control')); $test->addVariant(new CallbackVariant('v1', function () { echo 'v1'; })); $test->addVariant(new CallbackVariant('v2', function () { echo 'v2'; })); $test->addVariant(new CallbackVariant('v3', function () { echo 'v3'; })); // Add some tests $engine->addTest($test); $engine->start(); // Here starts MongoDB interaction // Provide a MongoDB Collection to be injected
/** * @expectedException \PhpAb\Exception\EngineLockedException */ public function testStartTwice() { // Arrange $engine = new Engine($this->getMock(ManagerInterface::class), $this->getMock(DispatcherInterface::class), $this->getMock(FilterInterface::class), null); $test = new Test('foo_test'); $test->addVariant(new SimpleVariant('_control')); // Act $engine->start(); $engine->start(); // Assert }