Skip to content

Commit

Permalink
Merge pull request #119 from ADmad/cake5
Browse files Browse the repository at this point in the history
Cake5
  • Loading branch information
ADmad authored Oct 15, 2023

Verified

This commit was signed with the committer’s verified signature.
vkubiv Volodymyr Kubiv
2 parents 495589f + a6cd30e commit 95343c7
Showing 21 changed files with 165 additions and 298 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpcs.xml.dist export-ignore
phpcs.xml export-ignore
phpstan.neon export-ignore
phpstan-baseline.neon export-ignore
phpunit.xml.dist export-ignore
95 changes: 7 additions & 88 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -8,95 +8,14 @@ on:
branches:
- '*'

permissions:
contents: read

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

services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres

steps:
- uses: actions/checkout@v3

- name: Setup Service
if: matrix.db-type == 'mysql'
run: |
sudo service mysql start
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp;'
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, pdo_${{ matrix.db-type }}
coverage: pcov

- name: Composer install
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer install
fi
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- 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'; 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' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Code Coverage Report
if: success() && matrix.php-version == '7.4'
uses: codecov/codecov-action@v3
uses: ADmad/.github/.github/workflows/testsuite-with-db.yml@master
secrets: inherit

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

steps:
- uses: actions/checkout@v3

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

- name: Composer Install
run: composer install

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

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

- name: Run psalm
if: always()
run: phpstan analyse
uses: ADmad/.github/.github/workflows/cs-stan.yml@master
secrets: inherit
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
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
"socialconnect/auth": "^3.1"
"cakephp/cakephp": "^5.0",
"socialconnect/auth": "^3.3"
},
"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": {
@@ -24,8 +24,9 @@
},
"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"
},
"config": {
"allow-plugins": {
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\\\\SocialAuthPlugin\\:\\:bootstrap\\(\\) has parameter \\$app with generic interface Cake\\\\Core\\\\PluginApplicationInterface but does not specify its types\\: TSubject$#"
count: 1
path: src/SocialAuthPlugin.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"
16 changes: 8 additions & 8 deletions src/Database/Type/SerializedType.php
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

namespace ADmad\SocialAuth\Database\Type;

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

@@ -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;
@@ -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;
@@ -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;
@@ -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;
Loading

0 comments on commit 95343c7

Please sign in to comment.