Example #1
0
 /**
  * When the view is rendered, this funciton saves all event->firing pairing to storage.
  */
 public static function saveSession()
 {
     if (!empty(self::$instance)) {
         foreach (self::$instance as $event) {
             $experiment = Experiments::firstOrCreate(['experiment' => $event->name, 'goal' => $event->goal]);
             $event = Events::firstOrCreate(['instance_id' => self::$session->id, 'name' => $event->name, 'value' => $event->fired]);
             $experiment->events()->save($event);
             self::$session->events()->save($event);
         }
     }
     return Session::get(config('laravel-ab.cache_key'));
 }
Example #2
0
 public function testNestedView()
 {
     $this->visit('/')->see('Test-')->dontSee('@ab');
     Ab::saveSession();
     $test1_experiments = Experiments::where(['experiment' => 'test1'])->get();
     $test2_experiments = Experiments::where(['experiment' => 'test2'])->get();
     $test1 = $test1_experiments->first();
     $test2 = $test2_experiments->first();
     $this->assertEquals($test1_experiments->count(), 1);
     $this->assertEquals($test1->events()->count(), 1);
     $this->assertEquals($test2_experiments->count(), 1);
     $this->assertEquals($test2->events()->count(), 1);
 }