Пример #1
0
 public function testSetRelationValue()
 {
     Model::unguard();
     $post = Post::create(['title' => "First post", 'description' => "Yay!!"]);
     $author1 = Author::create(['name' => 'Stevie', 'email' => '*****@*****.**']);
     $author2 = Author::create(['name' => 'Louie', 'email' => '*****@*****.**']);
     $author3 = Author::make(['name' => 'Charlie', 'email' => '*****@*****.**']);
     Model::reguard();
     // Set by Model object
     $post->author = $author1;
     $this->assertEquals($author1->id, $post->author_id);
     $this->assertEquals('Stevie', $post->author->name);
     // Set by primary key
     $post->author = $author2->id;
     $this->assertEquals($author2->id, $post->author_id);
     $this->assertEquals('Louie', $post->author->name);
     // Nullify
     $post->author = null;
     $this->assertNull($post->author_id);
     $this->assertNull($post->author);
     // Deferred in memory
     $post->author = $author3;
     $this->assertEquals('Charlie', $post->author->name);
     $this->assertNull($post->author_id);
     $author3->save();
     $this->assertEquals($author3->id, $post->author_id);
 }
Пример #2
0
 public function testCommitBinding()
 {
     $sessionKey = uniqid('session_key', true);
     DeferredBinding::truncate();
     Model::unguard();
     $author = Author::make(['name' => 'Stevie']);
     $post = Post::create(['title' => "First post"]);
     Model::reguard();
     $author->posts()->add($post, $sessionKey);
     $this->assertEquals(1, DeferredBinding::count());
     $author->commitDeferred($sessionKey);
     $this->assertEquals(0, DeferredBinding::count());
 }