1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00
This commit is contained in:
J. King 2021-06-25 11:08:56 -04:00
parent 0bb5e916d2
commit 514cb0a351
2 changed files with 48 additions and 1 deletions

View file

@ -6,6 +6,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\CLI; namespace JKingWeb\Arsse\TestCase\CLI;
use Eloquent\Phony\Phpunit\Phony;
use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ClientException;
use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf; use JKingWeb\Arsse\Conf;
@ -13,10 +14,10 @@ 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 JKingWeb\Arsse\Service\Daemon;
/** @covers \JKingWeb\Arsse\CLI */ /** @covers \JKingWeb\Arsse\CLI */
class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
@ -72,6 +73,43 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
$srv->watch->calledWith(true); $srv->watch->calledWith(true);
} }
public function testStartTheForkingDaemon(): void {
$f = tempnam(sys_get_temp_dir(), "arsse");
$srv = $this->mock(Service::class);
$srv->watch->returns(new \DateTimeImmutable);
$daemon = $this->mock(Daemon::class);
$daemon->checkPIDFilePath->returns($f);
$daemon->fork->returns(null);
$this->objMock->get->with(Service::class)->returns($srv->get());
$this->objMock->get->with(Daemon::class)->returns($daemon->get());
$this->assertConsole("arsse.php daemon --fork=arsse.pid", 0);
$this->assertFileDoesNotExist($f);
Phony::inOrder(
$daemon->checkPIDFilePath->calledWith("arsse.pid"),
$daemon->fork->calledWith($f),
$this->cli->loadConf->called(),
$srv->watch->calledWith(true)
);
}
public function testFailToStartTheForkingDaemon(): void {
$srv = $this->mock(Service::class);
$srv->watch->returns(new \DateTimeImmutable);
$daemon = $this->mock(Daemon::class);
$daemon->checkPIDFilePath->throws(new Service\Exception("pidDuplicate", ['pid' =>2112]));
$daemon->fork->returns(null);
$this->objMock->get->with(Service::class)->returns($srv->get());
$this->objMock->get->with(Daemon::class)->returns($daemon->get());
$this->assertConsole("arsse.php daemon --fork=arsse.pid", 0);
$this->assertFileDoesNotExist($f);
Phony::inOrder(
$daemon->checkPIDFilePath->calledWith("arsse.pid"),
$daemon->fork->calledWith($f),
$this->cli->loadConf->called(),
$srv->watch->calledWith(true)
);
}
public function testRefreshAllFeeds(): void { public function testRefreshAllFeeds(): void {
$srv = $this->mock(Service::class); $srv = $this->mock(Service::class);
$srv->watch->returns(new \DateTimeImmutable); $srv->watch->returns(new \DateTimeImmutable);

View file

@ -149,6 +149,15 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
} }
} }
public static function assertFileDoesNotExist(string $filename, string $message = ''): void {
if (method_exists(parent::class, "assertFileDoesNotExist")) {
parent::assertFileDoesNotExist($filename, $message);
} else {
parent::assertFileNotExists($filename, $message);
}
}
public function assertException($msg = "", string $prefix = "", string $type = "Exception"): void { public function assertException($msg = "", string $prefix = "", string $type = "Exception"): void {
if (func_num_args()) { if (func_num_args()) {
if ($msg instanceof \JKingWeb\Arsse\AbstractException) { if ($msg instanceof \JKingWeb\Arsse\AbstractException) {