Skip to content
Permalink
Browse files

Adding tests for bindingKey in HasMany

  • Loading branch information...
lorenzo committed Jul 2, 2015
1 parent 5739a30 commit eea020b89918bfe63d5bd0862324b7f7e20bfe2a
Showing with 36 additions and 1 deletion.
  1. +36 −1 tests/TestCase/ORM/BindingKeyTest.php
@@ -18,7 +18,7 @@
use Cake\TestSuite\TestCase;
/**
* Integration tetss for table operations involving composite keys
* Integration tests for usinge the bindingKey in associations
*/
class BindingKeyTest extends TestCase
{
@@ -44,6 +44,16 @@ public function strategiesProviderJoinable()
return [['join'], ['select']];
}
/**
* Data provider for the two types of strategies HasMany and BelongsToMany implements
*
* @return void
*/
public function strategiesProviderExternal()
{
return [['subquery'], ['select']];
}
/**
* Tests that bindingKey can be used in belongsTo associations
*
@@ -98,4 +108,29 @@ public function testHasOne($strategy) {
$this->assertEquals(3, $result->site_author->id);
}
/**
* Tests that bindingKey can be used in hasOne associations
*
* @dataProvider strategiesProviderExternal
* @return void
*/
public function testHasMany($strategy)
{
$users = TableRegistry::get('Users');
$authors = $users->hasMany('SiteAuthors', [
'bindingKey' => 'username',
'foreignKey' => 'name',
'strategy' => $strategy
]);
$authors->updateAll(['name' => 'garrett'], ['id >' => 2]);
$result = $users->find()
->contain(['SiteAuthors'])
->where(['username' => 'garrett']);
$expected = [3, 4];
$result = $result->extract('site_authors.{*}.id')->toList();
$this->assertEquals($expected, $result);
}
}

0 comments on commit eea020b

Please sign in to comment.
You can’t perform that action at this time.