public function __construct($name, PDO $db) { parent::__construct($name); $this->db = $db; $this->stmt = $db->prepare('insert into experiment_results (experiment, timestamp, behavior, is_control, execution_time, result) values (:experiment, UTC_TIMESTAMP, :behavior, :control, :duration, :result)'); $this->stmt->bindValue(':experiment', $name); }
/** * @expectedException \Exception * @expectedExceptionMessage Control code failed */ public function testExperimentForwardsThrownExceptionsFromControl() { $experiment = Experiment::create()->control(function () { throw new \Exception('Control code failed'); })->candidate(function () { return 'noop'; }); $experiment->run(); }
<?php namespace DaybreakStudios\Analyst\Samples; use DaybreakStudios\Analyst\Experiment; require __DIR__ . '/bootstrap.php'; ob_start(); $fullName = 'Tyler Lartonoix'; $name = Experiment::create()->setThrowOnMismatch(true)->setContext(['name' => $fullName])->control(function ($name) { $name = trim($name); return [substr($name, 0, strpos($name, ' ')), substr($name, strpos($name, ' ') + 1) ?: null]; })->candidate(function ($name) { return [strtok(trim($name), ' '), strtok('') ?: null]; })->run(); printf(":: Results\nFull name: %s\nFirst name: %s\nLast name: %s", $fullName, $name[0], $name[1]); echo ob_get_clean() . "\n";