Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cake 5 #601

Merged
merged 9 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ root = true
[*]
indent_style = space
indent_size = 4
charset = "utf-8"
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2

[*.neon]
Expand Down
6 changes: 4 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ CONTRIBUTING.md export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpunit.xml.dist export-ignore
.scrutinizer.yml export-ignore
.stickler.yml export-ignore
tests export-ignore
docs export-ignore
.github export-ignore
.phive export-ignore
phpcs.xml export-ignore
psalm.xml export-ignore
phpstan.neon export-ignore
98 changes: 15 additions & 83 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,22 @@
name: CI

on: [push, pull_request]
on:
push:
branches:
- master
- cake-5
pull_request:
branches:
- '*'

permissions:
contents: read

jobs:
testsuite:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1']
db-type: [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@v2

- 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: 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:[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' && ${{ matrix.db-type }} == 'mysql' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
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
uses: cakephp/.github/.github/workflows/[email protected]
secrets: inherit

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

steps:
- uses: actions/checkout@v2

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

- name: Composer Install
run: composer install

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

- name: Run phpstan
if: success() || failure()
run: phpstan analyse
uses: cakephp/.github/.github/workflows/[email protected]
secrets: inherit
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>
21 changes: 0 additions & 21 deletions .scrutinizer.yml

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://img.shields.io/github/workflow/status/FriendsOfCake/cakephp-upload/CI/master?style=flat-square)](https://github.com/FriendsOfCake/cakephp-upload/actions?query=workflow%3ACI+branch%3Amaster)
[![Build Status](https://img.shields.io/github/actions/workflow/status/FriendsOfCake/cakephp-upload/ci.yml?style=flat-square)](https://github.com/FriendsOfCake/cakephp-upload/actions?query=workflow%3ACI+branch%3Amaster)
[![Coverage Status](https://img.shields.io/codecov/c/github/FriendsOfCake/cakephp-upload/master?style=flat-square)](https://codecov.io/gh/FriendsOfCake/cakephp-upload)
[![Total Downloads](https://img.shields.io/packagist/dt/josegonzalez/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/josegonzalez/cakephp-upload)
[![Latest Stable Version](https://img.shields.io/packagist/v/josegonzalez/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/josegonzalez/cakephp-upload)
Expand All @@ -8,6 +8,8 @@

The Upload Plugin is an attempt to easily handle file uploads with CakePHP.

See [7.x branch](https://github.com/FriendsOfCake/cakephp-upload/tree/7.x) for CakePHP 4.x documentation.

See [4.x branch](https://github.com/FriendsOfCake/cakephp-upload/tree/4.x) for CakePHP 3.x documentation.

See [2.x branch](https://github.com/FriendsOfCake/cakephp-upload/tree/2.x) for CakePHP 2.x documentation.
Expand Down
29 changes: 22 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,30 @@
}
],
"require": {
"cakephp/orm": "^4.0.2",
"league/flysystem": "^2.2|^3.0"
"cakephp/orm": "^5.0",
"league/flysystem": "^3.15.1.0"
},
"require-dev": {
"cakephp/cakephp": "^4.0.2",
"phpunit/phpunit": "^8.5 || ^9.3",
"cakephp/cakephp-codesniffer": "^4.0",
"league/flysystem-memory": "^2.0|^3.0",
"mikey179/vfsstream": "^1.6.10"
"cakephp/cakephp": "^5.0",
"phpunit/phpunit": "^10.1.0",
"cakephp/cakephp-codesniffer": "^5.0",
"league/flysystem-memory": "^3.15",
"mikey179/vfsstream": "^1.6.10",
"cakephp/migrations": "^4.1"
},
"scripts": {
"cs-check": "phpcs --colors --parallel=16 -p src/ tests/",
"cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/",
"phpstan": "tools/phpstan analyse",
"psalm": "tools/psalm --show-info=false",
"stan": [
"@phpstan",
"@psalm"
],
"stan-baseline": "tools/phpstan --generate-baseline",
"psalm-baseline": "tools/psalm --set-baseline=psalm-baseline.xml",
"stan-setup": "phive install",
"test": "phpunit"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Core">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />

<arg value="s"/>
</ruleset>
6 changes: 3 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 7
level: 8
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
Expand All @@ -21,11 +21,11 @@ parameters:
path: src/Model/Behavior/UploadBehavior.php

-
message: "#^Cannot use array destructuring on array\\|false\\.$#"
message: "#^Cannot use array destructuring on array\\<int\\|string, int\\|string\\>\\|false\\.$#"
count: 4
path: src/Validation/DefaultValidation.php

-
message: "#^Cannot use array destructuring on array\\|false\\.$#"
message: "#^Cannot use array destructuring on array\\<int\\|string, int\\|string\\>\\|false\\.$#"
count: 4
path: src/Validation/ImageValidation.php
45 changes: 14 additions & 31 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?><phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
convertDeprecationsToExceptions="true"
>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd">
<coverage/>
<php>
<ini name="memory_limit" value="-1"/>
<!-- E_ALL & ~E_USER_DEPRECATED (16383)-->
<!-- E_ALL (32767) -->
<ini name="error_reporting" value="32767"/>
<ini name="apc.enable_cli" value="1"/>
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="Version Test Suite">
<directory>./tests/TestCase</directory>
<testsuite name="cakephp-upload">
<directory>tests/TestCase/</directory>
</testsuite>
</testsuites>

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

<!-- 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>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
19 changes: 19 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<psalm
reportMixedIssues="false"
autoloader="tests/bootstrap.php"
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
8 changes: 4 additions & 4 deletions src/Database/Type/FileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Josegonzalez\Upload\Database\Type;

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

class FileType extends BaseType
Expand All @@ -17,23 +17,23 @@
* @param mixed $value The value to convert.
* @return mixed Converted value.
*/
public function marshal($value)
public function marshal(mixed $value): mixed
{
return $value;
}

/**
* @inheritDoc
*/
public function toDatabase($value, DriverInterface $driver)
public function toDatabase(mixed $value, Driver $driver): mixed

Check warning on line 28 in src/Database/Type/FileType.php

View check run for this annotation

Codecov / codecov/patch

src/Database/Type/FileType.php#L28

Added line #L28 was not covered by tests
{
return $value;
}

/**
* @inheritDoc
*/
public function toPHP($value, DriverInterface $driver)
public function toPHP(mixed $value, Driver $driver): mixed

Check warning on line 36 in src/Database/Type/FileType.php

View check run for this annotation

Codecov / codecov/patch

src/Database/Type/FileType.php#L36

Added line #L36 was not covered by tests
{
return $value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/File/Path/Basepath/DefaultTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function basepath(): string
{
$defaultPath = 'webroot{DS}files{DS}{model}{DS}{field}{DS}';
$path = Hash::get($this->settings, 'path', $defaultPath);
if (strpos($path, '{primaryKey}') !== false) {
if (str_contains($path, '{primaryKey}')) {
if ($this->entity->isNew()) {
throw new LogicException('{primaryKey} substitution not allowed for new entities');
}
Expand All @@ -43,7 +43,7 @@ public function basepath(): string
'{microtime}' => microtime(true),
'{DS}' => DIRECTORY_SEPARATOR,
];
if (strpos($path, '{primaryKey}') !== false) {
if (str_contains($path, '{primaryKey}')) {
$replacements['{primaryKey}'] = $this->entity->get($this->table->getPrimaryKey());
}

Expand Down
Loading