mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Fix co-phpunit and co-pest, optimize ci workflows (#5825)
This commit is contained in:
parent
9e850b336c
commit
f0145b8177
1
.github/workflows/test.yml
vendored
1
.github/workflows/test.yml
vendored
@ -29,6 +29,7 @@ jobs:
|
||||
- name: Run CS Fix
|
||||
run: vendor/bin/php-cs-fixer fix src --dry-run
|
||||
tests:
|
||||
needs: cs-fix
|
||||
name: Test on PHP${{ matrix.php-version }} Swoole-${{ matrix.sw-version }}
|
||||
runs-on: "${{ matrix.os }}"
|
||||
strategy:
|
||||
|
37
bin/co-pest
37
bin/co-pest
@ -1,14 +1,6 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
use Pest\Kernel;
|
||||
use Pest\Panic;
|
||||
use Pest\TestCaseFilters\GitDirtyTestCaseFilter;
|
||||
@ -16,23 +8,22 @@ use Pest\TestCaseMethodFilters\TodoTestCaseFilter;
|
||||
use Pest\TestSuite;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
(function () {
|
||||
$prepend = null;
|
||||
foreach ($_SERVER['argv'] as $index => $argv) {
|
||||
foreach ($_SERVER["argv"] as $index => $argv) {
|
||||
// --prepend /path/to/file
|
||||
if ($argv === '--prepend') {
|
||||
unset($_SERVER['argv'][$index]);
|
||||
if (isset($_SERVER['argv'][$index + 1])) {
|
||||
$prepend = $_SERVER['argv'][$index + 1];
|
||||
unset($_SERVER['argv'][$index + 1]);
|
||||
if ($argv === "--prepend") {
|
||||
unset($_SERVER["argv"][$index]);
|
||||
if (isset($_SERVER["argv"][$index + 1])) {
|
||||
$prepend = $_SERVER["argv"][$index + 1];
|
||||
unset($_SERVER["argv"][$index + 1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// --prepend=/path/to/file
|
||||
if (strpos($argv, '--prepend=') === 0) {
|
||||
if (strpos($argv, "--prepend=") === 0) {
|
||||
$prepend = substr($argv, 10);
|
||||
unset($_SERVER['argv'][$index]);
|
||||
unset($_SERVER["argv"][$index]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -41,10 +32,10 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
}
|
||||
})();
|
||||
$code = 0;
|
||||
Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL, 'exit_condition' => function () {
|
||||
return Swoole\Coroutine::stats()['coroutine_num'] === 0;
|
||||
Swoole\Coroutine::set(["hook_flags" => SWOOLE_HOOK_ALL, "exit_condition" => function () {
|
||||
return Swoole\Coroutine::stats()["coroutine_num"] === 0;
|
||||
}]);
|
||||
Swoole\Coroutine\run(function () use (&$code) {
|
||||
Swoole\Coroutine\run(function () use(&$code) {
|
||||
try {
|
||||
$code = (static function () {
|
||||
// Ensures Collision's Printer is registered.
|
||||
@ -116,4 +107,4 @@ Swoole\Coroutine\run(function () use (&$code) {
|
||||
Swoole\Timer::clearAll();
|
||||
Hyperf\Coordinator\CoordinatorManager::until(Hyperf\Coordinator\Constants::WORKER_EXIT)->resume();
|
||||
});
|
||||
exit($code);
|
||||
die($code);
|
@ -45,26 +45,29 @@ if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
|
||||
fwrite(STDERR, 'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . ' composer install' . PHP_EOL . PHP_EOL . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL);
|
||||
die(1);
|
||||
}
|
||||
if (!isset(getopt('', ['prepend:'])['prepend'])) {
|
||||
(function () {
|
||||
$prepend = null;
|
||||
foreach ($_SERVER['argv'] as $index => $argv) {
|
||||
// --prepend /path/to/file
|
||||
if ($argv === '--prepend') {
|
||||
$prepend = $_SERVER['argv'][$index + 1] ?? null;
|
||||
break;
|
||||
}
|
||||
// --prepend=/path/to/file
|
||||
if (strpos($argv, '--prepend=') === 0) {
|
||||
$prepend = substr($argv, 10);
|
||||
break;
|
||||
(function () {
|
||||
$prepend = null;
|
||||
foreach ($_SERVER["argv"] as $index => $argv) {
|
||||
// --prepend /path/to/file
|
||||
if ($argv === "--prepend") {
|
||||
unset($_SERVER["argv"][$index]);
|
||||
if (isset($_SERVER["argv"][$index + 1])) {
|
||||
$prepend = $_SERVER["argv"][$index + 1];
|
||||
unset($_SERVER["argv"][$index + 1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($prepend !== null && file_exists($prepend)) {
|
||||
require $prepend;
|
||||
// --prepend=/path/to/file
|
||||
if (strpos($argv, "--prepend=") === 0) {
|
||||
$prepend = substr($argv, 10);
|
||||
unset($_SERVER["argv"][$index]);
|
||||
break;
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
if ($prepend !== null && file_exists($prepend)) {
|
||||
require $prepend;
|
||||
}
|
||||
})();
|
||||
require PHPUNIT_COMPOSER_INSTALL;
|
||||
$code = 0;
|
||||
Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL, 'exit_condition' => function () {
|
||||
|
@ -112,5 +112,5 @@ $code = ltrim($code, '?>' . PHP_EOL);
|
||||
|
||||
file_put_contents($coPest = __DIR__ . '/co-pest', $code);
|
||||
chmod($coPest, 0755);
|
||||
file_put_contents($coPest = __DIR__ . '/../src/testing/co-pest', $code);
|
||||
file_put_contents($coPest = __DIR__ . '/../src/testing/bin/co-pest', $code);
|
||||
chmod($coPest, 0755);
|
||||
|
@ -74,28 +74,31 @@ class RunInCoroutineVisitor extends NodeVisitorAbstract
|
||||
|
||||
protected function getPrependSetter(): array
|
||||
{
|
||||
return $this->parser->parse("<?php
|
||||
if (!isset(getopt('', ['prepend:'])['prepend'])) {
|
||||
(function () {
|
||||
\$prepend = null;
|
||||
foreach (\$_SERVER['argv'] as \$index => \$argv) {
|
||||
// --prepend /path/to/file
|
||||
if (\$argv === '--prepend') {
|
||||
\$prepend = \$_SERVER['argv'][\$index + 1] ?? null;
|
||||
break;
|
||||
}
|
||||
// --prepend=/path/to/file
|
||||
if (strpos(\$argv, '--prepend=') === 0) {
|
||||
\$prepend = substr(\$argv, 10);
|
||||
break;
|
||||
return $this->parser->parse('<?php
|
||||
(function () {
|
||||
$prepend = null;
|
||||
foreach ($_SERVER["argv"] as $index => $argv) {
|
||||
// --prepend /path/to/file
|
||||
if ($argv === "--prepend") {
|
||||
unset($_SERVER["argv"][$index]);
|
||||
if (isset($_SERVER["argv"][$index + 1])) {
|
||||
$prepend = $_SERVER["argv"][$index + 1];
|
||||
unset($_SERVER["argv"][$index + 1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (\$prepend !== null && file_exists(\$prepend)) {
|
||||
require \$prepend;
|
||||
// --prepend=/path/to/file
|
||||
if (strpos($argv, "--prepend=") === 0) {
|
||||
$prepend = substr($argv, 10);
|
||||
unset($_SERVER["argv"][$index]);
|
||||
break;
|
||||
}
|
||||
})();
|
||||
}
|
||||
");
|
||||
}
|
||||
if ($prepend !== null && file_exists($prepend)) {
|
||||
require $prepend;
|
||||
}
|
||||
})();
|
||||
');
|
||||
}
|
||||
|
||||
protected function getCoroutineSetter(): array
|
||||
|
@ -19,6 +19,7 @@ use Hyperf\Database\Model\Events\Saved;
|
||||
use Hyperf\Database\Model\Model;
|
||||
use Hyperf\Database\Model\SoftDeletes;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
use function Hyperf\Support\class_uses_recursive;
|
||||
|
||||
class ModelObserver
|
||||
|
@ -19,6 +19,8 @@ use Hyperf\Scout\Event\ModelsFlushed;
|
||||
use Hyperf\Scout\Event\ModelsImported;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
class SearchableScope implements Scope
|
||||
{
|
||||
/**
|
||||
|
@ -45,26 +45,29 @@ if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
|
||||
fwrite(STDERR, 'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . ' composer install' . PHP_EOL . PHP_EOL . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL);
|
||||
die(1);
|
||||
}
|
||||
if (!isset(getopt('', ['prepend:'])['prepend'])) {
|
||||
(function () {
|
||||
$prepend = null;
|
||||
foreach ($_SERVER['argv'] as $index => $argv) {
|
||||
// --prepend /path/to/file
|
||||
if ($argv === '--prepend') {
|
||||
$prepend = $_SERVER['argv'][$index + 1] ?? null;
|
||||
break;
|
||||
}
|
||||
// --prepend=/path/to/file
|
||||
if (strpos($argv, '--prepend=') === 0) {
|
||||
$prepend = substr($argv, 10);
|
||||
break;
|
||||
(function () {
|
||||
$prepend = null;
|
||||
foreach ($_SERVER["argv"] as $index => $argv) {
|
||||
// --prepend /path/to/file
|
||||
if ($argv === "--prepend") {
|
||||
unset($_SERVER["argv"][$index]);
|
||||
if (isset($_SERVER["argv"][$index + 1])) {
|
||||
$prepend = $_SERVER["argv"][$index + 1];
|
||||
unset($_SERVER["argv"][$index + 1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($prepend !== null && file_exists($prepend)) {
|
||||
require $prepend;
|
||||
// --prepend=/path/to/file
|
||||
if (strpos($argv, "--prepend=") === 0) {
|
||||
$prepend = substr($argv, 10);
|
||||
unset($_SERVER["argv"][$index]);
|
||||
break;
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
if ($prepend !== null && file_exists($prepend)) {
|
||||
require $prepend;
|
||||
}
|
||||
})();
|
||||
require PHPUNIT_COMPOSER_INSTALL;
|
||||
$code = 0;
|
||||
Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL, 'exit_condition' => function () {
|
||||
|
@ -32,6 +32,9 @@
|
||||
"hyperf/utils": "~3.1.0",
|
||||
"symfony/http-foundation": "^5.4|^6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"pestphp/pest": "For testing with Pest"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.0-dev"
|
||||
@ -39,6 +42,6 @@
|
||||
},
|
||||
"bin": [
|
||||
"co-phpunit",
|
||||
"co-pest"
|
||||
"bin/co-pest"
|
||||
]
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ use Hyperf\Stringable\Str;
|
||||
use Hyperf\Testing\Assert as PHPUnit;
|
||||
use JsonSerializable;
|
||||
|
||||
use function Hyperf\Collection\data_get;
|
||||
|
||||
class AssertableJsonString implements ArrayAccess, Countable
|
||||
{
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user