public function testGetRelationValue()
 {
     Model::unguard();
     $author = Author::create(['name' => 'Stevie']);
     $event = EventLog::make(['action' => "user-created", 'related_id' => $author->id, 'related_type' => get_class($author)]);
     Model::reguard();
     $this->assertEquals([$author->id, get_class($author)], $event->getRelationValue('related'));
 }
 public function testDeferredBinding()
 {
     $sessionKey = uniqid('session_key', true);
     Model::unguard();
     $author = Author::create(['name' => 'Stevie']);
     $event = EventLog::create(['action' => "user-created"]);
     Model::reguard();
     $eventId = $event->id;
     // Deferred add
     $author->event_log()->add($event, $sessionKey);
     $this->assertNull($event->related_id);
     $this->assertEmpty($author->event_log);
     $this->assertEquals(0, $author->event_log()->count());
     $this->assertEquals(1, $author->event_log()->withDeferred($sessionKey)->count());
     // Commit deferred
     $author->save(null, $sessionKey);
     $event = EventLog::find($eventId);
     $this->assertEquals(1, $author->event_log()->count());
     $this->assertEquals($author->id, $event->related_id);
     $this->assertEquals(['user-created'], $author->event_log->lists('action'));
     // New session
     $sessionKey = uniqid('session_key', true);
     // Deferred remove
     $author->event_log()->remove($event, $sessionKey);
     $this->assertEquals(1, $author->event_log()->count());
     $this->assertEquals(0, $author->event_log()->withDeferred($sessionKey)->count());
     $this->assertEquals($author->id, $event->related_id);
     $this->assertEquals(['user-created'], $author->event_log->lists('action'));
     // Commit deferred (model is deleted as per definition)
     $author->save(null, $sessionKey);
     $event = EventLog::find($eventId);
     $this->assertEquals(0, $author->event_log()->count());
     $this->assertNull($event);
     $this->assertEmpty($author->event_log);
 }