Skip to content

Commit

Permalink
Clean up tests a bit.
Browse files Browse the repository at this point in the history
Use less code to get things done.
  • Loading branch information
markstory committed May 16, 2015
1 parent 95a0fb6 commit 6a8aaad
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -721,16 +721,10 @@ public function testBelongsToManyWithMixedData()
]
];

$articles = TableRegistry::get('Articles');
$articles->belongsToMany('Tags');

$tags = TableRegistry::get('Tags');

$article = $articles->newEntity($data, [
'associated' => [
'Tags'
]
]);
$marshaller = new Marshaller($this->articles);
$article = $marshaller->one($data, ['associated' => ['Tags']]);

$this->assertEquals($data['tags'][0]['name'], $article->tags[0]->name);
$this->assertEquals($data['tags'][1]['name'], $article->tags[1]->name);
Expand All @@ -741,7 +735,7 @@ public function testBelongsToManyWithMixedData()
$this->assertEquals($article->tags[2]->isNew(), false);

$tagCount = $tags->find()->count();
$articles->save($article);
$this->articles->save($article);

$this->assertEquals($tagCount + 2, $tags->find()->count());
}
Expand All @@ -754,20 +748,18 @@ public function testBelongsToManyWithMixedData()
public function testHasManyWithIds()
{
$data = [
'username' => 'lux',
'password' => 'passphrase',
'title' => 'article',
'body' => 'some content',
'comments' => [
'_ids' => [1, 2]
]
];

$userTable = TableRegistry::get('Users');
$userTable->hasMany('Comments');
$commentTable = TableRegistry::get('Comments');
$user = $userTable->newEntity($data, ['associated' => ['Comments']]);
$marshaller = new Marshaller($this->articles);
$article = $marshaller->one($data, ['associated' => ['Comments']]);

$this->assertEquals($user->comments[0], $commentTable->get(1));
$this->assertEquals($user->comments[1], $commentTable->get(2));
$this->assertEquals($article->comments[0], $this->comments->get(1));
$this->assertEquals($article->comments[1], $this->comments->get(2));
}

/**
Expand All @@ -785,11 +777,12 @@ public function testHasManyInvalidData()
]
];

$article = $this->articles->newEntity($data, ['associated' => ['Comments']]);
$marshaller = new Marshaller($this->articles);
$article = $marshaller->one($data, ['associated' => ['Comments']]);
$this->assertEmpty($article->comments);

$data['comments'] = 1;
$article = $this->articles->newEntity($data, ['associated' => ['Comments']]);
$article = $marshaller->one($data, ['associated' => ['Comments']]);
$this->assertEmpty($article->comments);
}

Expand Down

0 comments on commit 6a8aaad

Please sign in to comment.