public function testServerStopWhileNotRunning() { $app = new Application(); $app->add($this->commandRepo->getRegisteredCommand('pjbserver:stop')); $command = $app->find('pjbserver:stop'); $tester = new CommandTester($command); $port = $this->config->getPort(); $tester->execute(['config-file' => PjbServerTestConfig::getBaseDir() . '/config/pjbserver.config.php.dist']); $this->assertEquals(0, $tester->getStatusCode()); $pid_file = $this->config->getPidFile(); if (!file_exists($pid_file)) { $this->assertRegexp("/Server already stopped \\(pid_file (.*) not found\\)./", $tester->getDisplay()); } else { $this->assertRegexp("/Server running on port {$port} successfully stopped/", $tester->getDisplay()); } }
/** * @param ConsoleLogger $logger * @param Config $config */ public function logServerConfig(ConsoleLogger $logger, Config $config) { $logger->info("* config port :" . $config->getPort()); $logger->info("* config log_file :" . $config->getLogFile()); $logger->info("* config pid_file :" . $config->getPidFile()); $logger->info("* config classpaths :" . implode(',', $config->getClasspaths())); $logger->info("* config java_bin :" . $config->getJavaBin()); $logger->info("* config server_jar :" . $config->getServerJar()); }
/** * Get standalone server pid number as it was stored during last start. * * @throws Exception\PidNotFoundException|ExceptionPidCorruptedException * * @return int */ public function getPid() { $pid_file = $this->config->getPidFile(); if (!file_exists($pid_file)) { $msg = "Pid file cannot be found '{$pid_file}'"; $this->logger->info("Get PID failed: {$msg}"); throw new Exception\PidNotFoundException($msg); } $pid = trim(file_get_contents($pid_file)); if (!preg_match('/^[0-9]+$/', $pid)) { $msg = "Pid found '{$pid_file}' but no valid pid stored in it or corrupted file '{$pid_file}'."; $this->logger->error("Get PID failed: {$msg}"); throw new Exception\PidCorruptedException($msg); } return (int) $pid; }
public function testGetMergedConfig() { $cfg = new Config(['port' => '8192', 'pid_file' => '{base_dir}/test_pjb-{tcp_port}.pid']); $base_dir = realpath(__DIR__ . '/../../../../..'); $this->assertEquals("{$base_dir}/test_pjb-8192.pid", $cfg->getPidFile()); }