Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #66

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<projectFiles>
<directory name="src" />
Expand Down
5 changes: 3 additions & 2 deletions src/Model/Behavior/TrashBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<array-key,array-key> $foreignKey */
/** @var list<string> $foreignKey */
$foreignKey = (array)$association->getForeignKey();
/** @var list<string> $bindingKey */
$bindingKey = (array)$association->getBindingKey();
$conditions = array_combine($foreignKey, $entity->extract($bindingKey));

Expand Down
4 changes: 2 additions & 2 deletions tests/Fixture/ArticlesFixture.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Muffin\Trash\Test\Fixture;

use Cake\I18n\Time;
use Cake\I18n\DateTime;
use Cake\TestSuite\Fixture\TestFixture;

class ArticlesFixture extends TestFixture
Expand All @@ -21,7 +21,7 @@ class ArticlesFixture extends TestFixture

public function init(): void
{
$created = $modified = new Time();
$created = $modified = new DateTime();
array_walk($this->records, function (&$record) use ($created, $modified) {
$record += compact('created', 'modified');
});
Expand Down
18 changes: 8 additions & 10 deletions tests/TestCase/Model/Behavior/TrashBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,32 @@
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
{
/**
* Fixtures to load.
*
* @var array
*/
public array $fixtures = [
protected array $fixtures = [
'plugin.Muffin/Trash.Articles',
'plugin.Muffin/Trash.Comments',
'plugin.Muffin/Trash.Users',
'plugin.Muffin/Trash.ArticlesUsers',
'plugin.Muffin/Trash.CompositeArticlesUsers',
];

protected Table $Users;
protected Table $CompositeArticlesUsers;
protected Table $Comments;
protected Table $Articles;
protected TrashBehavior $Behavior;

/**
* Runs before each test.
*
Expand Down
6 changes: 0 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
declare(strict_types=1);

use Cake\Core\Configure;

/**
* Test suite bootstrap.
*
Expand Down Expand Up @@ -31,7 +29,3 @@
}

require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';

Configure::write('Error.ignoredDeprecationPaths', [
'src/TestSuite/Fixture/FixtureInjector.php',
]);
Loading