Skip to content

Commit

Permalink
提升测试覆盖率,多项修复和改进 (#518)
Browse files Browse the repository at this point in the history
* 统一静态类声明方式

* 优化代码,完善测试用例

* 优化代码,完善测试用例

* 修复并标记废弃 Imi\Util\DateTime::getLastWeek(),增加 Imi\Util\DateTime::getPrevWeek()

* 修复 DelayServerBeanCallable、DelayBeanCallable 引用返回值,优化代码

* 增加测试

* 修复 Imi\Util\File::enumFile()、Imi\Util\File::enumFileSync() 错误的返回值注释

* 修复 FilterableList

* 修复 Request::getRequestTarget() 错误的值、ServerRequest::post() 不支持非数组、MemoryStream 偏移量处理

* 尝试测试组件覆盖率

* 修复测试

* 修复测试

* 修复测试

* test

* 修复 Swoole 测试覆盖率

* 修复 Imi\Util\Text::endwith()
完善测试

* 修复测试

* test

* test

* test

* test

* test

* 修复 PHP 8.2 兼容性(Creation of dynamic property)

* test

* test

* 增加 Http 验证器测试

* 修复事务嵌套,部分回滚事务

* 优化代码,补充测试,删除无用的类

* 关闭测试热更新

* 增加热更新监视器类测试

* 优化:非 Swoole、Workerman 环境使用 Timer 抛出异常

* 删除无用类

* 修复测试

* 将同步Gitee和组件发版任务设置为并发等待

* 并行测试覆盖率

* test

* test

* test

* test

* test

* test

* test

* test

* test

* 优化模型 DDL 注解的 decode 参数,允许设为 null
增加测试

* test

* test

* 修正变量名,增加测试

* 计划废弃 Imi\Model\ModelManager 类

* test

* test

* test

* 删除无用文件,增加测试

* 修复测试

* 覆盖率测试日志保存到artifact

* 保存最终的覆盖率 xml 文件到 artifact

* 修复测试

* update 补充DB别名测试

* update README.md [no ci]

* 使用缓存

* 修复测试

* 修复测试

* test

* 恢复被注释的测试
性能测试不在覆盖率测试执行

* 修复 roadrunner 并发测试过多时测试失败

* 修复测试

* 修复 roadrunner 并发测试过多时测试失败

---------

Co-authored-by: auooru <[email protected]>
  • Loading branch information
Yurunsoft and NHZEX authored May 20, 2023
1 parent bbdf169 commit d7d6593
Show file tree
Hide file tree
Showing 351 changed files with 4,094 additions and 1,522 deletions.
2 changes: 1 addition & 1 deletion .github/print-logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

echo '[Swoole Component]', \PHP_EOL;
$fileName = \dirname(__DIR__) . '/tests/unit/Component/logs/log-' . date('Y-m-d') . '.log';
$fileName = \dirname(__DIR__) . 'src/Components/swoole/tests/unit/Component/logs/log-' . date('Y-m-d') . '.log';
if (is_file($fileName))
{
echo file_get_contents($fileName), \PHP_EOL;
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,14 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.4, "8.0", "8.1"]
swoole: [v5.0.3, v4.8.11]
php: ["7.4", "8.0", "8.1", "8.2"]
swoole: [v5.0.3, v4.8.13]
roadrunner: [2.7.*]
exclude:
- php: 7.4
swoole: v5.0.3
- php: 8.2
swoole: v4.8.13
env:
MYSQL_SERVER_PASSWORD: "root"
PHP_VERSION: ${{ matrix.php }}
Expand Down Expand Up @@ -405,9 +407,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.4, "8.0", 8.1]
php: ["7.4", "8.0", "8.1"] # 部分扩展还未在 pecl 发布 PHP 8.2 Windows 版扩展,所以无法测试
roadrunner: [2.7.*]

extensions:
[
"apcu, bcmath, curl, openssl, mbstring, intl, json, redis, mysqli, pdo, pdo_mysql, sockets",
]
env:
IMI_ROADRUNNER_BINARY: ${{ github.workspace }}\rr.exe
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -435,7 +440,7 @@ jobs:
php-version: ${{ matrix.php }}
ini-values: session.save_path=C:\temp
tools: pecl
extensions: apcu, bcmath, curl, openssl, mbstring, intl, json, redis, mysqli, pdo, pdo_mysql, sockets
extensions: ${{ matrix.extensions }}
env:
fail-fast: true

