Skip to content

Commit

Permalink
Merge pull request #118 from LordSimal/cake5
Browse files Browse the repository at this point in the history
Cake5 upgrade
  • Loading branch information
ADmad authored Oct 15, 2023
2 parents 495589f + c8c779e commit 50fdccf
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 217 deletions.
35 changes: 19 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ on:

jobs:
testsuite:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1']
php-version: ['8.1', '8.2']
db-type: [sqlite, mysql, pgsql]
prefer-lowest: ['']
include:
- php-version: '7.2'
- php-version: '8.1'
db-type: 'sqlite'
prefer-lowest: 'prefer-lowest'

Expand All @@ -31,7 +31,7 @@ jobs:
POSTGRES_PASSWORD: postgres

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Service
if: matrix.db-type == 'mysql'
Expand Down Expand Up @@ -62,41 +62,44 @@ jobs:
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Code Coverage Report
if: success() && matrix.php-version == '7.4'
if: success() && matrix.php-version == '8.1'
uses: codecov/codecov-action@v3

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: cs2pr, vimeo/psalm:4, phpstan:1
tools: phive, cs2pr

- name: Composer Install
run: composer install
- name: Composer install
uses: ramsey/composer-install@v2

- name: Install PHP tools with phive.
run: "phive install --trust-gpg-keys 'CF1A108D0E7AE720,51C67305FFC2E5C0,12CE0F1D262429A5'"

- name: Run phpcs
run: vendor/bin/phpcs -q --report=checkstyle --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/ | cs2pr
run: vendor/bin/phpcs --report=checkstyle src/ tests/ | cs2pr

- name: Run psalm
if: always()
run: psalm --output-format=github
run: tools/psalm --output-format=github

- name: Run psalm
- name: Run phpstan
if: always()
run: phpstan analyse
run: tools/phpstan analyse --error-format=github
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/composer.lock
/phpunit.xml
/vendor/
.phpunit.result.cache
/.phpunit.cache
/.idea/
/config/Migrations/schema-dump-default.lock
/tools
5 changes: 5 additions & 0 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.10.38" installed="1.10.38" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.15.0" installed="5.15.0" location="./tools/psalm" copy="false"/>
</phive>
20 changes: 15 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"description": "A CakePHP plugin which allows you to authenticate using social providers like Facebook/Google/Twitter etc.",
"type": "cakephp-plugin",
"require": {
"cakephp/cakephp": "^4.1",
"cakephp/cakephp": "^5.0",
"socialconnect/auth": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "^8.5.0 || ^9.5.0",
"cakephp/cakephp-codesniffer": "^4.0"
"phpunit/phpunit": "^10.1",
"cakephp/cakephp-codesniffer": "^5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -24,8 +24,18 @@
},
"license": "MIT",
"scripts": {
"cs-check": "vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
"cs-fix": "vendor/bin/phpcbf -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/"
"cs-check": "phpcs --colors -p ./src ./tests",
"cs-fix": "phpcbf --colors -p ./src ./tests",
"test": "phpunit",
"phpstan": "tools/phpstan analyse",
"psalm": "tools/psalm --show-info=false",
"stan": [
"@phpstan",
"@psalm"
],
"phpstan-baseline": "tools/phpstan --generate-baseline",
"psalm-baseline": "tools/psalm --set-baseline=psalm-baseline.xml",
"stan-setup": "phive install"
},
"config": {
"allow-plugins": {
Expand Down
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Sentry">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />
</ruleset>
11 changes: 11 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$callback of function call_user_func expects callable\\(\\)\\: mixed, array\\{Cake\\\\ORM\\\\Table, mixed\\} given\\.$#"
count: 1
path: src/Middleware/SocialAuthMiddleware.php

-
message: "#^Method ADmad\\\\SocialAuth\\\\Plugin\\:\\:bootstrap\\(\\) has parameter \\$app with generic interface Cake\\\\Core\\\\PluginApplicationInterface but does not specify its types\\: TSubject$#"
count: 1
path: src/Plugin.php
8 changes: 3 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
includes:
- phpstan-baseline.neon

parameters:
level: 8
checkMissingIterableValueType: false
bootstrapFiles:
- tests/bootstrap.php
paths:
- src/
ignoreErrors:
-
message: "#^Parameter \\#1 \\$function of function call_user_func expects callable\\(\\)\\: mixed, array\\{Cake\\\\ORM\\\\Table, mixed\\} given\\.$#"
count: 1
path: src/Middleware/SocialAuthMiddleware.php
42 changes: 24 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="tests/bootstrap.php"
colors="true"
stopOnFailure="false"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
colors="true"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
cacheDirectory=".phpunit.cache">

<testsuites>
<testsuite name="social-auth">
<directory>tests/</directory>
</testsuite>
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="Cake\TestSuite\Fixture\FixtureManager"/>
</arguments>
</listener>
</listeners>
<extensions>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>

<filter>
<whitelist>
<source>
<include>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</include>
</source>

<php>
<ini name="memory_limit" value="-1"/>
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
<!-- Postgres
<env name="DB_URL" value="postgres://root@localhost/cake_test_db"/>
-->
<!-- Mysql
<env name="DB_URL" value="mysql://root@localhost/cake_test_db"/>
-->
</php>
</phpunit>
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0"?>
<psalm
findUnusedPsalmSuppress="true"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
16 changes: 8 additions & 8 deletions src/Database/Type/SerializedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ADmad\SocialAuth\Database\Type;

use Cake\Database\DriverInterface;
use Cake\Database\Driver;
use Cake\Database\Type\BaseType;
use PDO;

Expand All @@ -20,10 +20,10 @@ class SerializedType extends BaseType
* Convert a value data into a serialized string.
*
* @param mixed $value The value to convert.
* @param \Cake\Database\DriverInterface $driver The driver instance to convert with.
* @param \Cake\Database\Driver $driver The driver instance to convert with.
* @return string|null
*/
public function toDatabase($value, DriverInterface $driver)
public function toDatabase(mixed $value, Driver $driver): mixed
{
if ($value === null || is_string($value)) {
return $value;
Expand All @@ -36,10 +36,10 @@ public function toDatabase($value, DriverInterface $driver)
* Convert string values to PHP data structure.
*
* @param mixed $value The value to convert.
* @param \Cake\Database\DriverInterface $driver The driver instance to convert with.
* @param \Cake\Database\Driver $driver The driver instance to convert with.
* @return mixed
*/
public function toPHP($value, DriverInterface $driver)
public function toPHP(mixed $value, Driver $driver): mixed
{
if ($value === null) {
return $value;
Expand All @@ -58,10 +58,10 @@ public function toPHP($value, DriverInterface $driver)
* Get the correct PDO binding type for string data.
*
* @param mixed $value The value being bound.
* @param \Cake\Database\DriverInterface $driver The driver.
* @param \Cake\Database\Driver $driver The driver.
* @return int
*/
public function toStatement($value, DriverInterface $driver)
public function toStatement(mixed $value, Driver $driver): int
{
if ($value === null) {
return PDO::PARAM_NULL;
Expand All @@ -76,7 +76,7 @@ public function toStatement($value, DriverInterface $driver)
* @param mixed $value The value to convert.
* @return mixed Converted value.
*/
public function marshal($value)
public function marshal(mixed $value): mixed
{
if (is_array($value) || $value === null) {
return $value;
Expand Down
Loading

0 comments on commit 50fdccf

Please sign in to comment.