2021-06-10 22:34:13 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\TestCase\Service;
|
|
|
|
|
2021-06-13 20:19:47 +00:00
|
|
|
use JKingWeb\Arsse\Service\Daemon;
|
2021-06-10 22:34:13 +00:00
|
|
|
use JKingWeb\Arsse\Service\Exception;
|
|
|
|
use org\bovigo\vfs\vfsStream;
|
|
|
|
|
|
|
|
/** @covers \JKingWeb\Arsse\Service */
|
|
|
|
class TestPID extends \JKingWeb\Arsse\Test\AbstractTest {
|
|
|
|
protected $pidfiles = [
|
|
|
|
'errors' => [
|
|
|
|
'create' => [],
|
|
|
|
'read' => "",
|
|
|
|
'write' => "",
|
|
|
|
'readwrite' => "",
|
|
|
|
],
|
|
|
|
'ok' => [
|
|
|
|
'dir' => [],
|
|
|
|
'file' => "",
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2021-06-13 20:19:47 +00:00
|
|
|
public function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
$this->daemon = $this->partialMock(Daemon::class);
|
|
|
|
}
|
|
|
|
|
2021-06-10 22:34:13 +00:00
|
|
|
/** @dataProvider providePidResolutions */
|
|
|
|
public function testResolvePidFiles(string $file, bool $realpath, $exp): void {
|
|
|
|
$vfs = vfsStream::setup("pidtest", 0777, $this->pidfiles);
|
|
|
|
$path = $vfs->url()."/";
|
|
|
|
// set up access blocks
|
|
|
|
chmod($path."errors/create", 0555);
|
|
|
|
chmod($path."errors/read", 0333);
|
|
|
|
chmod($path."errors/write", 0555);
|
|
|
|
chmod($path."errors/readwrite", 0111);
|
2021-06-13 20:19:47 +00:00
|
|
|
// set up mock daemon class
|
|
|
|
$this->daemon->realPath->returns($realpath ? $path.$file : false);
|
|
|
|
$daemon = $this->daemon->get();
|
2021-06-10 22:34:13 +00:00
|
|
|
// perform the test
|
|
|
|
if ($exp instanceof \Exception) {
|
|
|
|
$this->assertException($exp);
|
2021-06-13 20:19:47 +00:00
|
|
|
$daemon->resolvePID($file);
|
2021-06-10 22:34:13 +00:00
|
|
|
} else {
|
2021-06-13 20:19:47 +00:00
|
|
|
$this->assertSame($exp, $daemon->resolvePID($file));
|
2021-06-10 22:34:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providePidResolutions(): iterable {
|
|
|
|
return [
|
|
|
|
["errors/create", true, new Exception("pidUncreatable")],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|