Skip to content

Commit 70eb9ac

Browse files
committed
+ add tests workflow.
1 parent 0a3e603 commit 70eb9ac

10 files changed

Lines changed: 3640 additions & 921 deletions

File tree

.github/workflows/tests.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Tests
2+
3+
on:
4+
# 在推送和PR时运行测试
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
# 允许手动触发
11+
workflow_dispatch:
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
php-version: ['8.1', '8.2', '8.3']
20+
21+
name: PHP ${{ matrix.php-version }} Tests
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Setup PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: ${{ matrix.php-version }}
31+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
32+
coverage: xdebug
33+
34+
- name: Validate composer.json and composer.lock
35+
run: composer validate --strict
36+
37+
- name: Cache Composer packages
38+
id: composer-cache
39+
uses: actions/cache@v3
40+
with:
41+
path: vendor
42+
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
43+
restore-keys: |
44+
${{ runner.os }}-php-${{ matrix.php-version }}-
45+
46+
- name: Install dependencies
47+
run: composer install --prefer-dist --no-progress --no-suggest
48+
49+
- name: Run PHPUnit tests
50+
run: composer test
51+
52+
code-quality:
53+
runs-on: ubuntu-latest
54+
name: Code Quality
55+
56+
steps:
57+
- name: Checkout code
58+
uses: actions/checkout@v4
59+
60+
- name: Setup PHP
61+
uses: shivammathur/setup-php@v2
62+
with:
63+
php-version: '8.1'
64+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
65+
66+
- name: Cache Composer packages
67+
uses: actions/cache@v3
68+
with:
69+
path: vendor
70+
key: ${{ runner.os }}-php-8.1-${{ hashFiles('**/composer.lock') }}
71+
restore-keys: |
72+
${{ runner.os }}-php-8.1-
73+
74+
- name: Install dependencies
75+
run: composer install --prefer-dist --no-progress --no-suggest
76+
77+
- name: Check PHP syntax
78+
run: find src tests -name "*.php" -exec php -l {} \;
79+
80+
- name: Run PHP CS Fixer
81+
run: composer cs-check
82+
83+
- name: Run PHPStan
84+
run: composer phpstan

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1+
# Dependencies
12
/vendor
23
site/node_modules
4+
5+
# VitePress
36
site/docs/.vitepress/cache
47
site/docs/.vitepress/dist
8+
9+
# Testing
10+
.phpunit.cache
11+
coverage/
12+
coverage.xml
13+
14+
# Code Quality Tools
15+
.php-cs-fixer.cache
16+
17+
# IDE
18+
.vscode/
19+
.idea/
20+
*.swp
21+
*.swo
22+
23+
# OS
24+
.DS_Store
25+
Thumbs.db

.php-cs-fixer.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/tests')
6+
->name('*.php')
7+
->notName('*.blade.php')
8+
->ignoreDotFiles(true)
9+
->ignoreVCS(true);
10+
11+
return (new PhpCsFixer\Config())
12+
->setRules([
13+
'@PSR12' => true,
14+
'@PHP81Migration' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
17+
'no_unused_imports' => true,
18+
'not_operator_with_successor_space' => false,
19+
'trailing_comma_in_multiline' => true,
20+
'phpdoc_scalar' => true,
21+
'unary_operator_spaces' => true,
22+
'binary_operator_spaces' => true,
23+
'blank_line_before_statement' => [
24+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
25+
],
26+
'phpdoc_single_line_var_spacing' => true,
27+
'phpdoc_var_without_name' => true,
28+
'method_argument_space' => [
29+
'on_multiline' => 'ensure_fully_multiline',
30+
'keep_multiple_spaces_after_comma' => true,
31+
],
32+
'single_trait_insert_per_statement' => true,
33+
])
34+
->setFinder($finder)
35+
->setUsingCache(true)
36+
->setRiskyAllowed(true);

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Purephp
22

3+
[![Tests](https://github.com/YonLJ/purephp/workflows/Tests/badge.svg)](https://github.com/YonLJ/purephp/actions)
4+
[![PHP Version](https://img.shields.io/badge/php-%3E%3D8.1-blue.svg)](https://php.net/)
5+
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
6+
37
Purephp is a PHP templating engine inspired by ReactJS functional components.
48

59
## 📖 Documentation

composer.json

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@
1717
]
1818
},
1919
"scripts": {
20-
"test": "phpunit tests/"
20+
"test": "phpunit tests/",
21+
"test-coverage": "phpunit --coverage-html coverage/",
22+
"test-coverage-clover": "phpunit --coverage-clover coverage.xml",
23+
"syntax-check": "find src tests -name '*.php' -exec php -l {} \\;",
24+
"cs-fix": "php-cs-fixer fix",
25+
"cs-check": "php-cs-fixer fix --dry-run --diff",
26+
"phpstan": "phpstan analyse",
27+
"quality": [
28+
"@syntax-check",
29+
"@cs-check",
30+
"@phpstan",
31+
"@test"
32+
]
2133
},
2234
"authors": [
2335
{
@@ -29,7 +41,9 @@
2941
"php": ">=8.1.0"
3042
},
3143
"require-dev": {
32-
"phpunit/phpunit": "^10"
44+
"phpunit/phpunit": "^10",
45+
"friendsofphp/php-cs-fixer": "^3.84",
46+
"phpstan/phpstan": "^2.1"
3347
},
3448
"keywords": [
3549
"php",
@@ -44,7 +58,16 @@
4458
"archive": {
4559
"exclude": [
4660
"tests/",
47-
"examples/"
61+
"examples/",
62+
"site/",
63+
".github/",
64+
".php-cs-fixer.php",
65+
"phpstan.neon",
66+
"phpunit.xml",
67+
".phpunit.cache/",
68+
"coverage/",
69+
"coverage.xml",
70+
".php-cs-fixer.cache"
4871
]
4972
}
5073
}

0 commit comments

Comments
 (0)