No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

LogcheckerTest.php 2.5 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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', $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. $htmlFile = implode(DIRECTORY_SEPARATOR, [$basePath, 'html', $fileName]);
  31. if (!file_exists($detailsFile) || !file_exists($htmlFile)) {
  32. $this->markTestIncomplete('Missing details or html output file: ' . $filePath);
  33. }
  34. $logchecker = new Logchecker();
  35. $logchecker->newFile($filePath);
  36. $logchecker->parse();
  37. $actual = [
  38. 'ripper' => $logchecker->getRipper(),
  39. 'version' => $logchecker->getRipperVersion(),
  40. 'language' => $logchecker->getLanguage(),
  41. 'score' => $logchecker->getScore(),
  42. 'checksum' => $logchecker->getChecksumState(),
  43. 'details' => $logchecker->getDetails()
  44. ];
  45. $this->assertEquals(json_decode(file_get_contents($detailsFile), true), $actual);
  46. $this->assertStringEqualsFile($htmlFile, $logchecker->getLog());
  47. }
  48. public function testGetAcceptValues(): void
  49. {
  50. $this->assertSame(".txt,.TXT,.log,.LOG", Logchecker::getAcceptValues());
  51. }
  52. public function testGetLogcheckerVersion(): void
  53. {
  54. $composer = json_decode(
  55. file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'composer.json'])),
  56. true
  57. );
  58. $this->assertSame($composer['version'], Logchecker::getLogcheckerVersion());
  59. }
  60. }