Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] 3.0 from imiphp:3.0 #185

Merged
merged 16 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions .github/print-logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,20 @@
}
}
}

foreach ([
'connection-center',
'model',
] as $component)
{
echo '[',$component,']', \PHP_EOL;
$fileName = \dirname(__DIR__) . '/src/Components/' . $component . '/tests/.runtime/logs/log-' . date('Y-m-d') . '.log';
if (is_file($fileName))
{
echo file_get_contents($fileName), \PHP_EOL;
}
else
{
echo 'Not found!', \PHP_EOL;
}
}
47 changes: 46 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ jobs:
- name: Test phar
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-phar
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-connection-center
- name: Test database
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-database
- name: Test model
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-model
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
Expand Down Expand Up @@ -189,6 +198,15 @@ jobs:
- name: Test pgsql
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-pgsql
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-connection-center
- name: Test database
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-database
- name: Test model
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-model
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
Expand Down Expand Up @@ -291,6 +309,15 @@ jobs:
- name: Test phar
if: ${{ env.test_prepared && always() }}
run: composer test-phar
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: composer test-connection-center
- name: Test database
if: ${{ env.test_prepared && always() }}
run: composer test-database
- name: Test model
if: ${{ env.test_prepared && always() }}
run: composer test-model
- name: Print logs
if: failure()
run: php .github/print-logs.php
Expand Down Expand Up @@ -421,6 +448,15 @@ jobs:
- name: Test phar
if: ${{ env.test_prepared && always() }}
run: composer test-phar
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: composer test-connection-center
- name: Test database
if: ${{ env.test_prepared && always() }}
run: composer test-database
- name: Test model
if: ${{ env.test_prepared && always() }}
run: composer test-model
- name: Print logs
if: failure()
run: php .github/print-logs.php
Expand Down Expand Up @@ -493,7 +529,7 @@ jobs:
composer update --prefer-dist --no-progress
Write-Output "::endgroup::"
Write-Output "::group::Table Init"
php src\Cli\bin\imi-cli generate/table --app-namespace "Imi\Test\Component"
php src\Cli\bin\imi-cli generate/table --app-namespace "Imi\Model\Test"
Write-Output "::endgroup::"

- name: Install RoadRunner
Expand Down Expand Up @@ -526,6 +562,15 @@ jobs:
- name: Test snowflake
if: ${{ env.test_prepared && always() }}
run: composer test-snowflake
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: composer test-connection-center-common
- name: Test database
if: ${{ env.test_prepared && always() }}
run: composer test-database
- name: Test model
if: ${{ env.test_prepared && always() }}
run: composer test-model
- name: Print logs
if: failure()
run: php .github\print-logs.php
11 changes: 7 additions & 4 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

env:
PHP_VERSION: 8.2

jobs:
test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -105,8 +108,7 @@ jobs:
--health-retries=3
env:
TEST_TYPE: ${{ matrix.testType }}
PHP_VERSION: 8.2
SWOOLE_VERSION: v5.0.3
SWOOLE_VERSION: v5.1.1
ROADRUNNER_VERSION: 2.7.*
IMI_ROADRUNNER_BINARY: ${{ github.workspace }}/rr
AMQP_SERVER_HOST: 127.0.0.1
Expand All @@ -133,12 +135,13 @@ jobs:
coverage: xdebug
extensions: >
apcu, bcmath, curl, openssl, mbstring, intl, json, redis, mysqli, pdo, pdo_mysql, pdo_pgsql,
sockets, zip, inotify, event
sockets, zip, inotify, event, :opcache
swoole-swoole/swoole-src@${{ env.SWOOLE_VERSION }}
- name: Check Version
run: |
php -v
php -m
php --ri xdebug
php --ri swoole
- name: Get composer cache directory
id: composer-cache
Expand Down Expand Up @@ -186,7 +189,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: ${{ env.PHP_VERSION }}
tools: pecl
extensions: >
bcmath, curl, openssl, mbstring, intl, json, sockets, zip, event
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/daily-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ jobs:
- name: Test phar
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-phar
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-connection-center
- name: Test database
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-database
- name: Test model
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-model
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
Expand All @@ -105,10 +114,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.2 ]
php: [8.2]
swoole:
- version: master
roadrunner: [ 2.7.* ]
roadrunner: [2.7.*]
env:
ENV_SERVICE: php
PHP_VERSION: ${{ matrix.php }}
Expand Down Expand Up @@ -185,4 +194,4 @@ jobs:
run: docker exec ${ENV_SERVICE} composer test-phar
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
17 changes: 16 additions & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ jobs:
run: |
docker exec ${ENV_SERVICE} ./dev/phpstan.sh phar

