Browse Source

Catch unknown ripper error in logchecker proper

tags/0.9.2
itismadness 4 years ago
parent
commit
63c7d8f6b5
3 changed files with 25 additions and 2 deletions
  1. +1
    -1
      src/Check/Ripper.php
  2. +11
    -1
      src/Logchecker.php
  3. +13
    -0
      tests/LogcheckerTest.php

+ 1
- 1
src/Check/Ripper.php View File

@@ -8,7 +8,7 @@ use OrpheusNET\Logchecker\Exception\UnknownRipperException;


class Ripper class Ripper
{ {
public const UNKNOWN = 'unknown';
public const WHIPPER = 'whipper'; public const WHIPPER = 'whipper';
public const XLD = 'XLD'; public const XLD = 'XLD';
public const EAC = 'EAC'; public const EAC = 'EAC';


+ 11
- 1
src/Logchecker.php View File

@@ -3,6 +3,7 @@
namespace OrpheusNET\Logchecker; namespace OrpheusNET\Logchecker;


use OrpheusNET\Logchecker\Check\Ripper; use OrpheusNET\Logchecker\Check\Ripper;
use OrpheusNET\Logchecker\Exception\UnknownRipperException;
use OrpheusNET\Logchecker\Parser\EAC\Translator; use OrpheusNET\Logchecker\Parser\EAC\Translator;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Exception\ParseException;
@@ -108,9 +109,18 @@ class Logchecker
} catch (\Exception $exc) { } catch (\Exception $exc) {
$this->Score = 0; $this->Score = 0;
$this->account('Could not detect log encoding, log is corrupt.'); $this->account('Could not detect log encoding, log is corrupt.');
return;
}

try {
$this->ripper = Ripper::getRipper($this->log);
} catch (UnknownRipperException $exc) {
$this->Score = 0;
$this->account('Unknown log file, could not determine ripper.');
$this->ripper = Ripper::UNKNOWN;
return;
} }


$this->ripper = Ripper::getRipper($this->log);
if ($this->ripper === Ripper::WHIPPER) { if ($this->ripper === Ripper::WHIPPER) {
$this->whipperParse(); $this->whipperParse();
} else { } else {


+ 13
- 0
tests/LogcheckerTest.php View File

@@ -70,4 +70,17 @@ class LogcheckerTest extends TestCase
); );
$this->assertSame($composer['version'], Logchecker::getLogcheckerVersion()); $this->assertSame($composer['version'], Logchecker::getLogcheckerVersion());
} }

public function testCheckUnknownLog(): void
{
$logchecker = new Logchecker();
$logchecker->newFile(implode(DIRECTORY_SEPARATOR, [__DIR__, 'LogcheckerTest.php']));
$logchecker->parse();

$this->assertSame(Ripper::UNKNOWN, $logchecker->getRipper());
$this->assertNull($logchecker->getRipperVersion());
$this->assertSame(0, $logchecker->getScore());
$this->assertSame('en', $logchecker->getLanguage());
$this->assertSame(['Unknown log file, could not determine ripper.'], $logchecker->getDetails());
}
} }

Loading…
Cancel
Save