Browse Source

Merge pull request #12956 from cakephp/4.x-cleanup

Use EntityInterface where applicable.
Mark Story 7 years ago
parent
commit
25d03343c7

+ 1 - 1
src/Mailer/Mailer.php

@@ -69,7 +69,7 @@ use Cake\View\ViewBuilder;
  *     ];
  * }
  *
- * public function onRegistration(EventInterface $event, Entity $entity, ArrayObject $options)
+ * public function onRegistration(EventInterface $event, EntityInterface $entity, ArrayObject $options)
  * {
  *     if ($entity->isNew()) {
  *          $this->send('welcome', [$entity]);

+ 4 - 3
tests/TestCase/ORM/Association/BelongsToManyTest.php

@@ -18,6 +18,7 @@ namespace Cake\Test\TestCase\ORM\Association;
 use Cake\Database\Connection;
 use Cake\Database\Expression\QueryExpression;
 use Cake\Datasource\ConnectionManager;
+use Cake\Datasource\EntityInterface;
 use Cake\Event\EventInterface;
 use Cake\ORM\Association\BelongsTo;
 use Cake\ORM\Association\BelongsToMany;
@@ -550,7 +551,7 @@ class BelongsToManyTest extends TestCase
 
         $joint->expects($this->at(1))
             ->method('save')
-            ->will($this->returnCallback(function (Entity $e, $opts) use ($entity) {
+            ->will($this->returnCallback(function (EntityInterface $e, $opts) use ($entity) {
                 $expected = ['article_id' => 1, 'tag_id' => 2];
                 $this->assertEquals($expected, $e->toArray());
                 $this->assertEquals(['foo' => 'bar'], $opts);
@@ -561,7 +562,7 @@ class BelongsToManyTest extends TestCase
 
         $joint->expects($this->at(2))
             ->method('save')
-            ->will($this->returnCallback(function (Entity $e, $opts) use ($entity) {
+            ->will($this->returnCallback(function (EntityInterface $e, $opts) use ($entity) {
                 $expected = ['article_id' => 1, 'tag_id' => 3];
                 $this->assertEquals($expected, $e->toArray());
                 $this->assertEquals(['foo' => 'bar'], $opts);
@@ -605,7 +606,7 @@ class BelongsToManyTest extends TestCase
 
         $joint->expects($this->once())
             ->method('save')
-            ->will($this->returnCallback(function (Entity $e, $opts) {
+            ->will($this->returnCallback(function (EntityInterface $e, $opts) {
                 $this->assertSame('Plugin.ArticlesTags', $e->getSource());
 
                 return $e;

+ 4 - 3
tests/TestCase/ORM/RulesCheckerIntegrationTest.php

@@ -15,6 +15,7 @@ declare(strict_types=1);
  */
 namespace Cake\Test\TestCase\ORM;
 
+use Cake\Datasource\EntityInterface;
 use Cake\Event\EventInterface;
 use Cake\ORM\Entity;
 use Cake\ORM\RulesChecker;
@@ -108,7 +109,7 @@ class RulesCheckerIntegrationTest extends TestCase
             ->getTarget()
             ->rulesChecker()
             ->add(
-                function (Entity $entity) {
+                function (EntityInterface $entity) {
                     return false;
                 },
                 ['errorField' => 'title', 'message' => 'This is an error']
@@ -752,7 +753,7 @@ class RulesCheckerIntegrationTest extends TestCase
 
         $table->getEventManager()->on(
             'Model.beforeRules',
-            function (EventInterface $event, Entity $entity, \ArrayObject $options, $operation) {
+            function (EventInterface $event, EntityInterface $entity, \ArrayObject $options, $operation) {
                 $this->assertEquals(
                     [
                         'atomic' => true,
@@ -792,7 +793,7 @@ class RulesCheckerIntegrationTest extends TestCase
 
         $table->getEventManager()->on(
             'Model.afterRules',
-            function (EventInterface $event, Entity $entity, \ArrayObject $options, $result, $operation) {
+            function (EventInterface $event, EntityInterface $entity, \ArrayObject $options, $result, $operation) {
                 $this->assertEquals(
                     [
                         'atomic' => true,

+ 19 - 19
tests/TestCase/ORM/TableTest.php

@@ -2715,7 +2715,7 @@ class TableTest extends TestCase
             new Entity(['name' => 'jose']),
         ];
 
-        $table->getEventManager()->on('Model.beforeSave', function (EventInterface $event, Entity $entity) {
+        $table->getEventManager()->on('Model.beforeSave', function (EventInterface $event, EntityInterface $entity) {
             if ($entity->name === 'jose') {
                 throw new \Exception('Oh noes');
             }
@@ -4774,7 +4774,7 @@ class TableTest extends TestCase
         $actualOptions = null;
         $tags->junction()->getEventManager()->on(
             'Model.beforeDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualOptions) {
                 $actualOptions = $options->getArrayCopy();
             }
         );
@@ -4809,7 +4809,7 @@ class TableTest extends TestCase
         $actualOptions = null;
         $tags->junction()->getEventManager()->on(
             'Model.beforeSave',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualOptions) {
                 $actualOptions = $options->getArrayCopy();
             }
         );
@@ -4846,7 +4846,7 @@ class TableTest extends TestCase
         $actualOptions = null;
         $tags->junction()->getEventManager()->on(
             'Model.beforeDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualOptions) {
                 $actualOptions = $options->getArrayCopy();
             }
         );
@@ -4879,13 +4879,13 @@ class TableTest extends TestCase
         $actualDeleteOptions = null;
         $tags->junction()->getEventManager()->on(
             'Model.beforeSave',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualSaveOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualSaveOptions) {
                 $actualSaveOptions = $options->getArrayCopy();
             }
         );
         $tags->junction()->getEventManager()->on(
             'Model.beforeDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualDeleteOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualDeleteOptions) {
                 $actualDeleteOptions = $options->getArrayCopy();
             }
         );
@@ -4938,7 +4938,7 @@ class TableTest extends TestCase
         $actualOptions = null;
         $articles->getTarget()->getEventManager()->on(
             'Model.beforeDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualOptions) {
                 $actualOptions = $options->getArrayCopy();
             }
         );
@@ -4974,7 +4974,7 @@ class TableTest extends TestCase
         $actualOptions = null;
         $articles->getTarget()->getEventManager()->on(
             'Model.beforeSave',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualOptions) {
                 $actualOptions = $options->getArrayCopy();
             }
         );
@@ -5017,7 +5017,7 @@ class TableTest extends TestCase
         $actualOptions = null;
         $articles->getTarget()->getEventManager()->on(
             'Model.beforeDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualOptions) {
                 $actualOptions = $options->getArrayCopy();
             }
         );
@@ -5054,13 +5054,13 @@ class TableTest extends TestCase
         $actualDeleteOptions = null;
         $articles->getTarget()->getEventManager()->on(
             'Model.beforeSave',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualSaveOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualSaveOptions) {
                 $actualSaveOptions = $options->getArrayCopy();
             }
         );
         $articles->getTarget()->getEventManager()->on(
             'Model.beforeDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualDeleteOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualDeleteOptions) {
                 $actualDeleteOptions = $options->getArrayCopy();
             }
         );
@@ -5115,7 +5115,7 @@ class TableTest extends TestCase
         $actualOptions = null;
         $tags->junction()->getEventManager()->on(
             'Model.beforeDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualOptions) {
                 $actualOptions = $options->getArrayCopy();
             }
         );
@@ -5147,7 +5147,7 @@ class TableTest extends TestCase
         $actualOptions = null;
         $articles->getTarget()->getEventManager()->on(
             'Model.beforeDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$actualOptions) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$actualOptions) {
                 $actualOptions = $options->getArrayCopy();
             }
         );
@@ -5932,14 +5932,14 @@ class TableTest extends TestCase
         );
         $eventManager->on(
             'Model.beforeRules',
-            function (EventInterface $event, Entity $entity, ArrayObject $options, $operation) use (&$beforeRulesCount) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options, $operation) use (&$beforeRulesCount) {
                 $this->assertInternalType('string', $operation);
                 $beforeRulesCount ++;
             }
         );
         $eventManager->on(
             'Model.afterRules',
-            function (EventInterface $event, Entity $entity, ArrayObject $options, $result, $operation) use (&$afterRulesCount) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options, $result, $operation) use (&$afterRulesCount) {
                 $this->assertInternalType('bool', $result);
                 $this->assertInternalType('string', $operation);
                 $afterRulesCount ++;
@@ -5947,13 +5947,13 @@ class TableTest extends TestCase
         );
         $eventManager->on(
             'Model.beforeSave',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$beforeSaveCount) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$beforeSaveCount) {
                 $beforeSaveCount ++;
             }
         );
         $eventManager->on(
             'Model.afterSave',
-            $afterSaveCallback = function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$afterSaveCount) {
+            $afterSaveCallback = function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$afterSaveCount) {
                 $afterSaveCount ++;
             }
         );
@@ -5969,13 +5969,13 @@ class TableTest extends TestCase
         $afterDeleteCount = 0;
         $eventManager->on(
             'Model.beforeDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$beforeDeleteCount) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$beforeDeleteCount) {
                 $beforeDeleteCount ++;
             }
         );
         $eventManager->on(
             'Model.afterDelete',
-            function (EventInterface $event, Entity $entity, ArrayObject $options) use (&$afterDeleteCount) {
+            function (EventInterface $event, EntityInterface $entity, ArrayObject $options) use (&$afterDeleteCount) {
                 $afterDeleteCount ++;
             }
         );