Skip to content

Commit 1ccb073

Browse files
authored
Merge pull request #1 from o-p/ci/base-action
Add Github actions
2 parents a58fe16 + 2d3d889 commit 1ccb073

File tree

7 files changed

+109
-7
lines changed

7 files changed

+109
-7
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ end_of_line = lf
55
insert_final_newline = true
66
indent_style = space
77
indent_size = 4
8+
9+
[*.yml,*.yaml]
10+
indent_size = 2

.github/workflows/lint.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Lint PHP Source Code
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches: [ master ]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Cache Composer packages
19+
id: composer-cache
20+
uses: actions/cache@v2
21+
with:
22+
path: vendor
23+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
24+
restore-keys: |
25+
${{ runner.os }}-php-
26+
27+
- name: Install dependencies
28+
if: steps.composer-cache.outputs.cache-hit != 'true'
29+
run: composer install --prefer-dist --no-progress --no-suggest
30+
31+
- name: Run linter
32+
run: composer run-script lint

.github/workflows/unit-test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Unit Test
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches: [ master ]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Validate composer.json and composer.lock
19+
run: composer validate
20+
21+
- name: Cache Composer packages
22+
id: composer-cache
23+
uses: actions/cache@v2
24+
with:
25+
path: vendor
26+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
27+
restore-keys: |
28+
${{ runner.os }}-php-
29+
30+
- name: Install dependencies
31+
if: steps.composer-cache.outputs.cache-hit != 'true'
32+
run: composer install --prefer-dist --no-progress --no-suggest
33+
34+
- name: Run test suite
35+
run: composer run-script test:ci
36+
37+
- name: Archive coverage results
38+
uses: actions/upload-artifact@v2
39+
with:
40+
name: code-coverage-report
41+
path: cache/coverage

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
11
# An unofficial PHP implementation of JsonLogic
2+
3+
### Usage
4+
5+
- For an one-time logic to data use case, the `apply` function is enough:
6+
7+
```php
8+
echo \JsonLogic\JsonLogic::apply($rule, $data);
9+
```
10+
11+
- For a rule runs tons times, e.g. find matched records in daily logs:
12+
13+
```php
14+
$rule = \JsonLogic\JsonLogic::rule($rule);
15+
16+
var_dump(
17+
array_filter($logs, function ($log) use ($rule) {
18+
return $rule->process($log);
19+
})
20+
);
21+
```

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
},
3434
"scripts": {
3535
"lint": "phpcs",
36-
"test": "phpunit"
36+
"test": "phpunit --stop-on-failure --no-coverage --colors=auto",
37+
"test:ci": "phpunit --disallow-test-output -c phpunit.xml.dist"
3738
}
3839
}

phpunit.xml.dist

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
backupGlobals="false"
44
backupStaticAttributes="false"
55
bootstrap="tests/bootstrap.php"
6-
colors="false"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false"
126
cacheResultFile="cache/.phpunit.result.cache"
7+
failOnRisky="true"
8+
failOnWarning="true"
139
>
1410
<testsuites>
1511
<testsuite name="Json Logic Test Suite">
@@ -21,4 +17,11 @@
2117
<directory suffix=".php">./src/</directory>
2218
</whitelist>
2319
</filter>
20+
<logging>
21+
<log type="coverage-html" target="cache/coverage/report" lowUpperBound="35" highLowerBound="70" />
22+
<log type="coverage-clover" target="cache/coverage/coverage.xml" />
23+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" />
24+
<log type="junit" target="cache/coverage/junit.xml" />
25+
<log type="testdox-text" target="cache/coverage/testdox.txt" />
26+
</logging>
2427
</phpunit>

src/Fallbacks.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* For fully fallback to official JsonLogic lib
18+
*
19+
* phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
1820
*/
1921
trait Fallbacks
2022
{

0 commit comments

Comments
 (0)