File tree 19 files changed +353
-25
lines changed
19 files changed +353
-25
lines changed Original file line number Diff line number Diff line change @@ -27,4 +27,9 @@ public function myMethod(): array
27
27
28
28
return ['hi ' ];
29
29
}
30
+
31
+ public function myMethod2 (): string
32
+ {
33
+ return __METHOD__ ;
34
+ }
30
35
}
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /**
3
+ * This file is part of Swoft.
4
+ *
5
+ * @link https://swoft.org
6
+ * @document https://swoft.org/docs
7
+
8
+ * @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9
+ */
10
+
11
+ namespace App \Http \Controller ;
12
+
13
+ use App \Process \MonitorProcess ;
14
+ use Swoft \Http \Server \Annotation \Mapping \Controller ;
15
+ use Swoft \Http \Server \Annotation \Mapping \RequestMapping ;
16
+ use function bean ;
17
+ use function vdump ;
18
+
19
+ /**
20
+ * Class ProcController
21
+ *
22
+ * @since 2.0
23
+ *
24
+ * @Controller()
25
+ */
26
+ class ProcController
27
+ {
28
+ /**
29
+ * @RequestMapping("test")
30
+ *
31
+ * @return string
32
+ */
33
+ public function test (): string
34
+ {
35
+ $ mp = bean (MonitorProcess::class);
36
+ vdump ($ mp ->getSwooleProcess ()->exportSocket ());
37
+
38
+ return 'hello ' ;
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -34,19 +34,20 @@ class MonitorLogic
34
34
*/
35
35
public function monitor (Process $ process ): void
36
36
{
37
- $ process ->name ('swoft-monitor ' );
37
+ // \vdump($process->exportSocket());
38
+ // $process->name('swoft-monitor');
38
39
39
40
while (true ) {
40
41
$ connections = context ()->getServer ()->getSwooleServer ()->connections ;
41
42
CLog::info ('monitor = ' . json_encode ($ connections ));
42
43
43
44
// Database
44
- $ user = User::find (1 )->toArray ();
45
- CLog::info ('user= ' . json_encode ($ user ));
46
-
47
- // Redis
48
- Redis::set ('test ' , 'ok ' );
49
- CLog::info ('test= ' . Redis::get ('test ' ));
45
+ // $user = User::find(1)->toArray();
46
+ // CLog::info('user=' . json_encode($user));
47
+ //
48
+ // // Redis
49
+ // Redis::set('test', 'ok');
50
+ // CLog::info('test=' . Redis::get('test'));
50
51
51
52
Coroutine::sleep (3 );
52
53
}
Original file line number Diff line number Diff line change 41
41
// 'tcp' => bean('tcpServer'),
42
42
],
43
43
'process ' => [
44
- // 'monitor' => bean(MonitorProcess::class)
45
- // 'crontab' => bean(CrontabProcess::class)
44
+ // 'monitor' => bean(\App\Process\ MonitorProcess::class)
45
+ // 'crontab' => bean(CrontabProcess::class)
46
46
],
47
47
'on ' => [
48
- // SwooleEvent::TASK => bean(SyncTaskListener::class), // Enable sync task
48
+ // SwooleEvent::TASK => bean(SyncTaskListener::class), // Enable sync task
49
49
SwooleEvent::TASK => bean (TaskListener::class), // Enable task must task and finish event
50
50
SwooleEvent::FINISH => bean (FinishListener::class)
51
51
],
130
130
],
131
131
'rpcServer ' => [
132
132
'class ' => ServiceServer::class,
133
+ 'listener ' => [
134
+ 'http ' => bean ('httpServer ' ),
135
+ ]
133
136
],
134
137
'wsServer ' => [
135
138
'class ' => WebSocketServer::class,
Original file line number Diff line number Diff line change 8
8
convertWarningsToExceptions =" true"
9
9
processIsolation =" false"
10
10
stopOnFailure =" false" >
11
- <testsuites >
12
- <testsuite name =" Tests" >
13
- <directory suffix =" Test.php" >./test</directory >
14
- </testsuite >
15
- </testsuites >
16
- <filter >
17
- <whitelist processUncoveredFilesFromWhitelist =" true" >
18
- <directory suffix =" .php" >./app</directory >
19
- </whitelist >
20
- </filter >
11
+ <testsuites >
12
+ <testsuite name =" unitTests" >
13
+ <directory suffix =" Test.php" >./test/unit</directory >
14
+ </testsuite >
15
+ <testsuite name =" apiTests" >
16
+ <directory suffix =" Test.php" >./test/api</directory >
17
+ </testsuite >
18
+ </testsuites >
19
+ <filter >
20
+ <whitelist processUncoveredFilesFromWhitelist =" true" >
21
+ <directory suffix =" .php" >./app</directory >
22
+ </whitelist >
23
+ </filter >
21
24
</phpunit >
Original file line number Diff line number Diff line change
1
+ # Tests
2
+
3
+ ## Http tests
4
+
5
+ ** If you want to run http client tests, you must start the http server.**
6
+
7
+ ### Run http tests
8
+
9
+ Can only be run inside phpstorm.
10
+
11
+ ![ http-client-tests] ( testdata/http-client-tests.png )
12
+
13
+ ## API tests
14
+
15
+ ** If you want to run api tests, you must start the http server.**
16
+
17
+ ## Start server
18
+
19
+ ``` bash
20
+ php bin/swoft http:start
21
+ # OR
22
+ php bin/swoft http:start -d
23
+ ```
24
+
25
+ ### Run api tests
26
+
27
+ - use vendor phpunit
28
+
29
+ ``` bash
30
+ vendor/bin/phpunit --testsuite apiTests
31
+ ```
32
+
33
+ - use global installed phpunit
34
+
35
+ ``` bash
36
+ phpunit --testsuite apiTests
37
+ ```
38
+
39
+ ## Unit tests
40
+
41
+ ### Run unit tests
42
+
43
+ - use vendor phpunit
44
+
45
+ ``` bash
46
+ vendor/bin/phpunit --testsuite unitTests
47
+ ```
48
+
49
+ - use global installed phpunit
50
+
51
+ ``` bash
52
+ phpunit --testsuite unitTests
53
+ ```
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /**
3
+ * This file is part of Swoft.
4
+ *
5
+ * @link https://swoft.org
6
+ * @document https://swoft.org/docs
7
+
8
+ * @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9
+ */
10
+
11
+ namespace AppTest \Api ;
12
+
13
+ use PHPUnit \Framework \TestCase ;
14
+ use Swoft \Swlib \HttpClient ;
15
+
16
+ /**
17
+ * Class ExampleApiTest
18
+ *
19
+ * @package AppTest\Api
20
+ */
21
+ class ExampleApiTest extends TestCase
22
+ {
23
+ /**
24
+ * @var HttpClient
25
+ */
26
+ private $ http ;
27
+
28
+ public function setUp (): void
29
+ {
30
+ $ this ->http = new HttpClient ();
31
+ }
32
+
33
+ public function testHi (): void
34
+ {
35
+ $ w = $ this ->http ->get ('http://127.0.0.1/hi ' );
36
+
37
+ $ this ->assertSame ('hi ' , $ w ->getBody ()->getContents ());
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ # Http tests
2
+
3
+ ** If you want to run these tests, you must start the http server.**
4
+
5
+ ## Start server
6
+
7
+ ``` bash
8
+ php bin/swoft http:start
9
+ ```
Original file line number Diff line number Diff line change 8
8
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9
9
*/
10
10
11
- use SwoftTest \Testing \TestApplication ;
11
+ use AppTest \Testing \TestApplication ;
12
12
13
13
$ baseDir = dirname (__DIR__ );
14
14
$ vendor = dirname (__DIR__ ) . '/vendor ' ;
15
15
16
16
/** @var \Composer\Autoload\ClassLoader $loader */
17
17
$ loader = require dirname (__DIR__ ) . '/vendor/autoload.php ' ;
18
- $ loader ->addPsr4 ('SwoftTest \\Testing \\' , $ vendor . '/swoft/framework/test/testing/ ' );
19
18
20
- $ application = new TestApplication ($ baseDir );
21
- $ application ->setBeanFile ($ baseDir . '/app/bean.php ' );
22
- $ application ->run ();
19
+ $ swoftFwDir = $ vendor . '/swoft/framework ' ;
20
+
21
+ // in framework developing
22
+ if (file_exists ($ vendor . '/swoft/component/src/framework ' )) {
23
+ $ swoftFwDir = $ vendor . '/swoft/component/src/framework ' ;
24
+ }
25
+
26
+ $ loader ->addPsr4 ('AppTest \\Unit \\' , $ baseDir . '/test/unit/ ' );
27
+ $ loader ->addPsr4 ('AppTest \\Testing \\' , $ baseDir . '/test/testing/ ' );
28
+ $ loader ->addPsr4 ('SwoftTest \\Testing \\' , $ swoftFwDir . '/test/testing/ ' );
29
+
30
+ $ app = new TestApplication ($ baseDir );
31
+ $ app ->run ();
Original file line number Diff line number Diff line change
1
+ If you want run api test, must start an server before run tests.
Original file line number Diff line number Diff line change
1
+ # Http tests
2
+
3
+ ** If you want to run these tests, you must start the http server.**
4
+
5
+ ## Config
6
+
7
+ Please see http-client.env.json
8
+
9
+ ## Start server
10
+
11
+ ``` bash
12
+ php bin/swoft http:start
13
+ ```
14
+
15
+ ## Run
16
+
17
+ Can only be run inside phpstorm
Original file line number Diff line number Diff line change
1
+ {
2
+ "development" : {
3
+ "host" : " 127.0.0.1:10106" ,
4
+ "bid" : 10006 ,
5
+ "id-value" : 12345 ,
6
+ "username" : " " ,
7
+ "password" : " " ,
8
+ "my-var" : " my-dev-value" ,
9
+ "form-type" : " application/x-www-form-urlencoded"
10
+ },
11
+ "testing" : {
12
+ "host" : " " ,
13
+ "bid" : 10001 ,
14
+ "id-value" : 12345 ,
15
+ "username" : " " ,
16
+ "password" : " " ,
17
+ "my-var" : " my-dev-value" ,
18
+ "form-type" : " application/x-www-form-urlencoded"
19
+ },
20
+ "production" : {
21
+ "host" : " example.com" ,
22
+ "bid" : 10001 ,
23
+ "id-value" : 6789 ,
24
+ "username" : " " ,
25
+ "password" : " " ,
26
+ "my-var" : " my-prod-value"
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ ### test api
2
+ GET http://{{host}}/hi
3
+ Accept: text/plain
4
+
5
+ ### test api2
6
+ GET http://{{host}}/hello
7
+ Accept: text/plain
8
+
9
+ ###
Original file line number Diff line number Diff line change
1
+ storage same temp files for tests
You can’t perform that action at this time.
0 commit comments