- name: Analyse connection-center
if: ${{ env.test_prepared && always() }}
run: |
docker exec ${ENV_SERVICE} ./dev/phpstan.sh connection-center

- name: Analyse database
if: ${{ env.test_prepared && always() }}
run: |
docker exec ${ENV_SERVICE} ./dev/phpstan.sh database

- name: Analyse model
if: ${{ env.test_prepared && always() }}
run: |
docker exec ${ENV_SERVICE} ./dev/phpstan.sh model

- name: Save All composer.lock And autoloader-suffix
if: ${{ env.test_prepared && always() }}
run: |
Expand All @@ -194,4 +209,4 @@ jobs:
name: phpstan-cache
path: |
/tmp/base_cache/phpstan
!/tmp/base_cache/phpstan/cache/PHPStan/
!/tmp/base_cache/phpstan/cache/PHPStan/
17 changes: 16 additions & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
with:
path: /tmp/base_cache/rector
key: ${{ runner.os }}-rector-${{ env.IMAGE_VERSION }}-${{ github.run_id }}
restore-keys: |
restore-keys: |
${{ runner.os }}-rector-${{ env.IMAGE_VERSION }}-

- name: Analyse core
Expand Down Expand Up @@ -167,3 +167,18 @@ jobs:
if: ${{ env.test_prepared && always() }}
run: |
docker exec -w /imi/src/Components/workerman-gateway ${ENV_SERVICE} /imi/vendor/bin/rector process --dry-run

- name: Analyse connection-center
if: ${{ env.test_prepared && always() }}
run: |
docker exec -w /imi/src/Components/connection-center ${ENV_SERVICE} /imi/vendor/bin/rector process --dry-run

- name: Analyse database
if: ${{ env.test_prepared && always() }}
run: |
docker exec -w /imi/src/Components/database ${ENV_SERVICE} /imi/vendor/bin/rector process --dry-run

