Skip to content

Commit b323625

Browse files
committed
Add: process manager tests
1 parent fee0a85 commit b323625

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

tests/Lib/TestProcess.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
4+
namespace EasySwoole\Component\Tests\Lib;
5+
6+
7+
use EasySwoole\Component\Process\AbstractProcess;
8+
9+
class TestProcess extends AbstractProcess
10+
{
11+
protected function run($arg)
12+
{
13+
// TODO: Implement run() method.
14+
}
15+
}

tests/ProcessManagerTest.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
4+
use EasySwoole\Component\Process\Config;
5+
use EasySwoole\Component\Tests\Lib\TestProcess;
6+
use PHPUnit\Framework\TestCase;
7+
use EasySwoole\Component\Process\Manager;
8+
9+
class ProcessManagerTest extends TestCase
10+
{
11+
12+
13+
public function testGetProcessByPid()
14+
{
15+
$config = new Config();
16+
$process = new TestProcess($config);
17+
Manager::getInstance()->addProcess($process);
18+
19+
$this->assertEquals(null, Manager::getInstance()->getProcessByPid(0));
20+
}
21+
22+
public function testGetProcessByName()
23+
{
24+
$process = new TestProcess();
25+
Manager::getInstance()->addProcess($process);
26+
$this->assertEmpty(Manager::getInstance()->getProcessByName('test'));
27+
28+
29+
$config = new Config();
30+
$process = new TestProcess($config);
31+
$config->setProcessName('test');
32+
Manager::getInstance()->addProcess($process);
33+
$this->assertEquals(1, count(Manager::getInstance()->getProcessByName('test')));
34+
}
35+
36+
public function testGetProcessByGroup()
37+
{
38+
$process = new TestProcess();
39+
Manager::getInstance()->addProcess($process);
40+
$this->assertEmpty(Manager::getInstance()->getProcessByGroup('test'));
41+
42+
43+
$config = new Config();
44+
$process = new TestProcess($config);
45+
$config->setProcessGroup('test');
46+
Manager::getInstance()->addProcess($process);
47+
$this->assertEquals(1, count(Manager::getInstance()->getProcessByGroup('test')));
48+
}
49+
}

0 commit comments

Comments
 (0)