From 413d4c4ace0a3772df97a24807252b289c780038 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 16 Apr 2024 18:59:13 +0530 Subject: [PATCH 1/2] Fix tests --- tests/Fixture/ArticlesFixture.php | 4 ++-- .../Model/Behavior/TrashBehaviorTest.php | 18 ++++++++---------- tests/bootstrap.php | 3 --- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/tests/Fixture/ArticlesFixture.php b/tests/Fixture/ArticlesFixture.php index 674e9a4..7e47dc4 100644 --- a/tests/Fixture/ArticlesFixture.php +++ b/tests/Fixture/ArticlesFixture.php @@ -1,7 +1,7 @@ records, function (&$record) use ($created, $modified) { $record += compact('created', 'modified'); }); diff --git a/tests/TestCase/Model/Behavior/TrashBehaviorTest.php b/tests/TestCase/Model/Behavior/TrashBehaviorTest.php index ed4c28b..cd02d98 100644 --- a/tests/TestCase/Model/Behavior/TrashBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/TrashBehaviorTest.php @@ -12,19 +12,11 @@ use Cake\I18n\DateTime; use Cake\ORM\Association\HasMany; use Cake\ORM\Entity; +use Cake\ORM\Table; use Cake\TestSuite\TestCase; use InvalidArgumentException; use Muffin\Trash\Model\Behavior\TrashBehavior; -/** - * @property \Cake\ORM\Table Users - * @property \Cake\ORM\Table CompositeArticlesUsers - * @property \Cake\ORM\Table Comments - * @property \Cake\ORM\Table Articles - * @property \Muffin\Trash\Model\Behavior\TrashBehavior Behavior - * - * @property \Cake\ORM\Table @mixin \Muffin\Trash\Model\Behavior\TrashBehavior - */ class TrashBehaviorTest extends TestCase { /** @@ -32,7 +24,7 @@ class TrashBehaviorTest extends TestCase * * @var array */ - public array $fixtures = [ + protected array $fixtures = [ 'plugin.Muffin/Trash.Articles', 'plugin.Muffin/Trash.Comments', 'plugin.Muffin/Trash.Users', @@ -40,6 +32,12 @@ class TrashBehaviorTest extends TestCase 'plugin.Muffin/Trash.CompositeArticlesUsers', ]; + protected Table $Users; + protected Table $CompositeArticlesUsers; + protected Table $Comments; + protected Table $Articles; + protected TrashBehavior $Behavior; + /** * Runs before each test. * diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5b073d5..ca891ba 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -32,6 +32,3 @@ require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php'; -Configure::write('Error.ignoredDeprecationPaths', [ - 'src/TestSuite/Fixture/FixtureInjector.php', -]); From 5b09bc61859606f4f79e17019a085bf1aaf99a2b Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 16 Apr 2024 19:10:58 +0530 Subject: [PATCH 2/2] Fix psalm errors --- psalm.xml | 2 ++ src/Model/Behavior/TrashBehavior.php | 5 +++-- tests/bootstrap.php | 3 --- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/psalm.xml b/psalm.xml index a09944e..b192091 100644 --- a/psalm.xml +++ b/psalm.xml @@ -4,6 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" + findUnusedBaselineEntry="true" + findUnusedCode="false" > diff --git a/src/Model/Behavior/TrashBehavior.php b/src/Model/Behavior/TrashBehavior.php index ce878b1..94402c3 100644 --- a/src/Model/Behavior/TrashBehavior.php +++ b/src/Model/Behavior/TrashBehavior.php @@ -295,12 +295,13 @@ public function cascadingRestoreTrash( foreach ($this->_table->associations() as $association) { if ($this->_isRecursable($association, $this->_table)) { if ($entity === null) { - if ($result) { + if ($result > 1) { $result += $association->getTarget()->cascadingRestoreTrash(null, $options); } } else { - /** @var array $foreignKey */ + /** @var list $foreignKey */ $foreignKey = (array)$association->getForeignKey(); + /** @var list $bindingKey */ $bindingKey = (array)$association->getBindingKey(); $conditions = array_combine($foreignKey, $entity->extract($bindingKey)); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ca891ba..eae831c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,8 +1,6 @@