56 lines
2.5 KiB
PHP
56 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace JumPHP\Ide\Tests;
|
|
|
|
use JumPHP\Ide\Log\BugReport;
|
|
use JumPHP\Ide\Log\LogBuffer;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/** "Report a bug": what goes to jumphp.net never says who the person is. */
|
|
final class BugReportTest extends TestCase
|
|
{
|
|
public function testTheLogSaysNothingAboutWhoThePersonIs(): void
|
|
{
|
|
$log = new LogBuffer();
|
|
$log->add('info', 'ide', 'Settings folder: /home/alice/.config/jumphp; repo /home/bob/x');
|
|
$log->add('error', 'git', 'push failed for [email protected] on C:\\Users\\Carol\\game and Alice-the-dev');
|
|
for ($i = 0; $i < 80; $i++) {
|
|
$log->add('debug', 'ide', "line $i");
|
|
}
|
|
$lines = BugReport::logTail($log, ['alice'], 82, '/home/alice');
|
|
self::assertCount(82, $lines);
|
|
$all = implode("\n", $lines);
|
|
self::assertStringContainsString('~/.config/jumphp', $all);
|
|
self::assertStringContainsString('/home/<user>/x', $all);
|
|
self::assertStringContainsString('<email>', $all);
|
|
self::assertStringContainsString('Users\\<user>', $all);
|
|
self::assertStringNotContainsStringIgnoringCase('alice', $all);
|
|
self::assertStringNotContainsString('Carol', $all);
|
|
self::assertStringNotContainsString('bob', $all);
|
|
self::assertCount(BugReport::LOG_LINES, BugReport::logTail($log));
|
|
}
|
|
|
|
public function testThePayload(): void
|
|
{
|
|
$png = base64_encode("\x89PNG\r\n\x1a\n" . 'data');
|
|
$p = BugReport::payload(['message' => ' It froze ', 'contact' => '', 'screenshot' => "data:image/png;base64,$png", 'meta' => ['kind' => 'game', 'login' => 'x']],
|
|
['version' => '0.1.112', 'os' => 'Linux x86_64', 'php' => '8.5', 'log' => ['a']]);
|
|
self::assertSame('It froze', $p['message']);
|
|
self::assertSame('', $p['contact']);
|
|
self::assertSame($png, $p['screenshot']);
|
|
self::assertSame(['app' => 'ide', 'source' => 'desktop', 'kind' => 'game', 'version' => '0.1.112', 'os' => 'Linux x86_64', 'php' => '8.5', 'log' => ['a']], $p['meta']);
|
|
self::assertNull(BugReport::payload(['message' => 'x'], [])['screenshot']);
|
|
}
|
|
|
|
public function testWhatIsRefused(): void
|
|
{
|
|
foreach ([['message' => ' '], ['message' => 'x', 'screenshot' => base64_encode('GIF89a')]] as $input) {
|
|
try {
|
|
BugReport::payload($input, []);
|
|
self::fail('accepted: ' . json_encode($input));
|
|
} catch (\InvalidArgumentException) {
|
|
self::addToAssertionCount(1);
|
|
}
|
|
}
|
|
}
|
|
}
|