Skip to content

Nested Getters and Setters #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Created test cases for nested getters and setters
  • Loading branch information
unknown authored and unknown committed Oct 10, 2013
commit 0dc92249edef848ff62b48139a14e6d78ec413d7
35 changes: 34 additions & 1 deletion tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,38 @@ public function testUnset()
$this->assertFalse(isset($user2->note1));
$this->assertFalse(isset($user2->note2));
}


public function testSetAndGetNestedValues()
{
$user = User::create(array('name' => 'John Doe', 'notes' => array('note1' => 'ABC', 'note2' => 'DEF')));

$user = User::find($user->_id);

$this->assertTrue($user->getAttribute('notes.note1') === 'ABC');
$user->setAttribute('notes.note1', 'XYZ');

$this->assertFalse($user->getAttribute('notes.note1') === 'ABC');
$this->assertTrue($user->getAttribute('notes.note1') === 'XYZ');

$user->notesNote4 = "GHI";
$this->assertTrue($user->notesNote4 === "GHI");

}

public function testSetAndGetNestedMutators()
{
$user = User::create(array('name' => 'John Doe', 'notes' => array('note1' => 'ABC', 'note3' => 'DEF')));

$user = User::find($user->_id);

$note3 = $user->notesNote3;

$this->assertTrue($note3 === 'DEFmutated');
$this->assertTrue($user->notesNote1 === 'ABC');

$user->notesNote3 = "ABCDEF";

$this->assertFalse($user->notesNote3 === 'ABCDEF');
$this->assertTrue($user->notesNote3 === 'abcdefmutated');
}
}