From 2543bd2b67af93a9e37526787d5c891600bab4cd Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 11 Jul 2022 19:00:36 +0530 Subject: [PATCH] Update for Cake 5 --- .github/workflows/ci.yml | 54 +++++++++---------- composer.json | 13 +++-- phpunit.xml.dist | 32 +++++------ src/Model/Behavior/SequenceBehavior.php | 12 ++--- tests/Fixture/GroupedItemsFixture.php | 20 +------ tests/Fixture/ItemsFixture.php | 19 +------ tests/Fixture/KeywordItemsFixture.php | 19 +------ tests/Fixture/UniqueItemsFixture.php | 22 +------- .../Model/Behavior/SequenceBehaviorTest.php | 5 +- tests/bootstrap.php | 5 -- tests/schema.php | 45 ++++++++++++++++ tests/test_app/src/Model/Entity/Item.php | 4 +- tests/test_app/src/Model/Table/ItemsTable.php | 2 +- 13 files changed, 108 insertions(+), 144 deletions(-) create mode 100644 tests/schema.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7db0cd..2b73a91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,17 +10,20 @@ on: jobs: testsuite: - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - php-version: ['7.4', '8.0', '8.1'] + php-version: ['8.1'] db-type: [mysql, pgsql] - prefer-lowest: [''] + dependencies: ['highest'] include: - - php-version: '7.2' + - php-version: '8.1' db-type: 'sqlite' - prefer-lowest: 'prefer-lowest' + dependencies: 'lowest' + - php-version: '8.2' + db-type: 'mysql' + composer-options: '--ignore-platform-req=php' services: postgres: @@ -31,7 +34,7 @@ jobs: POSTGRES_PASSWORD: postgres steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Service if: matrix.db-type == 'mysql' @@ -47,55 +50,52 @@ jobs: coverage: pcov - name: Composer install - run: | - composer --version - if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then - composer update --prefer-lowest --prefer-stable - else - composer install - fi + uses: ramsey/composer-install@v2 + with: + dependency-versions: ${{ matrix.dependencies }} + composer-options: ${{ matrix.composer-options }} - name: Run PHPUnit run: | if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi - if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'; fi + if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp'; fi if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi - if [[ ${{ matrix.php-version }} == '7.4' && ${{ matrix.db-type }} == 'mysql' ]]; then - vendor/bin/phpunit --coverage-clover=coverage.xml + if [[ ${{ matrix.php-version }} == '8.1' && ${{ matrix.db-type }} == 'mysql' ]]; then + vendor/bin/phpunit --coverage-clover=coverage.xml --verbose else vendor/bin/phpunit fi - name: Code Coverage Report - if: success() && matrix.php-version == '7.4' && matrix.db-type == 'mysql' - uses: codecov/codecov-action@v2 + if: success() && matrix.php-version == '8.1' && matrix.db-type == 'mysql' + uses: codecov/codecov-action@v3 cs-stan: name: Coding Standard & Static Analysis - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.1' extensions: mbstring, intl coverage: none - tools: psalm:4.4, phpstan:1.0 + tools: vimeo/psalm:4, phpstan:1, cs2pr - name: Composer Install - run: composer require cakephp/cakephp-codesniffer:^4.2 + run: composer require cakephp/cakephp-codesniffer:5.x-dev - name: Run phpcs - run: vendor/bin/phpcs --standard=CakePHP src/ tests/ + run: vendor/bin/phpcs --report=checkstyle --standard=CakePHP src/ tests/ | cs2pr - name: Run psalm - if: success() || failure() + if: always() run: psalm --output-format=github - name: Run phpstan - if: success() || failure() - run: phpstan + if: always() + run: phpstan analyse diff --git a/composer.json b/composer.json index 64c0569..db1d7c7 100644 --- a/composer.json +++ b/composer.json @@ -5,11 +5,11 @@ "type": "cakephp-plugin", "license": "MIT", "require": { - "cakephp/orm": "^4.0" + "cakephp/orm": "5.x-dev" }, "require-dev": { - "cakephp/cakephp": "^4.0", - "phpunit/phpunit": "~8.5.0" + "cakephp/cakephp": "5.x-dev", + "phpunit/phpunit": "^9.5.19" }, "autoload": { "psr-4": { @@ -22,5 +22,12 @@ "Cake\\Test\\": "./vendor/cakephp/cakephp/tests", "TestApp\\": "tests/test_app/src" } + }, + "config": { + "process-timeout": 900, + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a66b296..08068a6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,32 +5,24 @@ stopOnFailure="false" bootstrap="./tests/bootstrap.php" > - - - - ./tests/TestCase - - - - - - - - - + + + + + + + src/ + + - - - ./src/ - - + + + diff --git a/src/Model/Behavior/SequenceBehavior.php b/src/Model/Behavior/SequenceBehavior.php index 1532c41..dca0350 100644 --- a/src/Model/Behavior/SequenceBehavior.php +++ b/src/Model/Behavior/SequenceBehavior.php @@ -67,7 +67,7 @@ class SequenceBehavior extends Behavior * * @var array */ - protected $_defaultConfig = [ + protected array $_defaultConfig = [ 'sequenceField' => 'position', 'scope' => [], 'startAt' => 1, @@ -78,7 +78,7 @@ class SequenceBehavior extends Behavior * * @var array|null */ - protected $_oldValues; + protected ?array $_oldValues = null; /** * Normalize config options. @@ -276,7 +276,7 @@ public function afterDelete(EventInterface $event, EntityInterface $entity) * @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved. * @return bool */ - public function moveUp(EntityInterface $entity) + public function moveUp(EntityInterface $entity): bool { return $this->_movePosition($entity, '-'); } @@ -289,7 +289,7 @@ public function moveUp(EntityInterface $entity) * @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved. * @return bool */ - public function moveDown(EntityInterface $entity) + public function moveDown(EntityInterface $entity): bool { return $this->_movePosition($entity, '+'); } @@ -471,7 +471,7 @@ protected function _getOldValues(EntityInterface $entity): array * @param \Cake\Datasource\EntityInterface $entity Entity. * @return array|false */ - protected function _getScope(EntityInterface $entity) + protected function _getScope(EntityInterface $entity): array|false { $scope = []; $config = $this->getConfig(); @@ -504,7 +504,7 @@ protected function _getScope(EntityInterface $entity) * @param array $scope Array with scope field => scope values, used for conditions. * @return int Value of order field of last record in set */ - protected function _getHighestOrder(array $scope = []): int + protected function _getHighestOrder(array $scope): int { $orderField = $this->_config['sequenceField']; diff --git a/tests/Fixture/GroupedItemsFixture.php b/tests/Fixture/GroupedItemsFixture.php index 0dbf548..a514a4f 100644 --- a/tests/Fixture/GroupedItemsFixture.php +++ b/tests/Fixture/GroupedItemsFixture.php @@ -5,25 +5,7 @@ class GroupedItemsFixture extends TestFixture { - /** - * fields property. - * - * @var array - */ - public $fields = [ - 'id' => ['type' => 'integer'], - 'name' => ['type' => 'string', 'null' => true], - 'group_field' => ['type' => 'integer', 'null' => true], - 'position' => ['type' => 'integer', 'null' => true], - '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], - ]; - - /** - * records property. - * - * @var array - */ - public $records = [ + public array $records = [ ['name' => 'Group 1 Item A', 'group_field' => 1, 'position' => 0], ['name' => 'Group 1 Item B', 'group_field' => 1, 'position' => 1], ['name' => 'Group 1 Item C', 'group_field' => 1, 'position' => 2], diff --git a/tests/Fixture/ItemsFixture.php b/tests/Fixture/ItemsFixture.php index ac9c134..9ebc69c 100644 --- a/tests/Fixture/ItemsFixture.php +++ b/tests/Fixture/ItemsFixture.php @@ -5,24 +5,7 @@ class ItemsFixture extends TestFixture { - /** - * fields property. - * - * @var array - */ - public $fields = [ - 'id' => ['type' => 'integer'], - 'name' => ['type' => 'string', 'null' => true], - 'position' => ['type' => 'integer', 'null' => true], - '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], - ]; - - /** - * records property. - * - * @var array - */ - public $records = [ + public array $records = [ ['name' => 'Item A', 'position' => 0], ['name' => 'Item B', 'position' => 1], ['name' => 'Item C', 'position' => 2], diff --git a/tests/Fixture/KeywordItemsFixture.php b/tests/Fixture/KeywordItemsFixture.php index 65c16d4..13e82c3 100644 --- a/tests/Fixture/KeywordItemsFixture.php +++ b/tests/Fixture/KeywordItemsFixture.php @@ -5,24 +5,7 @@ class KeywordItemsFixture extends TestFixture { - /** - * fields property. - * - * @var array - */ - public $fields = [ - 'id' => ['type' => 'integer'], - 'name' => ['type' => 'string', 'null' => true], - 'order' => ['type' => 'integer', 'null' => true], - '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], - ]; - - /** - * records property. - * - * @var array - */ - public $records = [ + public array $records = [ ['name' => 'Item A', 'order' => 0], ['name' => 'Item B', 'order' => 1], ['name' => 'Item C', 'order' => 2], diff --git a/tests/Fixture/UniqueItemsFixture.php b/tests/Fixture/UniqueItemsFixture.php index 4f25ba8..99c5cbb 100644 --- a/tests/Fixture/UniqueItemsFixture.php +++ b/tests/Fixture/UniqueItemsFixture.php @@ -5,27 +5,7 @@ class UniqueItemsFixture extends TestFixture { - /** - * fields property. - * - * @var array - */ - public $fields = [ - 'id' => ['type' => 'integer'], - 'name' => ['type' => 'string', 'null' => true], - 'position' => ['type' => 'integer', 'null' => true], - '_constraints' => [ - 'primary' => ['type' => 'primary', 'columns' => ['id']], - 'position' => ['type' => 'unique', 'columns' => ['position']], - ], - ]; - - /** - * records property. - * - * @var array - */ - public $records = [ + public array $records = [ ['name' => 'Item A', 'position' => 0], ['name' => 'Item B', 'position' => 1], ['name' => 'Item C', 'position' => 2], diff --git a/tests/TestCase/Model/Behavior/SequenceBehaviorTest.php b/tests/TestCase/Model/Behavior/SequenceBehaviorTest.php index 3d49f8e..39ebf42 100644 --- a/tests/TestCase/Model/Behavior/SequenceBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/SequenceBehaviorTest.php @@ -4,7 +4,6 @@ namespace ADmad\Sequence\Test\TestCase\Model\Behavior; use Cake\ORM\Entity; -use Cake\ORM\Locator\LocatorAwareTrait; use Cake\TestSuite\TestCase; use TestApp\Model\Table\GroupedItemsTable; use TestApp\Model\Table\ItemsTable; @@ -13,9 +12,7 @@ class SequenceBehaviorTest extends TestCase { - use LocatorAwareTrait; - - public $fixtures = [ + protected array $fixtures = [ 'plugin.ADmad/Sequence.Items', 'plugin.ADmad/Sequence.GroupedItems', 'plugin.ADmad/Sequence.KeywordItems', diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 77078cc..76c2ba1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,7 +5,6 @@ * Test suite bootstrap for Sequence */ -use Cake\Core\Configure; use Cake\Datasource\ConnectionManager; /* @@ -37,7 +36,3 @@ require dirname(__DIR__) . '/vendor/cakephp/cakephp/tests/bootstrap.php'; ConnectionManager::get('test')->getDriver()->enableAutoQuoting(true); - -Configure::write('Error.ignoredDeprecationPaths', [ - 'src/TestSuite/Fixture/FixtureInjector.php', -]); diff --git a/tests/schema.php b/tests/schema.php new file mode 100644 index 0000000..0d08d4f --- /dev/null +++ b/tests/schema.php @@ -0,0 +1,45 @@ + 'grouped_items', + 'columns' => [ + 'id' => ['type' => 'integer'], + 'name' => ['type' => 'string', 'null' => true], + 'group_field' => ['type' => 'integer', 'null' => true], + 'position' => ['type' => 'integer', 'null' => true], + ], + 'constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], + ], + [ + 'table' => 'items', + 'columns' => [ + 'id' => ['type' => 'integer'], + 'name' => ['type' => 'string', 'null' => true], + 'position' => ['type' => 'integer', 'null' => true], + ], + 'constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], + ], + [ + 'table' => 'keyword_items', + 'columns' => [ + 'id' => ['type' => 'integer'], + 'name' => ['type' => 'string', 'null' => true], + 'order' => ['type' => 'integer', 'null' => true], + ], + 'constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], + ], + [ + 'table' => 'unique_items', + 'columns' => [ + 'id' => ['type' => 'integer'], + 'name' => ['type' => 'string', 'null' => true], + 'position' => ['type' => 'integer', 'null' => true], + ], + 'constraints' => [ + 'primary' => ['type' => 'primary', 'columns' => ['id']], + 'position' => ['type' => 'unique', 'columns' => ['position']], + ], + ], +]; diff --git a/tests/test_app/src/Model/Entity/Item.php b/tests/test_app/src/Model/Entity/Item.php index 06e20b8..ef026ad 100644 --- a/tests/test_app/src/Model/Entity/Item.php +++ b/tests/test_app/src/Model/Entity/Item.php @@ -7,7 +7,7 @@ class Item extends Entity { - protected $_accessible = ['*' => true, 'id' => false]; + protected array $_accessible = ['*' => true, 'id' => false]; - protected $_virtual = ['virutal_name']; + protected array $_virtual = ['virutal_name']; } diff --git a/tests/test_app/src/Model/Table/ItemsTable.php b/tests/test_app/src/Model/Table/ItemsTable.php index 6249271..bfd53cc 100644 --- a/tests/test_app/src/Model/Table/ItemsTable.php +++ b/tests/test_app/src/Model/Table/ItemsTable.php @@ -8,7 +8,7 @@ class ItemsTable extends Table { - protected $_entityClass = Item::class; + protected ?string $_entityClass = Item::class; public function initialize(array $config): void {