/**
* Tests that attaching an association to a query will trigger beforeFind
* for the target table
*
* @return void
*/
public function testAttachToBeforeFindExtraOptions()
{
$query = $this->getMock('\\Cake\\ORM\\Query', ['join', 'select'], [null, null]);
$config = ['sourceTable' => $this->article, 'targetTable' => $this->tag];
$table = TableRegistry::get('ArticlesTags');
$association = new BelongsToMany('Tags', $config);
$listener = $this->getMock('stdClass', ['__invoke']);
$this->tag->getEventManager()->attach($listener, 'Model.beforeFind');
$opts = ['something' => 'more'];
$listener->expects($this->once())->method('__invoke')->with($this->isInstanceOf('\\Cake\\Event\\Event'), $this->isInstanceOf('\\Cake\\ORM\\Query'), $opts, false);
$listener2 = $this->getMock('stdClass', ['__invoke']);
$table->getEventManager()->attach($listener2, 'Model.beforeFind');
$listener2->expects($this->once())->method('__invoke')->with($this->isInstanceOf('\\Cake\\Event\\Event'), $this->isInstanceOf('\\Cake\\ORM\\Query'), [], false);
$association->attachTo($query, ['queryBuilder' => function ($q) {
return $q->applyOptions(['something' => 'more']);
}]);
}