Skip to content

Commit ef9cd64

Browse files
authored
Resume exit channel by coordinator after running phpunit. (#4227)
1 parent 4013d31 commit ef9cd64

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

co-phpunit

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,21 @@ declare (strict_types=1);
99
* For the full copyright and license information, please view the LICENSE
1010
* file that was distributed with this source code.
1111
*/
12+
if (!version_compare(PHP_VERSION, PHP_VERSION, '=')) {
13+
fwrite(STDERR, sprintf('%s declares an invalid value for PHP_VERSION.' . PHP_EOL . 'This breaks fundamental functionality such as version_compare().' . PHP_EOL . 'Please use a different PHP interpreter.' . PHP_EOL, PHP_BINARY));
14+
die(1);
15+
}
1216
if (version_compare('7.3.0', PHP_VERSION, '>')) {
1317
fwrite(STDERR, sprintf('This version of PHPUnit requires PHP >= 7.3.' . PHP_EOL . 'You are using PHP %s (%s).' . PHP_EOL, PHP_VERSION, PHP_BINARY));
1418
die(1);
1519
}
20+
foreach (['dom', 'json', 'libxml', 'mbstring', 'tokenizer', 'xml', 'xmlwriter'] as $extension) {
21+
if (extension_loaded($extension)) {
22+
continue;
23+
}
24+
fwrite(STDERR, sprintf('PHPUnit requires the "%s" extension.' . PHP_EOL, $extension));
25+
die(1);
26+
}
1627
if (!ini_get('date.timezone')) {
1728
ini_set('date.timezone', 'UTC');
1829
}
@@ -40,5 +51,6 @@ Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL, 'exit_condition' => func
4051
Swoole\Coroutine\run(function () use(&$code) {
4152
$code = PHPUnit\TextUI\Command::main(false);
4253
Swoole\Timer::clearAll();
54+
Hyperf\Coordinator\CoordinatorManager::until(Hyperf\Coordinator\Constants::WORKER_EXIT)->resume();
4355
});
4456
die($code);

src/Client.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,21 @@
3434

3535
class Client extends Server
3636
{
37-
/**
38-
* @var PackerInterface
39-
*/
40-
protected $packer;
37+
protected PackerInterface $packer;
4138

42-
/**
43-
* @var float
44-
*/
45-
protected $waitTimeout = 10.0;
39+
protected float $waitTimeout = 10.0;
4640

47-
/**
48-
* @var string
49-
*/
50-
protected $baseUri = 'http://127.0.0.1/';
41+
protected string $baseUri = 'http://127.0.0.1/';
5142

5243
public function __construct(ContainerInterface $container, PackerInterface $packer = null, $server = 'http')
5344
{
54-
parent::__construct($container, $container->get(HttpDispatcher::class), $container->get(ExceptionHandlerDispatcher::class), $container->get(ResponseEmitter::class));
45+
parent::__construct(
46+
$container,
47+
$container->get(HttpDispatcher::class),
48+
$container->get(ExceptionHandlerDispatcher::class),
49+
$container->get(ResponseEmitter::class)
50+
);
51+
5552
$this->packer = $packer ?? new JsonPacker();
5653

5754
$this->initCoreMiddleware($server);

src/HttpClient.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,12 @@
2121

2222
class HttpClient
2323
{
24-
/**
25-
* @var ContainerInterface
26-
*/
27-
protected $container;
28-
29-
/**
30-
* @var Client
31-
*/
32-
protected $client;
33-
34-
/**
35-
* @var PackerInterface
36-
*/
37-
protected $packer;
38-
39-
public function __construct(ContainerInterface $container, PackerInterface $packer = null, $baseUri = 'http://127.0.0.1:9501')
24+
protected Client $client;
25+
26+
protected PackerInterface $packer;
27+
28+
public function __construct(protected ContainerInterface $container, PackerInterface $packer = null, $baseUri = 'http://127.0.0.1:9501')
4029
{
41-
$this->container = $container;
4230
$this->packer = $packer ?? new JsonPacker();
4331
$handler = null;
4432
if (Coroutine::inCoroutine()) {

0 commit comments

Comments
 (0)