Skip to content

Commit

Permalink
Merge pull request #101 from UseMuffin/cake-4.x
Browse files Browse the repository at this point in the history
Cake 4.x
  • Loading branch information
ADmad authored Sep 11, 2021
2 parents 9bde164 + f5351a3 commit fa00f1f
Show file tree
Hide file tree
Showing 70 changed files with 1,157 additions and 1,733 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ end_of_line = crlf

[*.yml]
indent_style = space
indent_size = 2
indent_size = 2

[*.neon]
indent_style = tab
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.semver export-ignore
phpunit.xml.dist export-ignore
.travis.yml export-ignore
tests export-ignore
phpstan.neon export-ignore
psalm.xml export-ignore
.github export-ignore
101 changes: 101 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- '*'

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

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: psalm:4.7, phpstan:0.12

- name: Composer Install
run: composer require cakephp/cakephp-codesniffer:^4.2

- name: Run phpcs
run: vendor/bin/phpcs --standard=CakePHP src/ tests/

- name: Run psalm
if: success() || failure()
run: psalm --output-format=github

- name: Run phpstan
if: success() || failure()
run: phpstan analyse
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/composer.lock
/plugins
/vendor
.phpunit.result.cache
58 changes: 0 additions & 58 deletions .travis.yml

This file was deleted.

31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Webservice

