1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Start on PI(D file resolution tests

This commit is contained in:
J. King 2021-06-09 19:49:34 -04:00
parent e8cab78bd6
commit 55acb87577
2 changed files with 47 additions and 1 deletions

View file

@ -352,8 +352,12 @@ USAGE_TEXT;
throw new CLI\Exception("pidUncreatable", ['pidfile' => $out]); throw new CLI\Exception("pidUncreatable", ['pidfile' => $out]);
} }
} else { } else {
throw new \Exception("pidDirNotFound", ['piddir' => $dir]); throw new CLI\Exception("pidDirNotFound", ['piddir' => $dir]);
} }
return $out; return $out;
} }
protected function realpath(string $path) {
return @realpath($path);
}
} }

View file

@ -13,12 +13,27 @@ use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Database; use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Service; use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\CLI; use JKingWeb\Arsse\CLI;
use JKingWeb\Arsse\CLI\Exception;
use JKingWeb\Arsse\REST\Fever\User as FeverUser; use JKingWeb\Arsse\REST\Fever\User as FeverUser;
use JKingWeb\Arsse\REST\Miniflux\Token as MinifluxToken; use JKingWeb\Arsse\REST\Miniflux\Token as MinifluxToken;
use JKingWeb\Arsse\ImportExport\OPML; use JKingWeb\Arsse\ImportExport\OPML;
use org\bovigo\vfs\vfsStream;
/** @covers \JKingWeb\Arsse\CLI */ /** @covers \JKingWeb\Arsse\CLI */
class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
protected $pidfiles = [
'errors' => [
'create' => [],
'read' => "",
'write' => "",
'readwrite' => "",
],
'ok' => [
'dir' => [],
'file' => "",
],
];
public function setUp(): void { public function setUp(): void {
parent::setUp(); parent::setUp();
$this->cli = $this->partialMock(CLI::class); $this->cli = $this->partialMock(CLI::class);
@ -27,6 +42,33 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
$this->dbMock = $this->mock(Database::class); $this->dbMock = $this->mock(Database::class);
} }
/** @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);
// set up mock CLI
$this->cli->realPath->returns($realpath ? $path.$file : false);
$cli = $this->cli->get();
// perform the test
if ($exp instanceof \Exception) {
$this->assertException($exp);
$cli->resolvePID($file);
} else {
$this->assertSame($exp, $cli->resolvePID($file));
}
}
public function providePidResolutions(): iterable {
return [
["errors/create", true, new Exception("pidUncreatable")],
];
}
public function assertConsole(string $command, int $exitStatus, string $output = "", bool $pattern = false): void { public function assertConsole(string $command, int $exitStatus, string $output = "", bool $pattern = false): void {
Arsse::$obj = $this->objMock->get(); Arsse::$obj = $this->objMock->get();
Arsse::$db = $this->dbMock->get(); Arsse::$db = $this->dbMock->get();