RequireOnceItopFile('webservices/CronService.php'); } public function testIsStarted() { $sPath = $this->GetTemporaryFilePath(); file_put_contents($sPath, file_get_contents(__DIR__.'/resources/cron_starting.log')); $this->assertEquals(true, \CronService::GetInstance()->IsStarted($sPath)); } public function testIsFailed_MissingCredentialsFailure() { $sPath = $this->GetTemporaryFilePath(); file_put_contents($sPath, file_get_contents(__DIR__.'/resources/cron_missingcreds_error.log')); $this->assertEquals("Missing argument 'auth_user'", \CronService::GetInstance()->GetErrorMessage($sPath)); $this->assertEquals(true, \CronService::GetInstance()->IsFailed($sPath)); } public static function ErrorProvider() { return [ ["Access wrong credentials ('user123')"], ['gabuzomeu'], ]; } /** * @dataProvider ErrorProvider */ public function testIsFailed_AuthenticationFailure($sError) { $sPath = $this->GetTemporaryFilePath(); $sContent = <<assertEquals($sError, \CronService::GetInstance()->GetErrorMessage($sPath)); $this->assertEquals(true, \CronService::GetInstance()->IsFailed($sPath)); } public static function CannotStartProvider() { return [ ["cron_alreadyrunning.log", 'Already running...'], ['cron_maintenance.log', 'A maintenance is ongoing'], ['cron_notanadmin.log', 'Access restricted to administrators'], ]; } /** * @dataProvider CannotStartProvider */ public function testCronCannotStart(string $sLogFile, $sError) { $sPath = $this->GetTemporaryFilePath(); file_put_contents($sPath, file_get_contents(__DIR__.'/resources/'.$sLogFile)); $this->assertEquals($sError, \CronService::GetInstance()->GetErrorMessage($sPath)); $this->assertEquals(true, \CronService::GetInstance()->IsFailed($sPath)); } public function testCronRunning() { $sPath = $this->GetTemporaryFilePath(); $sContent = <<assertEquals(null, \CronService::GetInstance()->GetErrorMessage($sPath)); $this->assertEquals(false, \CronService::GetInstance()->IsFailed($sPath)); } public function testCronStopped() { $sPath = $this->GetTemporaryFilePath(); file_put_contents($sPath, file_get_contents(__DIR__.'/resources/cron_stopped.log')); $this->assertEquals(null, \CronService::GetInstance()->GetErrorMessage($sPath)); $this->assertEquals(false, \CronService::GetInstance()->IsFailed($sPath)); } }