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

Cake 5 updates #320

Merged
merged 2 commits into from
Jul 17, 2023
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: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: vimeo/psalm:5, phpstan:1.9, cs2pr
tools: vimeo/psalm:5, phpstan:1.10, cs2pr

- name: Composer Install
run: composer require --dev cakephp/cakephp-codesniffer:^5.0
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor/
composer.lock
tmp
.phpunit.result.cache
.phpunit.cache
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"require-dev": {
"friendsofcake/cakephp-test-utilities": "dev-cake-5.x",
"markstory/asset_compress": "5.x-dev",
"phpunit/phpunit": "^9.5.19"
"phpunit/phpunit": "^10.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ parameters:
- src
universalObjectCratesClasses:
- Crud\Event\Subject
bootstrapFiles:
- vendor/cakephp/cakephp/src/Database/Exception/DatabaseException.php
22 changes: 7 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="./tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="CrudView Tests">
<directory>./tests/TestCase</directory>
</testsuite>
</testsuites>

<extensions>
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension"/>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>

<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>

<php>
<!-- <env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/> -->
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@">
<file src="src/Listener/ViewListener.php">
<UndefinedPropertyAssignment occurrences="1">
<code>$event-&gt;getSubject()-&gt;element</code>
</UndefinedPropertyAssignment>
</file>
<file src="src/Listener/ViewSearchListener.php">
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$input['type']</code>
Expand Down
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
usePhpDocMethodsWithoutMagicCall="true"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
Expand Down
1 change: 1 addition & 0 deletions src/Action/DashboardAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Crud\Action\BaseAction;
use Crud\Traits\ViewTrait;
use CrudView\Dashboard\Dashboard;
use function Cake\I18n\__d;

class DashboardAction extends BaseAction
{
Expand Down
1 change: 1 addition & 0 deletions src/Dashboard/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Datasource\EntityTrait;
use Cake\View\Cell;
use InvalidArgumentException;
use function Cake\I18n\__d;

class Dashboard
{
Expand Down
1 change: 1 addition & 0 deletions src/Listener/Traits/FormTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Controller\Controller;
use Crud\Action\BaseAction;
use Crud\Action\EditAction;
use function Cake\I18n\__d;

trait FormTypeTrait
{
Expand Down
4 changes: 2 additions & 2 deletions src/Listener/Traits/IndexTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

$field = $action->getConfig('scaffold.index_title_field');
if ($field === null) {
$field = $this->_table()->getDisplayField();
$field = $this->_model()->getDisplayField();

Check warning on line 87 in src/Listener/Traits/IndexTypeTrait.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/Traits/IndexTypeTrait.php#L87

Added line #L87 was not covered by tests
}

return $field;
Expand Down Expand Up @@ -154,5 +154,5 @@
/**
* @inheritDoc
*/
abstract protected function _table();
abstract protected function _model();
}
24 changes: 15 additions & 9 deletions src/Listener/ViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
use CrudView\Listener\Traits\SiteTitleTrait;
use CrudView\Listener\Traits\UtilityNavigationTrait;
use CrudView\Traits\CrudViewConfigTrait;
use function Cake\Core\pluginSplit;
use function Cake\I18n\__d;

/**
* @method \Cake\ORM\Table _model()
*/
class ViewListener extends BaseListener
{
use CrudViewConfigTrait;
Expand Down Expand Up @@ -133,6 +138,7 @@
public function setFlash(EventInterface $event): void
{
unset($event->getSubject()->params['class']);
/** @psalm-suppress UndefinedPropertyAssignment */
$event->getSubject()->element = ltrim($event->getSubject()->type);
}

Expand Down Expand Up @@ -172,7 +178,7 @@
$displayFieldValue = $this->_displayFieldValue();
if (
$displayFieldValue === null
|| $this->_table()->getDisplayField() === $this->_table()->getPrimaryKey()
|| $this->_model()->getDisplayField() === $this->_model()->getPrimaryKey()

Check warning on line 181 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L181

Added line #L181 was not covered by tests
) {
/** @psalm-var string $primaryKeyValue */
return sprintf('%s %s #%s', $actionName, $controllerName, $primaryKeyValue);
Expand Down Expand Up @@ -217,12 +223,12 @@
if (empty($models)) {
$associations = [];
if (empty($associationTypes)) {
$associations = $this->_table()->associations();
$associations = $this->_model()->associations();

Check warning on line 226 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L226

Added line #L226 was not covered by tests
} else {
foreach ($associationTypes as $assocType) {
$associations = array_merge(
$associations,
$this->_table()->associations()->getByType($assocType)
$this->_model()->associations()->getByType($assocType)

Check warning on line 231 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L231

Added line #L231 was not covered by tests
);
}
}
Expand Down Expand Up @@ -267,7 +273,7 @@
*/
protected function _getPageVariables(): array
{
$table = $this->_table();
$table = $this->_model();

Check warning on line 276 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L276

Added line #L276 was not covered by tests
$modelClass = $table->getAlias();
$controller = $this->_controller();
$scope = $this->_action()->getConfig('scope');
Expand Down Expand Up @@ -316,7 +322,7 @@
}

if (empty($scaffoldFields) || $action->getConfig('scaffold.autoFields')) {
$cols = $this->_table()->getSchema()->columns();
$cols = $this->_model()->getSchema()->columns();

Check warning on line 325 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L325

Added line #L325 was not covered by tests
$cols = Hash::normalize($cols);

$scope = $action->getConfig('scope');
Expand Down Expand Up @@ -553,7 +559,7 @@
*/
protected function _associations(array $whitelist = []): array
{
$table = $this->_table();
$table = $this->_model();

Check warning on line 562 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L562

Added line #L562 was not covered by tests

$associationConfiguration = [];

Expand Down Expand Up @@ -604,7 +610,7 @@
*/
protected function _primaryKeyValue(): array|string
{
$fields = (array)$this->_table()->getPrimaryKey();
$fields = (array)$this->_model()->getPrimaryKey();

Check warning on line 613 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L613

Added line #L613 was not covered by tests
$values = [];
foreach ($fields as $field) {
$values[] = $this->_deriveFieldFromContext($field);
Expand All @@ -627,7 +633,7 @@
protected function _displayFieldValue(): string|int|null
{
/** @psalm-suppress PossiblyInvalidArgument */
return $this->_deriveFieldFromContext($this->_table()->getDisplayField());
return $this->_deriveFieldFromContext($this->_model()->getDisplayField());

Check warning on line 636 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L636

Added line #L636 was not covered by tests
}

/**
Expand All @@ -640,7 +646,7 @@
protected function _deriveFieldFromContext(string $field): mixed
{
$controller = $this->_controller();
$modelClass = $this->_table()->getAlias();
$modelClass = $this->_model()->getAlias();

Check warning on line 649 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L649

Added line #L649 was not covered by tests
$entity = $this->_entity();
$request = $this->_request();
$value = $entity->get($field);
Expand Down
9 changes: 6 additions & 3 deletions src/Listener/ViewSearchListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Cake\Utility\Hash;
use Crud\Listener\BaseListener;

/**
* @method \Cake\ORM\Table _model()
*/
class ViewSearchListener extends BaseListener
{
/**
Expand Down Expand Up @@ -56,7 +59,7 @@
*/
public function afterPaginate(EventInterface $event): void
{
if (!$this->_table()->behaviors()->has('Search')) {
if (!$this->_model()->behaviors()->has('Search')) {

Check warning on line 62 in src/Listener/ViewSearchListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewSearchListener.php#L62

Added line #L62 was not covered by tests
return;
}

Expand All @@ -82,13 +85,13 @@
$fields = $this->getConfig('fields') ?: [];
$config = $this->getConfig();

$schema = $this->_table()->getSchema();
$schema = $this->_model()->getSchema();

Check warning on line 88 in src/Listener/ViewSearchListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewSearchListener.php#L88

Added line #L88 was not covered by tests
$request = $this->_request();

if ($fields) {
$fields = Hash::normalize($fields);
} else {
$filters = $this->_table()->searchManager()->getFilters($config['collection']);
$filters = $this->_model()->searchManager()->getFilters($config['collection']);

Check warning on line 94 in src/Listener/ViewSearchListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewSearchListener.php#L94

Added line #L94 was not covered by tests

foreach ($filters as $filter) {
$opts = $filter->getConfig('form');
Expand Down
2 changes: 2 additions & 0 deletions src/View/Helper/CrudViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Cake\Utility\Text;
use Cake\View\Helper;
use Cake\View\Helper\FormHelper;
use function Cake\Core\h;
use function Cake\I18n\__d;

/**
* @property \BootstrapUI\View\Helper\FormHelper $Form
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Dashboard/DashboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use CrudView\Dashboard\Dashboard;
use CrudView\View\Cell\DashboardTableCell;
use InvalidArgumentException;
use function Cake\I18n\__d;

/**
* DashboardTest class
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/View/Widget/DateTimeWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testRenderSimple($compareFileName, $data)
*
* @return array
*/
public function renderProvider()
public static function renderProvider()
{
return [
[
Expand Down