public function testHasManySave() { $user = User::read(3); $comment1 = Comment::create(['text' => 'create']); $comment2 = Comment::newRecord(['text' => 'new record']); $user->Comment[] = $comment1; $user->Comment[] = $comment2; $this->assertEquals(true, $user->save()); $this->assertEquals($user->id, $comment1->user_id); $this->assertEquals($user->id, $comment2->user_id); $this->assertEquals('create', $user->Comment[0]->text); $this->assertEquals('new record', $user->Comment[1]->text); /* * 本当に保存できたかreadで確認 */ $savedComment1 = Comment::read($user->Comment[0]->id); $savedComment2 = Comment::read($user->Comment[1]->id); $this->assertEquals('create', $savedComment1->text); $this->assertEquals('new record', $savedComment2->text); $this->assertEquals($user->id, $savedComment1->user_id); $this->assertEquals($user->id, $savedComment2->user_id); }