/** * Tests to make sure we can serialize and unserialize a model * * @return void **/ public function testCanDoSimpleSerialization() { $user = User::oneOrFail(1); $serialized = serialize($user); $unserialized = unserialize($serialized); $this->assertEquals($user, $unserialized, 'Unserialize did not result in the original model'); }
/** * Tests to make sure we can add a dynamic relationship at runtime * * @return void **/ public function testCanAddRuntimeRelationship() { User::registerRelationship('bio', function ($model) { return $model->oneToOne('Bio'); }); $this->assertEquals('This is my bio about me.', User::oneOrFail(1)->bio->text, 'Bio call should have returned the bio for user 1'); $this->assertEquals('This is my bio about me.', User::oneOrFail(1)->bio()->rows()->text, 'Bio call should have returned the bio for user 1'); }
/** * Tests to make sure saving a one to many relationship properly sets the associated field on the related side * * @return void **/ public function testSaveOneToManyAssociatesRelated() { User::oneOrFail(1)->posts()->save(['content' => 'This is a test post']); $this->assertArrayHasKey('user_id', User::oneOrFail(1)->posts->last(), 'Saved item should have automatically included a user_id'); }