diff --git a/tests/PhactoryTest.php b/tests/PhactoryTest.php index c77ae4b..4d26d73 100644 --- a/tests/PhactoryTest.php +++ b/tests/PhactoryTest.php @@ -32,9 +32,57 @@ public function testBlueprintsOverlay() 'first_name' => 'Fronzel', 'last_name' => 'Neekburm', 'email' => 'user0001@example.org', - 'isadmin' => true, + 'is_admin' => true, )); } + + public function testOverrideAttributes() + { + Phactory::factory('user', 'UserFactory'); + $user = Phactory::user(array( + 'last_name' => 'Blarg#{sn}', + )); + + $this->assertEquals($user, (object)array( + 'first_name' => 'Fronzel', + 'last_name' => 'Blarg0001', + 'email' => 'user0001@example.org', + )); + + $admin = Phactory::user('admin', array( + 'first_name' => 'Admin', + )); + + $this->assertEquals($user, (object)array( + 'first_name' => 'Admin', + 'last_name' => 'Neekburm', + 'email' => 'user0001@example.org', + 'is_admin' => true, + )); + } + + public function testRelationships() + { + Phactory::factory('user', 'UserPhactory'); + Phactory::factory('comment', 'CommentFactory'); + $comment = Phactory::comment(); + + $this->assertEquals($comment, (object)array( + 'title' => 'OMGWTFBBQ!', + 'content' => 'Food goes in here.', + 'user' => (object)array( + 'first_name' => 'Fronzel', + 'last_name' => 'Neekburm', + 'email' => 'user#{sn}@example.org', + ) + )); + + $comment = Phactory::comment(array( + 'user' => Phactory::user('admin'), + )); + + $this->assertTrue($comment->user->is_admin); + } } class UserPhactory @@ -51,7 +99,19 @@ public function blueprint() public function admin() { return array( - 'isadmin' => true, + 'is_admin' => true, + ); + } +} + +class CommentPhactory +{ + public function blueprint() + { + return array( + 'title' => 'OMGWTFBBQ!', + 'content' => 'Food goes in here.', + 'user' => Phactory::user(), ); } } \ No newline at end of file