Skip to content

Commit

Permalink
Merge pull request #25 from sizuhiko/develop
Browse files Browse the repository at this point in the history
release 2.0.2
  • Loading branch information
sizuhiko committed Jun 21, 2016
2 parents 9038254 + 1b1df87 commit f94b39d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Factory/FabricateModelFactory.php
Expand Up @@ -57,6 +57,7 @@ public function attributes_for($recordCount, $definition)
*/
protected function fakeRecord($tableInfo, $index)
{
$record = [];
foreach ($tableInfo as $field => $fieldInfo) {
if (empty($fieldInfo['type'])) {
continue;
Expand Down
30 changes: 24 additions & 6 deletions tests/Case/Fabricate/FabricateTest.php
Expand Up @@ -22,14 +22,22 @@ public function setUp() {
->addColumn('published', 'string', ['limit' => 1])
->addColumn('created', 'datetime')
->addColumn('updated', 'datetime')
->belongsTo('Author', 'author_id', 'User'),
->belongsTo('Author', 'author_id', 'User')
->hasMany('PostTag', 'post_id'),
'User' => (new FabricateModel('User'))
->addColumn('id', 'integer')
->addColumn('user', 'string', ['null' => true, 'limit' => 255])
->addColumn('password', 'string', ['null' => true, 'limit' => 255])
->addColumn('created', 'datetime')
->addColumn('updated', 'datetime')
->hasMany('Post', 'author_id'),
'Tag' => (new FabricateModel('Tag'))
->addColumn('id', 'integer')
->addColumn('title', 'string', ['null' => false, 'limit' => 50])
->hasMany('PostTag', 'tag_id'),
'PostTag' => (new FabricateModel('PostTag'))
->belongsTo('Post', 'post_id', 'Post')
->belongsTo('Tag', 'tag_id', 'Tag'),
];
Fabricate::config(function($config) use($adaptor) {
$config->adaptor = $adaptor;
Expand All @@ -41,7 +49,7 @@ public function testAttributesFor() {
return ["created" => "2013-10-09 12:40:28", "updated" => "2013-10-09 12:40:28"];
});
$this->assertCount(10, $results);
for ($i = 0; $i < 10; $i++) {
for ($i = 0; $i < 10; $i++) {
$this->assertEquals($i+1, $results[$i]['id']);
$this->assertEquals($i+1, $results[$i]['author_id']);
$this->assertEquals(50, strlen($results[$i]['title']));
Expand Down Expand Up @@ -70,7 +78,7 @@ public function testCreate() {
return ["created" => "2013-10-09 12:40:28", "updated" => "2013-10-09 12:40:28"];
});
$this->assertCount(10, $results);
for ($i = 0; $i < 10; $i++) {
for ($i = 0; $i < 10; $i++) {
$this->assertEquals($i+1, $results[$i]['Post']['id']);
$this->assertEquals($i+1, $results[$i]['Post']['author_id']);
$this->assertEquals(50, strlen($results[$i]['Post']['title']));
Expand All @@ -84,7 +92,7 @@ public function testCreate() {
public function testAttributesForWithArrayOption() {
$results = Fabricate::attributes_for('Post', 10, ["created" => "2013-10-09 12:40:28", "updated" => "2013-10-09 12:40:28"]);
$this->assertCount(10, $results);
for ($i = 0; $i < 10; $i++) {
for ($i = 0; $i < 10; $i++) {
$this->assertEquals($i+1, $results[$i]['id']);
$this->assertEquals($i+1, $results[$i]['author_id']);
$this->assertEquals(50, strlen($results[$i]['title']));
Expand All @@ -111,7 +119,7 @@ public function testCreateWithArrayOption() {
$this->assertCount(10, $results);

$this->assertCount(10, $results);
for ($i = 0; $i < 10; $i++) {
for ($i = 0; $i < 10; $i++) {
$this->assertEquals($i+1, $results[$i]['Post']['id']);
$this->assertEquals($i+1, $results[$i]['Post']['author_id']);
$this->assertEquals(50, strlen($results[$i]['Post']['title']));
Expand Down Expand Up @@ -187,12 +195,22 @@ public function testCreateWithAssociation() {
$results = Fabricate::create('User', function($data, $world) {
return [
'user' => 'taro',
'Post' => $world->association('Post', 3, ['id'=>false,'author_id'=>false]),
'Post' => $world->association('Post', 3, [
'id' => false,
'author_id' => false,
'PostTag' => $world->association('PostTag', 2, [
'post_id' => false,
'tag_id' => false,
'Tag' => $world->association('Tag')
]),
]),
];
});

$this->assertEquals('taro', $results['User']['user']);
$this->assertCount(3, $results['User']['Post']);
$this->assertCount(2, $results['User']['Post'][0]['PostTag']);
$this->assertNotEmpty($results['User']['Post'][0]['PostTag'][0]['Tag']);
}

public function testCreateWithDefinedAssociation() {
Expand Down

0 comments on commit f94b39d

Please sign in to comment.