From 395de81c0739bea7f7edd47e8bc8a98fe516aff9 Mon Sep 17 00:00:00 2001 From: ndm2 Date: Sun, 11 Jan 2015 16:38:19 +0100 Subject: [PATCH] Make beforeFind triggered by associations use ArrayObject too --- src/ORM/Association.php | 2 +- tests/TestCase/ORM/TableTest.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ORM/Association.php b/src/ORM/Association.php index 65519ef7133..b1079d55870 100644 --- a/src/ORM/Association.php +++ b/src/ORM/Association.php @@ -611,7 +611,7 @@ protected function _dispatchBeforeFind($query) { $table = $this->target(); $options = $query->getOptions(); - $table->dispatchEvent('Model.beforeFind', [$query, $options, false]); + $table->dispatchEvent('Model.beforeFind', [$query, new \ArrayObject($options), false]); } /** diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index 7a2e67c87e4..662aa5b36e6 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -3391,8 +3391,19 @@ public function testValidateUniqueScope() public function testCallbackArgumentTypes() { $table = TableRegistry::get('articles'); + $table->belongsTo('authors'); + $eventManager = $table->eventManager(); + $associationBeforeFindCount = 0; + $table->association('authors')->target()->eventManager()->attach( + function (Event $event, Query $query, ArrayObject $options, $primary) use (&$associationBeforeFindCount) { + $this->assertTrue(is_bool($primary)); + $associationBeforeFindCount ++; + }, + 'Model.beforeFind' + ); + $beforeFindCount = 0; $eventManager->attach( function (Event $event, Query $query, ArrayObject $options, $primary) use (&$beforeFindCount) { @@ -3401,7 +3412,8 @@ function (Event $event, Query $query, ArrayObject $options, $primary) use (&$bef }, 'Model.beforeFind' ); - $table->find()->first(); + $table->find()->contain('authors')->first(); + $this->assertEquals(1, $associationBeforeFindCount); $this->assertEquals(1, $beforeFindCount); $buildValidatorCount = 0;