Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Added tests for overrides and relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Bone committed Jul 13, 2011
1 parent 76bdf71 commit ddf6e9b
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions tests/PhactoryTest.php
Expand Up @@ -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
Expand All @@ -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(),
);
}
}

0 comments on commit ddf6e9b

Please sign in to comment.