/** * 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 get relationships defined on a model, including runtime relationships * * @return void **/ public function testCanIntrospectRelationshipsIncludingRuntimeRelationships() { // Note that we're expecting the relationship registered in the previous test $this->assertEquals(['posts', 'bio'], User::introspectRelationships(), 'User should have had two relationships of "posts" and "bio"'); }
/** * 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'); }