Skip to content

Commit 851f61d

Browse files
author
thinkingmedia
committed
uses data provider
1 parent 765064b commit 851f61d

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

tests/TestCase/ORM/AssociationCollectionTest.php

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
*/
2626
class AssociationCollectionTest extends TestCase
2727
{
28+
/**
29+
* @var AssociationCollection
30+
*/
31+
public $associations;
2832

2933
/**
3034
* setup
@@ -137,39 +141,45 @@ public function testKeys()
137141
$this->assertEquals(['users'], $this->associations->keys());
138142
}
139143

144+
/**
145+
* Data provider for AssociationCollection::type
146+
*/
147+
public function associationCollectionType()
148+
{
149+
return [
150+
['BelongsTo','BelongsToMany'],
151+
['belongsTo','belongsToMany'],
152+
['belongsto','belongstomany']
153+
];
154+
}
155+
140156
/**
141157
* Test getting association names by type.
142158
*
143-
* @return void
159+
* @param string $belongsToStr
160+
* @param string $belongsToManyStr
161+
* @dataProvider associationCollectionType
144162
*/
145-
public function testType()
163+
public function testType($belongsToStr, $belongsToManyStr)
146164
{
147-
$belongsToCases = ['BelongsTo', 'belongsTo', 'belongsto'];
148-
$belongsToManyCases = ['BelongsToMany', 'belongsToMany', 'belongstomany'];
149-
150165
$belongsTo = new BelongsTo('');
151166
$this->associations->add('Users', $belongsTo);
152167

153168
$belongsToMany = new BelongsToMany('');
154169
$this->associations->add('Tags', $belongsToMany);
155170

156-
foreach ($belongsToCases as $belongsToType) {
157-
$this->assertSame(
158-
[$belongsTo],
159-
$this->associations->type($belongsToType)
160-
);
161-
foreach ($belongsToManyCases as $belongsToManyType) {
162-
$this->assertSame(
163-
[$belongsToMany],
164-
$this->associations->type($belongsToManyType)
165-
);
166-
$this->assertSame(
167-
[$belongsTo, $belongsToMany],
168-
$this->associations->type([$belongsToType, $belongsToManyType])
169-
);
170-
}
171-
}
171+
$this->assertSame([$belongsTo], $this->associations->type($belongsToStr));
172+
$this->assertSame([$belongsToMany], $this->associations->type($belongsToManyStr));
173+
$this->assertSame([$belongsTo, $belongsToMany], $this->associations->type([$belongsToStr, $belongsToManyStr]));
174+
}
172175

176+
/**
177+
* Type should return empty array.
178+
*
179+
* @return void
180+
*/
181+
public function hasTypeReturnsEmptyArray()
182+
{
173183
foreach (['HasMany', 'hasMany', 'FooBar', 'DoesNotExist'] as $value) {
174184
$this->assertSame([], $this->associations->type($value));
175185
}

0 commit comments

Comments
 (0)