[![Build Status](https://img.shields.io/travis/UseMuffin/Webservice/master.svg?style=flat-square)](https://travis-ci.org/UseMuffin/Webservice)
[![Build Status](https://img.shields.io/travis/UseMuffin/Webservice/master.svg?style=flat-square)](https://github.com/UseMuffin/Webservice/actions?query=workflow%3ACI+branch%3Amaster)
[![Coverage](https://img.shields.io/codecov/c/github/UseMuffin/Webservice/master.svg?style=flat-square)](https://codecov.io/github/UseMuffin/Webservice)
[![Total Downloads](https://img.shields.io/packagist/dt/muffin/webservice.svg?style=flat-square)](https://packagist.org/packages/muffin/webservice)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
Expand All @@ -23,6 +23,24 @@ bin/cake plugin load Muffin/Webservice

## Usage

### Datasource Configuration

In your `app.php`, add a new `webservice` config under `Datasources`:

```php
'Datasources' => [
// Other db config here
'webservice' => [
'className' => \Muffin\Webservice\Connection::class,
'service' => 'Articles',
// Any additional keys will be set as Driver's config.
],
],
```

If you are making a plugin then conventionally the datasource config key name
should be underscored version of plugin name.

### As an ORM

#### Create driver
Expand All @@ -31,15 +49,15 @@ bin/cake plugin load Muffin/Webservice
<?php
namespace App\Webservice\Driver;

use Cake\Network\Http\Client;
use Muffin\Webservice\AbstractDriver;
use Cake\Http\Client;
use Muffin\Webservice\Driver\AbstractDriver;

class Articles extends AbstractDriver
{
/**
* Initialize is used to easily extend the constructor.
*/
public function initialize()
public function initialize(): void
{
$this->setClient(new Client([
'host' => 'example.com'
Expand All @@ -54,8 +72,8 @@ class Articles extends AbstractDriver
<?php
namespace App\Webservice;

use Muffin\Webservice\Query;
use Muffin\Webservice\ResultSet;
use Muffin\Webservice\Datasource\Query;
use Muffin\Webservice\Datasource\ResultSet;
use Muffin\Webservice\Webservice\Webservice;

class ArticlesWebservice extends Webservice
Expand Down Expand Up @@ -110,7 +128,6 @@ class Article extends Resource
<?php
namespace App\Controller;

use Cake\Event\Event;
use Muffin\Webservice\Model\EndpointLocator;

class ArticlesController extends AppController
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muffin/webservice",
"description": "Extremely simplistic webservices for CakePHP 3",
"description": "Simplistic webservices for CakePHP",
"type": "cakephp-plugin",
"keywords": [
"cakephp",
Expand Down Expand Up @@ -39,12 +39,12 @@
"irc": "irc://irc.freenode.org/muffin"
},
"require": {
"cakephp/orm": "^3.6"
"cakephp/orm": "^4.2"
},
"require-dev": {
"cakephp/cakephp": "^3.6",
"cakephp/cakephp-codesniffer": "^3.0",
"phpunit/phpunit": "^5.7.14|^6.0"
"cakephp/cakephp": "^4.2",
"cakephp/cakephp-codesniffer": "^4.0",
"phpunit/phpunit": "^8.5 || ^9.3"
},
"autoload": {
"psr-4": {
Expand All @@ -53,7 +53,10 @@
},
"autoload-dev": {
"psr-4": {
"Muffin\\Webservice\\Test\\": "tests"
"Muffin\\Webservice\\Test\\": "tests",
"TestApp\\": "tests/test_app/src",
"SomeVendor\\SomePlugin\\": "tests/test_app/plugins/SomeVendor/SomePlugin/src",
"TestPlugin\\": "tests/test_app/plugins/TestPlugin/src"
}
}
}
5 changes: 0 additions & 5 deletions config/bootstrap.php

This file was deleted.

78 changes: 20 additions & 58 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,59 +1,21 @@
parameters:
level: 6
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
-
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
count: 1
path: src/Marshaller.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 3
path: src/Model/Endpoint.php

-
message: "#^Result of \\|\\| is always true\\.$#"
count: 1
path: src/Model/Endpoint.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/Model/Endpoint.php

-
message: "#^Call to an undefined method Traversable\\:\\:count\\(\\)\\.$#"
count: 1
path: src/Model/Endpoint.php

-
message: "#^Parameter \\#1 \\$connection of method Muffin\\\\Webservice\\\\Model\\\\Endpoint\\:\\:setConnection\\(\\) expects Muffin\\\\Webservice\\\\Connection, Muffin\\\\Webservice\\\\AbstractDriver given\\.$#"
count: 1
path: src/Model/Endpoint.php

-
message: "#^Method Muffin\\\\Webservice\\\\Query\\:\\:endpoint\\(\\) should return \\$this\\(Muffin\\\\Webservice\\\\Query\\)\\|Muffin\\\\Webservice\\\\Model\\\\Endpoint but returns Cake\\\\Datasource\\\\RepositoryInterface\\.$#"
count: 1
path: src/Query.php

-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\RepositoryInterface\\:\\:callFinder\\(\\)\\.$#"
count: 1
path: src/Query.php

-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\RepositoryInterface\\:\\:getName\\(\\)\\.$#"
count: 1
path: src/Query.php

-
message: "#^Return type \\(array\\) of method Muffin\\\\Webservice\\\\Query\\:\\:aliasField\\(\\) should be compatible with return type \\(string\\) of method Cake\\\\Datasource\\\\QueryInterface\\:\\:aliasField\\(\\)$#"
count: 1
path: src/Query.php

-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\RepositoryInterface\\:\\:dispatchEvent\\(\\)\\.$#"
count: 1
path: src/Query.php
level: 6
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
- src/
ignoreErrors:
-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\RepositoryInterface\\:\\:callFinder\\(\\)\\.$#"
count: 1
path: src/Datasource/Query.php

-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\RepositoryInterface\\:\\:getName\\(\\)\\.$#"
count: 1
path: src/Datasource/Query.php

-
message: "#^Method Muffin\\\\Webservice\\\\Datasource\\\\Query\\:\\:execute\\(\\) should return bool\\|int\\|Muffin\\\\Webservice\\\\Datasource\\\\ResultSet\\|Muffin\\\\Webservice\\\\Model\\\\Resource but returns Cake\\\\Datasource\\\\ResultSetInterface\\.$#"
count: 1
path: src/Datasource/Query.php
Loading

0 comments on commit fa00f1f

Please sign in to comment.