getMockBuilder(Process::class)->disableOriginalConstructor()->getMock(); $process1 ->method('getPid')->willReturn(1); $process1->stdout = $this->getMockBuilder(ReadableStreamInterface::class)->disableOriginalConstructor()->getMock(); $process1->stdin = $this->getMockBuilder(WritableStreamInterface::class)->disableOriginalConstructor()->getMock(); $process2 = $this->getMockBuilder(Process::class)->disableOriginalConstructor()->getMock(); $process2->stdout = $this->getMockBuilder(ReadableStreamInterface::class)->disableOriginalConstructor()->getMock(); $process2->stdin = $this->getMockBuilder(WritableStreamInterface::class)->disableOriginalConstructor()->getMock(); $process1 ->method('getPid')->willReturn(2); $workerManager->addProcess($process1); $workerManager->addProcess($process2); $this->assertCount(2, $workerManager->getProcesses()); } public function testCanRunWithSuccess() { /** @var WorkerProcessManager $workerManager */ $workerManager = $this->getMockBuilder(WorkerProcessManager::class) ->setMethods(['logInfo','getMemoryUsage','getCpuUsage']) ->disableOriginalConstructor()->getMockForAbstractClass(); $workerManager ->method('getMemoryUsage')->willReturn(50); $workerManager ->method('getCpuUsage')->willReturn(50); $workerManager->setLimitOfMemory(80); $workerManager->setLimitOfCpu(80); $this->assertTrue($workerManager->canRun()); } public function testCanRunFailed() { /** @var WorkerProcessManager $workerManager */ $workerManager = $this->getMockBuilder(WorkerProcessManager::class) ->setMethods(['logInfo','getMemoryUsage','getCpuUsage']) ->disableOriginalConstructor()->getMockForAbstractClass(); $workerManager ->method('getMemoryUsage')->willReturn(90); $workerManager ->method('getCpuUsage')->willReturn(90); $workerManager->setLimitOfMemory(80); $workerManager->setLimitOfCpu(80); $this->assertFalse($workerManager->canRun()); } public function testGetCommand() { $workerManager = new WorkerProcessManager(); $workerManager->setOption(WorkerProcessManager::OPTION_TASK_COMMAND, 'some task'); $this->assertSame('some task', $workerManager->getCommand()); } public function testGetMemoryUsage() { $workerManager = new WorkerProcessManager(); $this->assertIsNumeric($workerManager->getMemoryUsage()); } public function testGetCpuUsage() { $workerManager = new WorkerProcessManager(); $this->assertIsFloat($workerManager->getCpuUsage()); } }