From 8d3b419af2046e16f82ab5046cef48e645daeeda Mon Sep 17 00:00:00 2001 From: Chris Chu Date: Tue, 22 Sep 2020 10:02:20 +0800 Subject: [PATCH 1/2] Add simple usage examples --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index e630fe0..ebf7a8b 100644 --- a/README.md +++ b/README.md @@ -1 +1,21 @@ # An unofficial PHP implementation of JsonLogic + +### Usage + +- For an one-time logic to data use case, the `apply` function is enough: + + ```php + echo \JsonLogic\JsonLogic::apply($rule, $data); + ``` + +- For a rule runs tons times, e.g. find matched records in daily logs: + + ```php + $rule = \JsonLogic\JsonLogic::rule($rule); + + var_dump( + array_filter($logs, function ($log) use ($rule) { + return $rule->process($log); + }) + ); + ``` From 2d3d88913c0e4a6dc5a8c33b91d1852f0fb59f51 Mon Sep 17 00:00:00 2001 From: Chris Chu Date: Mon, 21 Sep 2020 11:10:13 +0800 Subject: [PATCH 2/2] Add test and lint CI --- .editorconfig | 3 +++ .github/workflows/lint.yml | 32 +++++++++++++++++++++++++ .github/workflows/unit-test.yml | 41 +++++++++++++++++++++++++++++++++ composer.json | 3 ++- phpunit.xml.dist | 15 +++++++----- src/Fallbacks.php | 2 ++ 6 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/unit-test.yml diff --git a/.editorconfig b/.editorconfig index a882442..4d165c2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,3 +5,6 @@ end_of_line = lf insert_final_newline = true indent_style = space indent_size = 4 + +[*.yml,*.yaml] +indent_size = 2 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..cefe791 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,32 @@ +name: Lint PHP Source Code + +on: + push: + branches: + - '**' + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run linter + run: composer run-script lint diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 0000000..918406d --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,41 @@ +name: Unit Test + +on: + push: + branches: + - '**' + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run test suite + run: composer run-script test:ci + + - name: Archive coverage results + uses: actions/upload-artifact@v2 + with: + name: code-coverage-report + path: cache/coverage diff --git a/composer.json b/composer.json index 3615899..9a27eb5 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ }, "scripts": { "lint": "phpcs", - "test": "phpunit" + "test": "phpunit --stop-on-failure --no-coverage --colors=auto", + "test:ci": "phpunit --disallow-test-output -c phpunit.xml.dist" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f04479b..c8aa7a7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,13 +3,9 @@ backupGlobals="false" backupStaticAttributes="false" bootstrap="tests/bootstrap.php" - colors="false" - convertErrorsToExceptions="true" - convertNoticesToExceptions="true" - convertWarningsToExceptions="true" - processIsolation="false" - stopOnFailure="false" cacheResultFile="cache/.phpunit.result.cache" + failOnRisky="true" + failOnWarning="true" > @@ -21,4 +17,11 @@ ./src/ + + + + + + + diff --git a/src/Fallbacks.php b/src/Fallbacks.php index c29fb69..1fa04d7 100644 --- a/src/Fallbacks.php +++ b/src/Fallbacks.php @@ -15,6 +15,8 @@ /** * For fully fallback to official JsonLogic lib + * + * phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ trait Fallbacks {