Skip to content

Commit

Permalink
Merge pull request #320 from FriendsOfCake/cake-5-updates
Browse files Browse the repository at this point in the history
Cake 5 updates
  • Loading branch information
ADmad authored Jul 17, 2023
2 parents 44ed173 + d98efde commit 71e9d56
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 39 deletions.
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 @@ protected function _getIndexTitleField(): string

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

return $field;
Expand Down Expand Up @@ -154,5 +154,5 @@ abstract protected function _action(?string $name = null): BaseAction;
/**
* @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 beforeRender(EventInterface $event): void
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 @@ protected function _getPageTitle(): string
$displayFieldValue = $this->_displayFieldValue();
if (
$displayFieldValue === null
|| $this->_table()->getDisplayField() === $this->_table()->getPrimaryKey()
|| $this->_model()->getDisplayField() === $this->_model()->getPrimaryKey()
) {
/** @psalm-var string $primaryKeyValue */
return sprintf('%s %s #%s', $actionName, $controllerName, $primaryKeyValue);
Expand Down Expand Up @@ -217,12 +223,12 @@ protected function _getRelatedModels(array $associationTypes = []): array
if (empty($models)) {
$associations = [];
if (empty($associationTypes)) {
$associations = $this->_table()->associations();
$associations = $this->_model()->associations();
} else {
foreach ($associationTypes as $assocType) {
$associations = array_merge(
$associations,
$this->_table()->associations()->getByType($assocType)
$this->_model()->associations()->getByType($assocType)
);
}
}
Expand Down Expand Up @@ -267,7 +273,7 @@ protected function _blacklist(): array
*/
protected function _getPageVariables(): array
{
$table = $this->_table();
$table = $this->_model();
$modelClass = $table->getAlias();
$controller = $this->_controller();
$scope = $this->_action()->getConfig('scope');
Expand Down Expand Up @@ -316,7 +322,7 @@ protected function _scaffoldFields(array $associations = []): array
}

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

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

$associationConfiguration = [];

Expand Down Expand Up @@ -604,7 +610,7 @@ protected function _associations(array $whitelist = []): array
*/
protected function _primaryKeyValue(): array|string
{
$fields = (array)$this->_table()->getPrimaryKey();
$fields = (array)$this->_model()->getPrimaryKey();
$values = [];
foreach ($fields as $field) {
$values[] = $this->_deriveFieldFromContext($field);
Expand All @@ -627,7 +633,7 @@ protected function _primaryKeyValue(): array|string
protected function _displayFieldValue(): string|int|null
{
/** @psalm-suppress PossiblyInvalidArgument */
return $this->_deriveFieldFromContext($this->_table()->getDisplayField());
return $this->_deriveFieldFromContext($this->_model()->getDisplayField());
}

/**
Expand All @@ -640,7 +646,7 @@ protected function _displayFieldValue(): string|int|null
protected function _deriveFieldFromContext(string $field): mixed
{
$controller = $this->_controller();
$modelClass = $this->_table()->getAlias();
$modelClass = $this->_model()->getAlias();
$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 implementedEvents(): array
*/
public function afterPaginate(EventInterface $event): void
{
if (!$this->_table()->behaviors()->has('Search')) {
if (!$this->_model()->behaviors()->has('Search')) {
return;
}

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

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

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

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

0 comments on commit 71e9d56

Please sign in to comment.