From 851f61dcfa48a57f0568ea981efcc3c0b9acf134 Mon Sep 17 00:00:00 2001 From: thinkingmedia Date: Sat, 2 Jul 2016 12:31:08 -0400 Subject: [PATCH] uses data provider --- .../ORM/AssociationCollectionTest.php | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/tests/TestCase/ORM/AssociationCollectionTest.php b/tests/TestCase/ORM/AssociationCollectionTest.php index 5258046419a..64f43e37e9f 100644 --- a/tests/TestCase/ORM/AssociationCollectionTest.php +++ b/tests/TestCase/ORM/AssociationCollectionTest.php @@ -25,6 +25,10 @@ */ class AssociationCollectionTest extends TestCase { + /** + * @var AssociationCollection + */ + public $associations; /** * setup @@ -137,39 +141,45 @@ public function testKeys() $this->assertEquals(['users'], $this->associations->keys()); } + /** + * Data provider for AssociationCollection::type + */ + public function associationCollectionType() + { + return [ + ['BelongsTo','BelongsToMany'], + ['belongsTo','belongsToMany'], + ['belongsto','belongstomany'] + ]; + } + /** * Test getting association names by type. * - * @return void + * @param string $belongsToStr + * @param string $belongsToManyStr + * @dataProvider associationCollectionType */ - public function testType() + public function testType($belongsToStr, $belongsToManyStr) { - $belongsToCases = ['BelongsTo', 'belongsTo', 'belongsto']; - $belongsToManyCases = ['BelongsToMany', 'belongsToMany', 'belongstomany']; - $belongsTo = new BelongsTo(''); $this->associations->add('Users', $belongsTo); $belongsToMany = new BelongsToMany(''); $this->associations->add('Tags', $belongsToMany); - foreach ($belongsToCases as $belongsToType) { - $this->assertSame( - [$belongsTo], - $this->associations->type($belongsToType) - ); - foreach ($belongsToManyCases as $belongsToManyType) { - $this->assertSame( - [$belongsToMany], - $this->associations->type($belongsToManyType) - ); - $this->assertSame( - [$belongsTo, $belongsToMany], - $this->associations->type([$belongsToType, $belongsToManyType]) - ); - } - } + $this->assertSame([$belongsTo], $this->associations->type($belongsToStr)); + $this->assertSame([$belongsToMany], $this->associations->type($belongsToManyStr)); + $this->assertSame([$belongsTo, $belongsToMany], $this->associations->type([$belongsToStr, $belongsToManyStr])); + } + /** + * Type should return empty array. + * + * @return void + */ + public function hasTypeReturnsEmptyArray() + { foreach (['HasMany', 'hasMany', 'FooBar', 'DoesNotExist'] as $value) { $this->assertSame([], $this->associations->type($value)); }