Skip to content
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"cakephp/plugin-installer": "^1.3",
"league/flysystem-memory": "^3.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/phpstan": "^2.2",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpunit/phpunit": "^11.1",
"vimeo/psalm": "^6.8"
},
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ parameters:
- src
- tests
level: 8
ignoreErrors:
-
# Outdated `@method` annotation on BEdita\Core\Model\Table\MediaTable
message: '#^Unknown parameter \$contain in call to method BEdita\\Core\\Model\\Table\\MediaTable::get\(\)\.$#'
identifier: argument.unknown
path: tests
8 changes: 4 additions & 4 deletions src/Event/JsonSchemaEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public function implementedEvents(): array
* @param \Cake\Event\Event<\BEdita\Core\Model\Table\ObjectTypesTable> $event Dispatched event.
* @param array<string, mixed> $schema Automatically generated JSON schema.
* @param \BEdita\Core\Model\Entity\ObjectType $objectType Object type.
* @return array<string, mixed>
* @return void
*/
public function onGetSchema(Event $event, array $schema, ObjectType $objectType): array
public function onGetSchema(Event $event, array $schema, ObjectType $objectType): void
{
$table = $this->getTableLocator()->get($objectType->table);
if (!$table->hasBehavior('Placeholders')) {
return $schema;
return;
}

$behavior = $table->getBehavior('Placeholders');
Expand All @@ -76,6 +76,6 @@ public function onGetSchema(Event $event, array $schema, ObjectType $objectType)
$schema['relations'][$relName]['readonly'] = true;
}

