Skip to content

Commit 6a8aaad

Browse files
committed
Clean up tests a bit.
Use less code to get things done.
1 parent 95a0fb6 commit 6a8aaad

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

tests/TestCase/ORM/MarshallerTest.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -721,16 +721,10 @@ public function testBelongsToManyWithMixedData()
721721
]
722722
];
723723

724-
$articles = TableRegistry::get('Articles');
725-
$articles->belongsToMany('Tags');
726-
727724
$tags = TableRegistry::get('Tags');
728725

729-
$article = $articles->newEntity($data, [
730-
'associated' => [
731-
'Tags'
732-
]
733-
]);
726+
$marshaller = new Marshaller($this->articles);
727+
$article = $marshaller->one($data, ['associated' => ['Tags']]);
734728

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

743737
$tagCount = $tags->find()->count();
744-
$articles->save($article);
738+
$this->articles->save($article);
745739

746740
$this->assertEquals($tagCount + 2, $tags->find()->count());
747741
}
@@ -754,20 +748,18 @@ public function testBelongsToManyWithMixedData()
754748
public function testHasManyWithIds()
755749
{
756750
$data = [
757-
'username' => 'lux',
758-
'password' => 'passphrase',
751+
'title' => 'article',
752+
'body' => 'some content',
759753
'comments' => [
760754
'_ids' => [1, 2]
761755
]
762756
];
763757

764-
$userTable = TableRegistry::get('Users');
765-
$userTable->hasMany('Comments');
766-
$commentTable = TableRegistry::get('Comments');
767-
$user = $userTable->newEntity($data, ['associated' => ['Comments']]);
758+
$marshaller = new Marshaller($this->articles);
759+
$article = $marshaller->one($data, ['associated' => ['Comments']]);
768760

769-
$this->assertEquals($user->comments[0], $commentTable->get(1));
770-
$this->assertEquals($user->comments[1], $commentTable->get(2));
761+
$this->assertEquals($article->comments[0], $this->comments->get(1));
762+
$this->assertEquals($article->comments[1], $this->comments->get(2));
771763
}
772764

773765
/**
@@ -785,11 +777,12 @@ public function testHasManyInvalidData()
785777
]
786778
];
787779

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

791784
$data['comments'] = 1;
792-
$article = $this->articles->newEntity($data, ['associated' => ['Comments']]);
785+
$article = $marshaller->one($data, ['associated' => ['Comments']]);
793786
$this->assertEmpty($article->comments);
794787
}
795788

0 commit comments

Comments
 (0)