Browse Source

Make beforeFind triggered by associations use ArrayObject too

ndm2 11 years ago
parent
commit
395de81c07
2 changed files with 14 additions and 2 deletions
  1. 1 1
      src/ORM/Association.php
  2. 13 1
      tests/TestCase/ORM/TableTest.php

+ 1 - 1
src/ORM/Association.php

@@ -611,7 +611,7 @@ abstract class Association
     {
         $table = $this->target();
         $options = $query->getOptions();
-        $table->dispatchEvent('Model.beforeFind', [$query, $options, false]);
+        $table->dispatchEvent('Model.beforeFind', [$query, new \ArrayObject($options), false]);
     }
 
     /**

+ 13 - 1
tests/TestCase/ORM/TableTest.php

@@ -3391,8 +3391,19 @@ class TableTest extends TestCase
     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 @@ class TableTest extends TestCase
             },
             'Model.beforeFind'
         );
-        $table->find()->first();
+        $table->find()->contain('authors')->first();
+        $this->assertEquals(1, $associationBeforeFindCount);
         $this->assertEquals(1, $beforeFindCount);
 
         $buildValidatorCount = 0;