You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 4 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace OrpheusNET\Logchecker;
  3. use FilesystemIterator;
  4. use OrpheusNET\Logchecker\Check\Checksum;
  5. use OrpheusNET\Logchecker\Check\Ripper;
  6. use PHPUnit\Framework\TestCase;
  7. class LogcheckerTest extends TestCase
  8. {
  9. public function logDataProvider(): array
  10. {
  11. $return = [];
  12. foreach ([Ripper::EAC, Ripper::XLD, Ripper::WHIPPER] as $ripper) {
  13. $basePath = implode(DIRECTORY_SEPARATOR, [__DIR__, 'logs', strtolower($ripper)]);
  14. foreach (new FilesystemIterator($basePath . DIRECTORY_SEPARATOR . 'originals') as $entry) {
  15. $return[] = [$ripper, $entry->getPathname(), $entry->getFilename()];
  16. }
  17. }
  18. return $return;
  19. }
  20. /**
  21. * @dataProvider logDataProvider
  22. */
  23. public function testLogchecker(string $ripper, string $filePath, string $fileName): void
  24. {
  25. $basePath = implode(DIRECTORY_SEPARATOR, [__DIR__, 'logs', strtolower($ripper)]);
  26. if (!Checksum::logcheckerExists($ripper)) {
  27. $this->markTestSkipped("Need to install {$ripper} logchecker");
  28. }
  29. $detailsFile = implode(DIRECTORY_SEPARATOR, [$basePath, 'details', str_replace('.log', '.json', $fileName)]);
  30. if (!file_exists($detailsFile)) {
  31. $this->markTestIncomplete("Missing details file:\n- " . $detailsFile . "\n- " . $filePath);
  32. }
  33. $htmlFile = implode(DIRECTORY_SEPARATOR, [$basePath, 'html', $fileName]);
  34. if (!file_exists($htmlFile)) {
  35. $this->markTestIncomplete("Missing html file:\n- " . $htmlFile . "\n- " . $filePath);
  36. }
  37. $logchecker = new Logchecker();
  38. $logchecker->newFile($filePath);
  39. $logchecker->parse();
  40. $actual = [
  41. 'ripper' => $logchecker->getRipper(),
  42. 'version' => $logchecker->getRipperVersion(),
  43. 'language' => $logchecker->getLanguage(),
  44. 'combined' => $logchecker->isCombinedLog(),
  45. 'score' => $logchecker->getScore(),
  46. 'checksum' => $logchecker->getChecksumState(),
  47. 'details' => $logchecker->getDetails()
  48. ];
  49. $this->assertEquals(json_decode(file_get_contents($detailsFile), true), $actual);
  50. $this->assertStringEqualsFile($htmlFile, $logchecker->getLog());
  51. }
  52. public function testGetAcceptValues(): void
  53. {
  54. $this->assertSame(".txt,.TXT,.log,.LOG", Logchecker::getAcceptValues());
  55. }
  56. public function testGetLogcheckerVersion(): void
  57. {
  58. $composer = json_decode(
  59. file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'composer.json'])),
  60. true
  61. );
  62. $this->assertSame($composer['version'], Logchecker::getLogcheckerVersion());
  63. }
  64. public function testCheckUnknownLog(): void
  65. {
  66. $logchecker = new Logchecker();
  67. $logchecker->newFile(implode(DIRECTORY_SEPARATOR, [__DIR__, 'LogcheckerTest.php']));
  68. $logchecker->parse();
  69. $this->assertSame(Ripper::UNKNOWN, $logchecker->getRipper());
  70. $this->assertNull($logchecker->getRipperVersion());
  71. $this->assertSame(0, $logchecker->getScore());
  72. $this->assertSame('en', $logchecker->getLanguage());
  73. $this->assertSame(['Unknown log file, could not determine ripper.'], $logchecker->getDetails());
  74. }
  75. }