Skip to content

Commit ad01de7

Browse files
committed
update: add some new demo codes
1 parent 8f9e816 commit ad01de7

File tree

6 files changed

+116
-8
lines changed

6 files changed

+116
-8
lines changed

app/WebSocket/Test/TestController.php

+14
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,18 @@ public function autoReply(string $data): string
156156
{
157157
return '(home.ar)Recv: ' . $data;
158158
}
159+
160+
/**
161+
* Message command is: 'test.ar'
162+
*
163+
* @MessageMapping("stop-worker")
164+
*/
165+
public function testDie(): void
166+
{
167+
$wid = \server()->getPid('workerId');
168+
169+
\vdump($wid);
170+
171+
\server()->stopWorker($wid);
172+
}
159173
}

app/bean.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@
150150
'log_file' => alias('@runtime/swoole.log'),
151151
],
152152
],
153+
// 'wsConnectionManager' => [
154+
// 'storage' => bean('wsConnectionStorage')
155+
// ],
156+
// 'wsConnectionStorage' => [
157+
// 'class' => \Swoft\Session\SwooleStorage::class,
158+
// ],
153159
/** @see \Swoft\WebSocket\Server\WsMessageDispatcher */
154160
'wsMsgDispatcher' => [
155161
'middlewares' => [
@@ -176,10 +182,4 @@
176182
'cliRouter' => [
177183
// 'disabledGroups' => ['demo', 'test'],
178184
],
179-
'wsConnectionManager' => [
180-
'storage' => bean('wsConnectionStorage')
181-
],
182-
'wsConnectionStorage' => [
183-
'class' => \Swoft\Session\SwooleStorage::class,
184-
],
185185
];

bin/bootstrap.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@
77
* @contact [email protected]
88
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
99
*/
10-
require_once dirname(__DIR__) . '/vendor/autoload.php';
10+
11+
/** @var \Composer\Autoload\ClassLoader $loader */
12+
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
13+
14+
$loader->addPsr4("Swoft\\Cache\\", 'vendor/swoft/cache/src/');
15+
$loader->addPsr4("Swoft\\Swlib\\", 'vendor/swoft/swlib/src/');
16+
$loader->addPsr4("Swoft\\Serialize\\", 'vendor/swoft/serialize/src/');

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ services:
1717
- "18307:18307"
1818
- "18308:18308"
1919
volumes:
20-
- ./:/var/www/swoft
20+
- ./:/var/www/swoft
21+
# - ./:/var/www/swoft:delegated
22+
# - ./:/var/www/swoft:cached
2123
# - ./runtime/ng-conf:/etc/nginx
2224
# - ./runtime/logs:/var/log
2325

test/bootstrap.php

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
*/
1010

1111
define('APP_DEBUG', 1);
12+
13+
$vendor = dirname(__DIR__);
14+
15+
/** @var \Composer\Autoload\ClassLoader $loader */
16+
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
17+
$loader->addPsr4("SwoftTest\\Testing\\", $vendor . '/swoft/framework/test/testing/');

test/run.php

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/** For Swoole coroutine tests */
3+
4+
use PHPUnit\TextUI\Command;
5+
use Swoole\Coroutine;
6+
use Swoole\ExitException;
7+
8+
Coroutine::set([
9+
'log_level' => SWOOLE_LOG_INFO,
10+
'trace_flags' => 0
11+
]);
12+
13+
/*
14+
* This file is part of PHPUnit.
15+
*
16+
* (c) Sebastian Bergmann <[email protected]>
17+
*
18+
* For the full copyright and license information, please view the LICENSE
19+
* file that was distributed with this source code.
20+
*/
21+
if (version_compare('7.1.0', PHP_VERSION, '>')) {
22+
fwrite(STDERR,
23+
sprintf('This version of PHPUnit is supported on PHP 7.1 and PHP 7.2.' . PHP_EOL . 'You are using PHP %s (%s).' . PHP_EOL,
24+
PHP_VERSION, PHP_BINARY));
25+
die(1);
26+
}
27+
28+
if (!ini_get('date.timezone')) {
29+
ini_set('date.timezone', 'UTC');
30+
}
31+
32+
// add loader file
33+
$__loader_file = dirname(__DIR__) . '/vendor/autoload.php';
34+
if (file_exists($__loader_file)) {
35+
define('PHPUNIT_COMPOSER_INSTALL', $__loader_file);
36+
}
37+
38+
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
39+
fwrite(STDERR,
40+
"You need to set up the project dependencies using Composer:\n\n"
41+
. ' composer install' . PHP_EOL . PHP_EOL
42+
. 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL);
43+
die(1);
44+
}
45+
46+
if (array_reverse(explode('/', __DIR__))[0] ?? '' === 'test') {
47+
$vendor_dir = dirname(PHPUNIT_COMPOSER_INSTALL);
48+
$bin_unit = "{$vendor_dir}/bin/phpunit";
49+
$unit_uint = "{$vendor_dir}/phpunit/phpunit/phpunit";
50+
if (file_exists($bin_unit)) {
51+
@unlink($bin_unit);
52+
@symlink(__FILE__, $bin_unit);
53+
}
54+
if (file_exists($unit_uint)) {
55+
@unlink($unit_uint);
56+
@symlink(__FILE__, $unit_uint);
57+
}
58+
}
59+
60+
if (!in_array('-c', $_SERVER['argv'], true)) {
61+
$_SERVER['argv'][] = '-c';
62+
$_SERVER['argv'][] = dirname(__DIR__) . '/phpunit.xml';
63+
}
64+
65+
require PHPUNIT_COMPOSER_INSTALL;
66+
67+
$status = 0;
68+
\Swoft\Co::run(function () {
69+
// Status
70+
global $status;
71+
72+
try {
73+
$status = Command::main(false);
74+
} catch (ExitException $e) {
75+
$status = $e->getCode();
76+
echo 'ExitException: ' . $e->getMessage(), "\n";
77+
}
78+
});
79+
80+
exit($status);

0 commit comments

Comments
 (0)