Skip to content

Commit

Permalink
Merge pull request #12 from LordSimal/cake5
Browse files Browse the repository at this point in the history
Fix CI
  • Loading branch information
passchn authored Sep 23, 2023
2 parents 692e229 + 1d08749 commit d0fa577
Show file tree
Hide file tree
Showing 30 changed files with 173 additions and 225 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
root = true

[*]
indent_style = tab
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
Expand Down
53 changes: 25 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- cake5
pull_request:
workflow_dispatch:

Expand All @@ -13,11 +14,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ '8.0' ]
php-version: [ '8.1', '8.2' ]
db-type: [ 'sqlite', 'mysql', 'pgsql' ]
prefer-lowest: [ '' ]
include:
- php-version: '8.0'
- php-version: '8.1'
db-type: 'sqlite'
prefer-lowest: 'prefer-lowest'

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

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

- name: Setup Service
if: matrix.db-type == 'mysql'
Expand All @@ -50,7 +51,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down Expand Up @@ -80,52 +81,48 @@ 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?encoding=utf8'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
if [[ ${{ matrix.php-version }} == '8.0' && ${{ matrix.db-type }} == 'sqlite' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
if [[ ${{ matrix.php-version }} == '8.1' && ${{ matrix.db-type }} == 'sqlite' ]]; then
vendor/bin/phpunit --display-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml
else
vendor/bin/phpunit
vendor/bin/phpunit --display-deprecations
fi
- name: Validate prefer-lowest
run: if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then vendor/bin/validate-prefer-lowest -m; fi

- name: Code Coverage Report
if: success() && matrix.php-version == '8.0' && matrix.db-type == 'sqlite'
uses: codecov/codecov-action@v1
if: success() && matrix.php-version == '8.1' && matrix.db-type == 'sqlite'
uses: codecov/codecov-action@v3

validation:
name: Coding Standard & Static Analysis
runs-on: ubuntu-22.04

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: phive, cs2pr

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Composer install
uses: ramsey/composer-install@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

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

- name: Run phpstan
run: vendor/bin/phpstan analyse --error-format=github
- name: Run phpcs
if: always()
run: vendor/bin/phpcs --report=checkstyle src/ tests/ | cs2pr

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

- name: Run phpcs
run: composer cs-check
- name: Run phpstan
if: always()
run: tools/phpstan analyse --error-format=github
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/node_modules
webroot/modified
.phpunit.cache/test-results
/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.28" installed="1.10.28" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.14.1" installed="5.14.1" location="./tools/psalm" copy="false"/>
</phive>
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require-dev": {
"cakedc/cakephp-phpstan": "3.next-cake5-dev",
"cakephp/cakephp-codesniffer": "^5.1",
"phpunit/phpunit": "^10.0"
"phpunit/phpunit": "^10.1"
},
"autoload": {
"psr-4": {
Expand All @@ -30,16 +30,18 @@
}
},
"scripts": {
"cs-check": "phpcs --colors --parallel=16 -p src/",
"cs-fix": "phpcbf --colors --parallel=16 -p src/",
"phpstan": "phpstan.phar analyse",
"psalm": "psalm.phar --show-info=false",
"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",
"test": "phpunit",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~1.9.0 psalm/phar:~5.4.0 && mv composer.backup composer.json",
"stan-setup": "phive install",
"lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json"
},
"config": {
Expand Down
4 changes: 2 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<ruleset name="CakePHP DebugKit">
<ruleset name="CakePHP Assets Plugin">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />
Expand All @@ -8,4 +8,4 @@
<property name="lineLimit" value="150"/>
</properties>
</rule>
</ruleset>
</ruleset>
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ parameters:
- tests/bootstrap.php

includes:
- vendor/cakedc/cakephp-phpstan/extension.neon
- vendor/cakedc/cakephp-phpstan/extension.neon
41 changes: 23 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache">
<php>
<!-- E_ALL => 32767 -->
<!-- E_ALL & ~E_USER_DEPRECATED => 16383 -->
<ini name="error_reporting" value="16383"/>
</php>
<testsuites>
<testsuite name="assets">
<directory>tests/</directory>
</testsuite>
</testsuites>
<!-- Prevent coverage reports from looking in tests, vendors, config folders -->
<coverage/>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
cacheDirectory=".phpunit.cache">
<php>
<!-- E_ALL => 32767 -->
<!-- E_ALL & ~E_USER_DEPRECATED => 16383 -->
<ini name="error_reporting" value="16383"/>
</php>

<testsuites>
<testsuite name="assets">
<directory>tests/</directory>
</testsuite>
</testsuites>

<!-- Prevent coverage reports from looking in tests, vendors, config folders -->
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
27 changes: 12 additions & 15 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.x-dev@">
<files psalm-version="5.14.1@b9d355e0829c397b9b3b47d0c0ed042a8a70284d">
<file src="src/Controller/Admin/AssetsController.php">
<MissingDependency occurrences="1">
<code>AppController</code>
</MissingDependency>
<InternalClass>
<code><![CDATA[new CallbackStream(function () use ($asset) {
return $asset->read();
})]]></code>
</InternalClass>
<TooManyTemplateParams>
<code><![CDATA[$this->paginate($this->Assets)]]></code>
</TooManyTemplateParams>
</file>
<file src="src/Controller/AppController.php">
<UndefinedClass occurrences="1">
<code>BaseController</code>
</UndefinedClass>
</file>
<file src="src/Model/Entity/Asset.php">
<NonInvariantDocblockPropertyType occurrences="1">
<code>$_accessible</code>
</NonInvariantDocblockPropertyType>
<PossiblyNullReference occurrences="1">
<code>toDateTimeString</code>
</PossiblyNullReference>
<PropertyTypeCoercion>
<code><![CDATA[$this->fetchTable('Assets.Assets')]]></code>
</PropertyTypeCoercion>
</file>
</files>
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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"
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
Expand Down
33 changes: 19 additions & 14 deletions src/Controller/Admin/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
use Assets\Controller\AppController;
use Cake\Http\CallbackStream;
use Cake\Http\Response;
use function Cake\I18n\__d;

/**
* Assets Controller
*
* @method \Cake\ORM\Entity[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
* @method \Cake\Datasource\Paging\PaginatedInterface<\Assets\Model\Entity\Asset[]> paginate($object = null, array $settings = [])
*/
class AssetsController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
* @return void Renders view
*/
public function index()
public function index(): void
{
$assets = $this->paginate($this->Assets);

Expand All @@ -30,10 +31,10 @@ public function index()
* View method
*
* @param string|null $id Asset id.
* @return \Cake\Http\Response|null|void Renders view
* @return void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
public function view(?string $id = null): void
{
$asset = $this->Assets->get($id, [
'contain' => [],
Expand All @@ -45,9 +46,9 @@ public function view($id = null)
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
* @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
*/
public function add()
public function add(): ?Response
{
$asset = $this->Assets->newEmptyEntity();
if ($this->getRequest()->is('post')) {
Expand All @@ -60,16 +61,18 @@ public function add()
$this->Flash->error(__d('assets', 'The asset could not be saved. Please, try again.'));
}
$this->set(compact('asset'));

return $this->render();
}

/**
* Edit method
*
* @param string|null $id Asset id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function edit($id = null)
public function edit(?string $id = null): ?Response
{
$asset = $this->Assets->get($id, [
'contain' => [],
Expand All @@ -84,16 +87,18 @@ public function edit($id = null)
$this->Flash->error(__d('assets', 'The asset could not be saved. Please, try again.'));
}
$this->set(compact('asset'));

return $this->render();
}

/**
* Delete method
*
* @param string|null $id Asset id.
* @return \Cake\Http\Response|null|void Redirects to index.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function delete($id = null)
public function delete(?string $id = null): ?Response
{
$this->getRequest()->allowMethod(['post', 'delete']);
$asset = $this->Assets->get($id);
Expand All @@ -110,9 +115,9 @@ public function delete($id = null)
* Add ?download=1 to URL to download instead of view the file.
*
* @param string $id The ID of the asset
* @return \Cake\Http\Response
* @return \Cake\Http\Response|null
*/
public function download(string $id): Response
public function download(string $id): ?Response
{
$asset = $this->Assets->get($id);
$is_download = (bool)$this->getRequest()->getQuery('download');
Expand All @@ -122,7 +127,7 @@ public function download(string $id): Response
});

$response = $this->getResponse()
->withType($asset->mimetype)
->withType($asset->mimetype ?? 'jpg')
->withDisabledCache()
->withBody($stream);

Expand Down
Loading

0 comments on commit d0fa577

Please sign in to comment.