Skip to content

Commit

Permalink
uses data provider
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingmedia committed Jul 2, 2016
1 parent 765064b commit 851f61d
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions tests/TestCase/ORM/AssociationCollectionTest.php
Expand Up @@ -25,6 +25,10 @@
*/
class AssociationCollectionTest extends TestCase
{
/**
* @var AssociationCollection
*/
public $associations;

/**
* setup
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 851f61d

Please sign in to comment.