13 use \PHPUnit_Framework_MockObject_MockObject as MockObject;
20 private $filesystemMock;
25 private $pidConsumerManager;
32 require_once
__DIR__ .
'/../../../_files/pid_consumer_functions_mocks.php';
34 $this->filesystemMock = $this->getMockBuilder(Filesystem::class)
35 ->disableOriginalConstructor()
47 public function testIsRun($fileExists, $pid, $expectedResult)
49 $pidFilePath =
'somepath/consumerName.pid';
52 $directoryMock = $this->getMockBuilder(ReadInterface::class)
53 ->getMockForAbstractClass();
54 $directoryMock->expects($this->once())
56 ->willReturn($fileExists);
57 $directoryMock->expects($this->any())
62 $this->filesystemMock->expects($this->once())
63 ->method(
'getDirectoryRead')
65 ->willReturn($directoryMock);
67 $this->assertSame($expectedResult, $this->pidConsumerManager->isRun($pidFilePath));
76 [
'fileExists' =>
false,
'pid' =>
null,
false],
77 [
'fileExists' =>
false,
'pid' => 11111,
false],
78 [
'fileExists' =>
true,
'pid' => 11111,
true],
79 [
'fileExists' =>
true,
'pid' => 77777,
false],
83 public function testSavePid()
85 $pidFilePath =
'/var/somePath/pidfile.pid';
88 $writeMock = $this->getMockBuilder(WriteInterface::class)
89 ->getMockForAbstractClass();
90 $this->filesystemMock->expects($this->once())
91 ->method(
'getDirectoryWrite')
93 ->willReturn($writeMock);
94 $writeMock->expects($this->once())
102 $this->pidConsumerManager->savePid($pidFilePath);
defined('TESTS_BP')||define('TESTS_BP' __DIR__