Expand Down Expand Up @@ -489,7 +494,7 @@ jobs:
# swoole:
# # - version: v5.0.3
# # postgresql_version: ""
# # - version: v4.8.11
# # - version: v4.8.13
# # postgresql_version: ""
# - version: fix-curl-hook-php8.2
# postgresql_version: ""
Expand Down
233 changes: 77 additions & 156 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ on:
pull_request:

jobs:
tests:
test:
runs-on: ubuntu-latest
strategy:
matrix:
testType: [core, swoole, components]
services:
zookeeper:
image: zookeeper:3.4
Expand Down Expand Up @@ -97,6 +100,7 @@ jobs:
--health-timeout=5s
--health-retries=3
env:
TEST_TYPE: ${{ matrix.testType }}
SWOOLE_VERSION: v5.0.3
ROADRUNNER_VERSION: 2.7.*
IMI_ROADRUNNER_BINARY: ${{ github.workspace }}/rr
Expand All @@ -110,6 +114,7 @@ jobs:
--enable-swoole-json
--enable-swoole-curl
--enable-swoole-pgsql
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -118,18 +123,27 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
tools: pecl
coverage: xdebug
extensions: >
apcu, bcmath, curl, openssl, mbstring, intl, json, redis, mysqli, pdo, pdo_mysql, pdo_pgsql,
sockets, zip, inotify, event, apcu,
sockets, zip, inotify, event
swoole-swoole/swoole-src@${{ env.SWOOLE_VERSION }}
- name: Check Version
run: |
php -v
php -m
php --ri swoole
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache vendor
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Prepare
run: |
printf "127.0.0.1\tkafka1\n" | sudo tee -a /etc/hosts
Expand All @@ -139,160 +153,67 @@ jobs:
PGPASSWORD=root psql -h 127.0.0.1 -d db_imi_test -U root -f ./.github/pgsql.sql
src/Components/roadrunner/vendor/bin/rr get-binary -f $ROADRUNNER_VERSION
./rr -v
echo "test_ready=1" >> $GITHUB_ENV
- name: Run core test suite
timeout-minutes: 5
run: php vendor/bin/phpunit -c ./tests/phpunit.xml --coverage-clover=./core-coverage.xml -v
- name: Run swoole test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 5
run: >
php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/swoole/tests/phpunit.xml
--coverage-clover=./swoole-coverage.xml -v
- name: Run workerman test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/workerman/vendor/bin/phpunit
-c ./src/Components/workerman/tests/phpunit.xml
--coverage-clover=./workerman-coverage.xml -v
- name: Run workerman-gateway test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/workerman-gateway/vendor/bin/phpunit
-c ./src/Components/workerman-gateway/tests/phpunit.xml
--testsuite workerman
--coverage-clover=./workerman-gateway-coverage.xml -v
- name: Run workerman-gateway(swoole) test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/workerman-gateway/vendor/bin/phpunit
-c ./src/Components/workerman-gateway/tests/phpunit.xml
--testsuite swoole
--coverage-clover=./workerman-gateway-swoole-coverage.xml -v
- name: Run roadrunner test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/roadrunner/vendor/bin/phpunit
-c ./src/Components/roadrunner/tests/phpunit.xml
--coverage-clover=./roadrunner-coverage.xml -v
- name: Run fpm test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/fpm/vendor/bin/phpunit
-c ./src/Components/fpm/tests/phpunit.xml
--coverage-clover=./fpm-coverage.xml -v
- name: Run jwt test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/jwt/vendor/bin/phpunit
-c ./src/Components/jwt/tests/phpunit.xml
--coverage-clover=./jwt-coverage.xml -v
- name: Run queue test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/queue/tests/phpunit.xml
--coverage-clover=./queue-coverage.xml -v
- name: Run amqp-swoole test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
AMQP_TEST_MODE=swoole php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/amqp/tests/phpunit.xml
--coverage-clover=./amqp-swoole-coverage.xml -v
- name: Run amqp-workerman test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
AMQP_TEST_MODE=workerman php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/amqp/tests/phpunit.xml
--coverage-clover=./amqp-workerman-coverage.xml -v
- name: Run kafka-swoole test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
KAFKA_TEST_MODE=swoole php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/kafka/tests/phpunit.xml
--coverage-clover=./kafka-swoole-coverage.xml -v
- name: Run kafka-workerman test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
KAFKA_TEST_MODE=workerman php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/kafka/tests/phpunit.xml
--coverage-clover=./kafka-workerman-coverage.xml -v
- name: Run grpc test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/grpc/tests/phpunit.xml
--coverage-clover=./grpc-coverage.xml -v
- name: Run snowflake test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/snowflake/vendor/bin/phpunit
-c ./src/Components/snowflake/tests/phpunit.xml
--coverage-clover=./snowflake-coverage.xml -v
- name: Run mqtt test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/mqtt/tests/phpunit.xml
--coverage-clover=./mqtt-coverage.xml -v
- name: Run smarty test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/smarty/tests/phpunit.xml
--coverage-clover=./smarty-coverage.xml -v
- name: Run pgsql test suite
if: ${{ env.test_ready && always() }}
timeout-minutes: 3
run: >
php src/Components/swoole/bin/swoole-phpunit
-c ./src/Components/pgsql/tests/phpunit.xml
--coverage-clover=./pgsql-coverage.xml -v
- name: Print logs
if: failure()
run: php .github/print-logs.php
- name: Run test suite
id: run-test-suite
run: ./dev/test-coverage-actions.sh php $TEST_TYPE
- name: Upload coverage file
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.testType }}-coverage
path: tests/coverage.php
- name: Upload log files
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.testType }}-logs
path: |
tests/unit/Component/logs/*.log
src/Components/*/tests/*/*/logs/*.log
src/Components/*/example/.runtime/logs/*.log
upload-coverage:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
tools: pecl
extensions: >
bcmath, curl, openssl, mbstring, intl, json, sockets, zip, event
- name: Check Version
run: |
php -v
php -m
- name: Prepare
run: |
composer update --prefer-dist --no-progress
mkdir -p ./dev/cover
- name: Download core coverage
uses: actions/download-artifact@v3
with:
name: core-coverage
path: ./dev/cover/core-coverage.php
- name: Download swoole coverage
uses: actions/download-artifact@v3
with:
name: swoole-coverage
path: ./dev/cover/swoole-coverage.php
- name: Download components coverage
uses: actions/download-artifact@v3
with:
name: components-coverage
path: ./dev/cover/components-coverage.php
- name: Parse coverage data
run: php ./dev/merge-coverage.php clover
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: "./core-coverage.xml,\
./swoole-coverage.xml,\
./workerman-coverage.xml,\
./workerman-gateway-coverage.xml,\
./workerman-gateway-swoole-coverage.xml,\
./roadrunner-coverage.xml,\
./fpm-coverage.xml,\
./jwt-coverage.xml,\
./queue-coverage.xml,\
./amqp-swoole-coverage.xml,\
./amqp-workerman-coverage.xml,\
./kafka-swoole-coverage.xml,\
./kafka-workerman-coverage.xml,\
./grpc-coverage.xml,\
./amqp-swoole-coverage.xml,\
./amqp-workerman-coverage.xml,\
./kafka-swoole-coverage.xml,\
./kafka-workerman-coverage.xml,\
./grpc-coverage.xml,\
./snowflake-coverage.xml,\
./mqtt-coverage.xml,\
./smarty-coverage.xml,\
./pgsql-coverage.xml"
flags: unittests
name: umbrella
file: "./tests/coverage.xml"
- name: Upload coverage reports to artifact
uses: actions/upload-artifact@v3
with:
name: coverage
path: tests/coverage.xml
1 change: 1 addition & 0 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
jobs:
gitee:
if: github.repository == 'imiphp/imi' && (github.ref == 'refs/heads/2.1')
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-20.04
steps:
- name: Configure Private Key
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/split-repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ name: split repository
on:
push:
branches:
- '2.1'
- "2.1"
release:
types: [published]

jobs:
split-repository:
if: github.repository == 'imiphp/imi'
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ composer.lock
*.macro.php
/.phpbench
/node_modules
/tests/clover.xml
/tests/html-coverage
/dev/cover
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[![imi Doc](https://img.shields.io/badge/docs-passing-green.svg)](https://doc.imiphp.com/v2.1/)
[![imi License](https://img.shields.io/badge/license-MulanPSL%202.0-brightgreen.svg)](https://github.com/imiphp/imi/blob/master/LICENSE)
[![star](https://gitee.com/yurunsoft/IMI/badge/star.svg?theme=gvp)](https://gitee.com/yurunsoft/IMI/stargazers)
[![codecov](https://codecov.io/github/imiphp/imi/branch/dev/graph/badge.svg?token=YrNRQgbRe2)](https://codecov.io/github/imiphp/imi)
[![codecov](https://codecov.io/github/imiphp/imi/branch/2.1/graph/badge.svg?token=YrNRQgbRe2)](https://codecov.io/github/imiphp/imi)

## 介绍

Expand Down
Loading

0 comments on commit d7d6593

Please sign in to comment.