- name: Analyse model
if: ${{ env.test_prepared && always() }}
run: |
docker exec -w /imi/src/Components/model ${ENV_SERVICE} /imi/vendor/bin/rector process --dry-run
7 changes: 3 additions & 4 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->notPath('src/Components/grpc/example/grpc')
->notPath('tests/unit/Component/Model/Base')
->notPath('tests/unit/Component/Model/Base')
->notPath('src/Components/pgsql/tests/Model/Base')
->exclude('src/Components/grpc/example/grpc')
->exclude('src/Components/model/tests/Model/Base')
->exclude('src/Components/pgsql/tests/Model/Base')
)
;
18 changes: 15 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"php-cs-fixer/shim": "~3.35.1",
"phpstan/phpstan": "~1.10.39",
"phpunit/phpunit": "~10.4",
"rector/rector": "~0.18.5",
"rector/rector": "~0.19.0",
"symfony/polyfill-uuid": "^1.27",
"yurunsoft/ide-helper": "~1.0",
"yurunsoft/yurun-http": "^5.0.0"
Expand All @@ -52,7 +52,8 @@
},
"files": [
"dev/bootstrap.php",
"tests/helper.php"
"tests/helper.php",
"src/Components/model/vendor/autoload.php"
]
},
"suggest": {
Expand Down Expand Up @@ -111,6 +112,14 @@
"test-smarty": "@php vendor/bin/phpunit -c src/Components/smarty/tests/phpunit.xml",
"test-pgsql": "@php src/Components/swoole/bin/swoole-phpunit -c src/Components/pgsql/tests/phpunit.xml",
"test-phar": "@php src/Components/phar/tests/run-tests.php",
"test-connection-center-common": "@php vendor/bin/phpunit -c src/Components/connection-center/tests/phpunit.xml",
"test-connection-center-swoole": "CONNECTION_CENTER_TEST_MODE=swoole php src/Components/swoole/bin/swoole-phpunit -c src/Components/connection-center/tests/phpunit.xml",
"test-connection-center": [
"@composer test-connection-center-common",
"@composer test-connection-center-swoole"
],
"test-database": "@php vendor/bin/phpunit -c src/Components/database/tests/phpunit.xml",
"test-model": "@php vendor/bin/phpunit -c src/Components/model/tests/phpunit.xml",
"test-components": [
"@composer test-swoole",
"@composer test-workerman",
Expand All @@ -125,7 +134,10 @@
"@composer test-mqtt",
"@composer test-smarty",
"@composer test-pgsql",
"@composer test-phar"
"@composer test-phar",
"@composer test-connection-center",
"@composer test-database",
"@composer test-model"
]
},
"extra": {
Expand Down
20 changes: 17 additions & 3 deletions dev/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

declare(strict_types=1);

use Imi\Config;
use Imi\Core\CoreEvents;
use Imi\Event\Event;
use Imi\Server\Event\ServerEvents;
use Imi\Util\Uri;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;
Expand Down Expand Up @@ -50,11 +53,11 @@ function getRectorConfigCallback(string $path): callable
$rectorConfig->skip([
'*/vendor/*',
$path . '/src/Components/*',
\Rector\Php71\Rector\FuncCall\CountOnNullRector::class,
\Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector::class,
\Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector::class,
\Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector::class, // 调整包含默认值的参数顺序,会导致代码被破坏
\Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector::class, // 常量自动加 final,无法继承覆盖了
\Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector::class, // 自说自话改never真下头
]);

$rectorConfig->bootstrapFiles([
Expand Down Expand Up @@ -105,7 +108,7 @@ function getTestPhpBinary(): string
return $result;
}

return $result . (\extension_loaded('xdebug') ? '' : ' -dzend_extension=xdebug') . ' -dxdebug.mode=coverage';
return $result . (\extension_loaded('xdebug') ? '' : ' -dzend_extension=xdebug') . ' -dxdebug.mode=coverage -dswoole.enable_fiber_mock';
}

/**
Expand All @@ -123,6 +126,7 @@ function getTestPhpBinaryArray(): array
$result[] = '-dzend_extension=xdebug';
}
$result[] = '-dxdebug.mode=coverage';
$result[] = '-dswoole.enable_fiber_mock';
}

return $result;
Expand Down Expand Up @@ -204,8 +208,18 @@ function checkPorts(array $ports, string $host = '127.0.0.1', int $tryCount = 30
}
};

Event::on('IMI.SERVER.WORKER_STOP', $shutdownCallback);
Event::on(ServerEvents::WORKER_STOP, $shutdownCallback);
register_shutdown_function($shutdownCallback);
Event::on(CoreEvents::LOAD_CONFIG, static function (): void {
$config = [];
if (!\extension_loaded('xdebug'))
{
$config[] = '-dzend_extension=xdebug';
}
$config[] = '-dxdebug.mode=coverage';
$config[] = '-dswoole.enable_fiber_mock';
Config::set('@app.imi.phpOptions', $config);
});
})();
}

Expand Down
6 changes: 5 additions & 1 deletion dev/generate-facade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ src/Cli/bin/imi-cli --app-namespace "Imi\Swoole" --bootstrap "src/Components/swo

src/Cli/bin/imi-cli --app-namespace "Imi" generate/facade "Imi\Server\Session\Session" "SessionManager" --request=true && \

vendor/bin/php-cs-fixer fix
src/Cli/bin/imi-cli --app-namespace "Imi\ConnectionCenter" --bootstrap "src/Components/connection-center/vendor/autoload.php" generate/facade "Imi\ConnectionCenter\Facade\ConnectionCenter" "Imi\ConnectionCenter\AppConnectionCenter" && \

dev/rector.sh core jwt queue swoole connection-center && \

vendor/bin/php-cs-fixer fix
3 changes: 3 additions & 0 deletions dev/phpstan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ components=(
"swoole-tracker"
"workerman"
"workerman-gateway"
"connection-center"
"database"
"model"
)

analyze_component() {
Expand Down
3 changes: 3 additions & 0 deletions dev/rector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ components=(
"swoole-tracker"
"workerman"
"workerman-gateway"
"connection-center"
"database"
"model"
)

analyze_component() {
Expand Down
Loading
Loading