return $schema;
$event->setResult($schema);
}
}
4 changes: 2 additions & 2 deletions src/Plugin.php → src/PlaceholdersPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
/**
* Plugin for BEdita\Placeholders
*/
class Plugin extends BasePlugin
class PlaceholdersPlugin extends BasePlugin
{
/**
* {@inheritDoc}
*
* @param \Cake\Core\PluginApplicationInterface<\Cake\Core\ContainerInterface> $app
* @param \Cake\Core\PluginApplicationInterface $app
* @codeCoverageIgnore
*/
public function bootstrap(PluginApplicationInterface $app): void
Expand Down
2 changes: 0 additions & 2 deletions tests/TestApp/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*
* This defines the bootstrapping logic and middleware layers you
* want to use in your application.
*
* @extends \Cake\Http\BaseApplication<\BEdita\Placeholders\Test\TestApp\Application>
*/
class Application extends BaseApplication
{
Expand Down
10 changes: 0 additions & 10 deletions tests/TestCase/Controller/Component/PlaceholdersComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ public function setUp(): void
$this->controller->loadComponent(PlaceholdersComponent::class);
}

/**
* @inheritDoc
*/
public function tearDown(): void
{
unset($this->controller);

parent::tearDown();
}

/**
* Data provider for {@see PlaceholdersComponentTest::testBeforeFilter()} test case.
*
Expand Down
16 changes: 8 additions & 8 deletions tests/TestCase/Model/Behavior/PlaceholdedBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ class PlaceholdedBehaviorTest extends TestCase
/**
* ObjectsTable instance
*
* @var \BEdita\Core\Model\Table\ObjectsTable|null
* @var \BEdita\Core\Model\Table\ObjectsTable
*/
protected ?ObjectsTable $Documents = null;
protected ObjectsTable $Documents;

/**
* MediaTable instance
*
* @var \BEdita\Core\Model\Table\MediaTable|null
* @var \BEdita\Core\Model\Table\MediaTable
*/
protected ?MediaTable $Media = null;
protected MediaTable $Media;

/**
* @inheritDoc
Expand Down Expand Up @@ -107,17 +107,17 @@ public function testBeforeSaveLockedEntity(): void
$body = '<!-- BE-PLACEHOLDER.10 --><h1>My sweet placeholder</h1>';

// Save with placeholder in body.
$document = $this->Documents->get(2, ['contain' => ['ObjectTypes']]);
$document = $this->Documents->get(2, contain: ['ObjectTypes']);
$document->body = $body;
$this->Documents->saveOrFail($document);

$document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]);
$document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']);
static::assertSame([10], Hash::extract($document->get('placeholder'), '{n}.id'));

// Try to delete media.
$this->expectException(LockedResourceException::class);
$this->expectExceptionMessage('Cannot delete object 10 because it is still placeholded in one object');
$media = $this->Media->get(10, ['contain' => ['ObjectTypes']]);
$media = $this->Media->get(10, contain: ['ObjectTypes']);
$media->deleted = true;
$this->Media->saveOrFail($media);
}
Expand All @@ -129,7 +129,7 @@ public function testBeforeSaveLockedEntity(): void
*/
public function testBeforeSaveFreeEntity(): void
{
$media = $this->Media->get(10, ['contain' => ['ObjectTypes']]);
$media = $this->Media->get(10, contain: ['ObjectTypes']);
$media->deleted = true;
$actual = $this->Media->saveOrFail($media);

Expand Down
30 changes: 15 additions & 15 deletions tests/TestCase/Model/Behavior/PlaceholdersBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ class PlaceholdersBehaviorTest extends TestCase
/**
* ObjectsTable instance
*
* @var \BEdita\Core\Model\Table\ObjectsTable|null
* @var \BEdita\Core\Model\Table\ObjectsTable
*/
protected ?ObjectsTable $Documents = null;
protected ObjectsTable $Documents;

/**
* MediaTable instance
*
* @var \BEdita\Core\Model\Table\MediaTable|null
* @var \BEdita\Core\Model\Table\MediaTable
*/
protected ?MediaTable $Media = null;
protected MediaTable $Media;

/**
* @inheritDoc
Expand Down Expand Up @@ -293,7 +293,7 @@ public function testSavePlaceholders(): void
$this->Documents->saveOrFail($document);

// Reload entity from database, with placeholders.
$document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]);
$document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']);
static::assertSame($body, $document->body, 'Entity body has been changed');
static::assertTrue($document->has('placeholder'));

Expand Down Expand Up @@ -337,21 +337,21 @@ public function testSavePlaceholdersReplace(): void
// Save hypothetical previous data.
$action = new AddRelatedObjectsAction(['association' => $this->Documents->getAssociation('Placeholder')]);
$action([
'entity' => $this->Documents->get(2, ['contain' => ['ObjectTypes']]),
'entity' => $this->Documents->get(2, contain: ['ObjectTypes']),
'relatedEntities' => [
$this->Media->get(10, ['contain' => ['ObjectTypes']])->set(['_joinData' => ['params' => ['description' => []]]]),
$this->Media->get(14, ['contain' => ['ObjectTypes']]),
$this->Media->get(10, contain: ['ObjectTypes'])->patch(['_joinData' => ['params' => ['description' => []]]]),
$this->Media->get(14, contain: ['ObjectTypes']),
],
]);

// Save with placeholder in body.
$document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]);
$document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']);
static::assertSame([10, 14], Hash::extract($document->get('placeholder'), '{n}.id')); // Check that previous placeholders exist.
$document->body = $body;
$this->Documents->saveOrFail($document);

// Reload entity from database, with placeholders.
$document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]);
$document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']);
static::assertSame($body, $document->body, 'Entity body has been changed');
static::assertTrue($document->has('placeholder'));

Expand Down Expand Up @@ -379,21 +379,21 @@ public function testSavePlaceholdersRemove(): void
// Save hypothetical previous data.
$action = new AddRelatedObjectsAction(['association' => $this->Documents->getAssociation('Placeholder')]);
$action([
'entity' => $this->Documents->get(2, ['contain' => ['ObjectTypes']]),
'entity' => $this->Documents->get(2, contain: ['ObjectTypes']),
'relatedEntities' => [
$this->Media->get(10, ['contain' => ['ObjectTypes']])->set(['_joinData' => ['params' => ['description' => []]]]),
$this->Media->get(14, ['contain' => ['ObjectTypes']]),
$this->Media->get(10, contain: ['ObjectTypes'])->patch(['_joinData' => ['params' => ['description' => []]]]),
$this->Media->get(14, contain: ['ObjectTypes']),
],
]);

// Save with placeholder in body.
$document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]);
$document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']);
static::assertSame([10, 14], Hash::extract($document->get('placeholder'), '{n}.id')); // Check that previous placeholders exist.
$document->body = $body;
$this->Documents->saveOrFail($document);

// Reload entity from database, with placeholders.
$document = $this->Documents->get(2, ['contain' => ['ObjectTypes', 'Placeholder']]);
$document = $this->Documents->get(2, contain: ['ObjectTypes', 'Placeholder']);
static::assertSame($body, $document->body, 'Entity body has been changed');
static::assertTrue($document->has('placeholder'));

Expand Down
Loading