예제 #1
0
 public function testEmptyParticipationStore()
 {
     // Arrange
     $analytics = new \PhpAb\Analytics\MongoDB([], $this->mockedMongoCollection);
     // Act
     $result = $analytics->store('1.2.3.4-abc', 'homepage.php');
     // Assert
     $this->assertFalse($result);
 }
예제 #2
0
$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
$mongoCollection = (new \MongoDB\Client())->phpab->run;
// Inject together with Analytics Data
$analytics = new \PhpAb\Analytics\MongoDB($analyticsData->getTestsData(), $mongoCollection);
// Store it providing a user identifier and a scenario
// typically a URL or a controller name
$result = $analytics->store('1.2.3.4-abc', 'homepage.php');
var_dump($result);