Skip to content

Commit

Permalink
Update for Cake 5
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jul 11, 2022
1 parent 04e2dd2 commit 2543bd2
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 144 deletions.
54 changes: 27 additions & 27 deletions .github/workflows/ci.yml
Expand Up @@ -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:
Expand All @@ -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'
Expand All @@ -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
13 changes: 10 additions & 3 deletions composer.json
Expand Up @@ -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": {
Expand All @@ -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
}
}
}
32 changes: 12 additions & 20 deletions phpunit.xml.dist
Expand Up @@ -5,32 +5,24 @@
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="ADmad/Sequence TestSuite">
<directory>./tests/TestCase</directory>
</testsuite>
<!-- Add plugin test suites here. -->
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>
<extensions>
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension"/>
</extensions>

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

<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<php>
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
</php>
</phpunit>
12 changes: 6 additions & 6 deletions src/Model/Behavior/SequenceBehavior.php
Expand Up @@ -67,7 +67,7 @@ class SequenceBehavior extends Behavior
*
* @var array<string, mixed>
*/
protected $_defaultConfig = [
protected array $_defaultConfig = [
'sequenceField' => 'position',
'scope' => [],
'startAt' => 1,
Expand All @@ -78,7 +78,7 @@ class SequenceBehavior extends Behavior
*
* @var array|null
*/
protected $_oldValues;
protected ?array $_oldValues = null;

/**
* Normalize config options.
Expand Down Expand Up @@ -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, '-');
}
Expand All @@ -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, '+');
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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'];

Expand Down
20 changes: 1 addition & 19 deletions tests/Fixture/GroupedItemsFixture.php
Expand Up @@ -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],
Expand Down
19 changes: 1 addition & 18 deletions tests/Fixture/ItemsFixture.php
Expand Up @@ -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],
Expand Down
19 changes: 1 addition & 18 deletions tests/Fixture/KeywordItemsFixture.php
Expand Up @@ -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],
Expand Down
22 changes: 1 addition & 21 deletions tests/Fixture/UniqueItemsFixture.php
Expand Up @@ -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],
Expand Down
5 changes: 1 addition & 4 deletions tests/TestCase/Model/Behavior/SequenceBehaviorTest.php
Expand Up @@ -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;
Expand All @@ -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',
Expand Down
5 changes: 0 additions & 5 deletions tests/bootstrap.php
Expand Up @@ -5,7 +5,6 @@
* Test suite bootstrap for Sequence
*/

use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;

/*
Expand Down Expand Up @@ -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',
]);

0 comments on commit 2543bd2

Please sign in to comment.