ProcessManagerTest.php 1.4 KB

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