diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 92d2051..4b7235d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -24,12 +24,17 @@ jobs: cs: uses: bedita/github-workflows/.github/workflows/php-cs.yml@v2 with: - php_versions: '["8.4"]' + php_versions: '["8.5"]' + + psalm: + uses: bedita/github-workflows/.github/workflows/php-psalm.yml@v2 + with: + php_versions: '["8.5"]' stan: uses: bedita/github-workflows/.github/workflows/php-stan.yml@v2 with: - php_versions: '["8.4"]' + php_versions: '["8.5"]' unit: name: 'Run unit tests' @@ -38,7 +43,7 @@ jobs: strategy: matrix: - php-version: [8.3, 8.4] + php-version: [8.3, 8.4, 8.5] steps: - name: 'Checkout current revision' diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 0346e0e..a248711 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -14,7 +14,7 @@ build: analysis: environment: php: - version: 8.3.3 + version: 8.3.16 tests: override: - php-scrutinizer-run diff --git a/README.md b/README.md index 7178675..d49ea4a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Github Actions](https://github.com/bedita/import-tools/workflows/php/badge.svg)](https://github.com/bedita/import-tools/actions?query=workflow%3Aphp) [![codecov](https://codecov.io/gh/bedita/import-tools/branch/main/graph/badge.svg)](https://codecov.io/gh/bedita/import-tools) [![phpstan](https://img.shields.io/badge/PHPStan-level%205-brightgreen.svg)](https://phpstan.org) +[![psalm](https://img.shields.io/badge/psalm-level%208-brightgreen.svg)](https://psalm.dev) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bedita/import-tools/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/bedita/import-tools/?branch=main) [![image](https://img.shields.io/packagist/v/bedita/import-tools.svg?label=stable)](https://packagist.org/packages/bedita/import-tools) [![image](https://img.shields.io/github/license/bedita/import-tools.svg)](https://github.com/bedita/import-tools/blob/main/LICENSE.LGPL) diff --git a/composer.json b/composer.json index c1354cc..ee03947 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^1.12", "phpstan/phpstan-deprecation-rules": "^1.2", - "phpunit/phpunit": "^11.1.3" + "phpunit/phpunit": "^11.1.3", + "vimeo/psalm": "^6.8" }, "autoload": { "psr-4": { @@ -53,8 +54,10 @@ ], "cs-check": "vendor/bin/phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", "cs-fix": "vendor/bin/phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", + "psalm": "vendor/bin/psalm", + "stan": "vendor/bin/phpstan analyse", "test": "vendor/bin/phpunit --colors=always", - "stan": "vendor/bin/phpstan analyse" + "coverage": "vendor/bin/phpunit --colors=always --coverage-html coverage" }, "prefer-stable": true, "config": { diff --git a/psalm.xml.dist b/psalm.xml.dist new file mode 100644 index 0000000..47e667f --- /dev/null +++ b/psalm.xml.dist @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/src/Command/AnonymizeUsersCommand.php b/src/Command/AnonymizeUsersCommand.php index be3f00a..8cc0b83 100644 --- a/src/Command/AnonymizeUsersCommand.php +++ b/src/Command/AnonymizeUsersCommand.php @@ -180,7 +180,7 @@ protected function objectsGenerator(Query $query, Table $table, int $limit = 100 break; } foreach ($results as $entity) { - $lastId = $entity->id; + $lastId = $entity->get('id'); yield $entity; } diff --git a/src/Command/TranslateObjectsCommand.php b/src/Command/TranslateObjectsCommand.php index 459de7c..c8f7861 100644 --- a/src/Command/TranslateObjectsCommand.php +++ b/src/Command/TranslateObjectsCommand.php @@ -308,7 +308,9 @@ public function objectsIterator(array $conditions, string $lang, string $to): it /** @var \BEdita\Core\Model\Table\ObjectsTable $table */ $table = $this->fetchTable('objects'); if ($this->type !== null) { - $conditions[$table->aliasField('object_type_id')] = $table->objectType($this->type)->id; + /** @var \BEdita\Core\Model\Behavior\ObjectTypeBehavior $objectTypeBehavior */ + $objectTypeBehavior = $table->getBehavior('ObjectType'); + $conditions[$table->aliasField('object_type_id')] = $objectTypeBehavior->objectType($this->type)->id; } $conditions = array_merge( $conditions, @@ -334,7 +336,7 @@ public function objectsIterator(array $conditions, string $lang, string $to): it } foreach ($results as $entity) { - $lastId = $entity->id; + $lastId = $entity->get('id'); yield $entity; } diff --git a/src/Utility/Import.php b/src/Utility/Import.php index 5611340..d09d342 100644 --- a/src/Utility/Import.php +++ b/src/Utility/Import.php @@ -320,7 +320,7 @@ public function saveObject(array $obj): ObjectEntity ), ); } - $entity = $o->getTable()->find('type', [$this->type])->where($conditions)->firstOrFail(); + $entity = $o->getTable()->find('type', value: [$this->type])->where($conditions)->firstOrFail(); } } /** @var \BEdita\Core\Model\Entity\ObjectEntity $entity */ diff --git a/tests/TestCase/Command/ImportCommandTest.php b/tests/TestCase/Command/ImportCommandTest.php index bafa13d..5217b3a 100644 --- a/tests/TestCase/Command/ImportCommandTest.php +++ b/tests/TestCase/Command/ImportCommandTest.php @@ -80,11 +80,11 @@ public function testBuildOptionParser(): void $this->assertOutputContains('--parent, -p'); $this->assertOutputContains('destination folder uname'); $this->assertOutputContains('--quiet, -q'); - $this->assertOutputContains('Enable quiet output.'); + $this->assertOutputContains('Enable quiet output'); $this->assertOutputContains('--type, -t'); $this->assertOutputContains('entity type to import (required)'); $this->assertOutputContains('--verbose, -v'); - $this->assertOutputContains('Enable verbose output.'); + $this->assertOutputContains('Enable verbose output'); } /** diff --git a/tests/TestCase/Command/TranslateObjectsCommandTest.php b/tests/TestCase/Command/TranslateObjectsCommandTest.php index 8610642..ab90b6e 100644 --- a/tests/TestCase/Command/TranslateObjectsCommandTest.php +++ b/tests/TestCase/Command/TranslateObjectsCommandTest.php @@ -268,7 +268,19 @@ public function translate(ObjectEntity $object, string $from, string $to): void */ public function testObjectsIterator(): void { - $this->markTestIncomplete('Not implemented yet.'); + $cmd = new class () extends TranslateObjectsCommand { + public function __construct() + { + parent::__construct(); + $this->type = 'users'; + } + }; + $catch = false; + $conditions = []; + foreach ($cmd->objectsIterator($conditions, 'en', 'it') as $object) { + $catch = true; + } + static::assertFalse($catch, 'objectsIterator find no users'); } /** diff --git a/tests/TestCase/Utility/CsvTraitTest.php b/tests/TestCase/Utility/CsvTraitTest.php index 4ce6e00..fc13f42 100644 --- a/tests/TestCase/Utility/CsvTraitTest.php +++ b/tests/TestCase/Utility/CsvTraitTest.php @@ -15,17 +15,17 @@ namespace BEdita\ImportTools\Test\TestCase\Utility; use BEdita\ImportTools\Utility\CsvTrait; -use BEdita\ImportTools\Utility\XmlTrait; +use BEdita\ImportTools\Utility\FileTrait; use Cake\TestSuite\TestCase; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\Attributes\CoversTrait; +use PHPUnit\Framework\Attributes\UsesTrait; use RuntimeException; /** * {@see \BEdita\ImportTools\Utility\CsvTrait} Test Case */ -#[CoversClass(CsvTrait::class)] -#[UsesClass(XmlTrait::class)] +#[CoversTrait(CsvTrait::class)] +#[UsesTrait(FileTrait::class)] class CsvTraitTest extends TestCase { use CsvTrait; diff --git a/tests/TestCase/Utility/ReadTraitTest.php b/tests/TestCase/Utility/ReadTraitTest.php index 0627475..b6a14f1 100644 --- a/tests/TestCase/Utility/ReadTraitTest.php +++ b/tests/TestCase/Utility/ReadTraitTest.php @@ -14,19 +14,23 @@ */ namespace BEdita\ImportTools\Test\TestCase\Utility; +use BEdita\ImportTools\Utility\CsvTrait; +use BEdita\ImportTools\Utility\FileTrait; use BEdita\ImportTools\Utility\ReadTrait; use BEdita\ImportTools\Utility\XmlTrait; use Cake\TestSuite\TestCase; use InvalidArgumentException; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\Attributes\CoversTrait; +use PHPUnit\Framework\Attributes\UsesTrait; use RuntimeException; /** * {@see \BEdita\ImportTools\Utility\ReadTrait} Test Case */ -#[CoversClass(ReadTrait::class)] -#[UsesClass(XmlTrait::class)] +#[CoversTrait(ReadTrait::class)] +#[UsesTrait(CsvTrait::class)] +#[UsesTrait(XmlTrait::class)] +#[UsesTrait(FileTrait::class)] class ReadTraitTest extends TestCase { use ReadTrait;