mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Manage exception with missing nzb
This commit is contained in:
@@ -329,8 +329,18 @@ class GetNzbController extends BasePageController
|
||||
*/
|
||||
private function streamModifiedNzbContent(string $nzbPath, int $uid): void
|
||||
{
|
||||
$fileHandle = gzopen($nzbPath, 'rb');
|
||||
if (! File::exists($nzbPath)) {
|
||||
Log::warning('NZB file not found during streaming', ['path' => $nzbPath]);
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?><error>NZB file not found</error>';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fileHandle = @gzopen($nzbPath, 'rb');
|
||||
if ($fileHandle === false) {
|
||||
Log::warning('Failed to open NZB file for streaming', ['path' => $nzbPath]);
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?><error>Failed to read NZB file</error>';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class GetNzbControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test that file_exists returns false for non-existent files
|
||||
*/
|
||||
public function test_file_exists_returns_false_for_non_existent_file(): void
|
||||
{
|
||||
$nonExistentPath = '/tmp/non-existent-file-'.uniqid().'.nzb.gz';
|
||||
$this->assertFalse(file_exists($nonExistentPath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the file check prevents gzopen from being called on missing files
|
||||
*/
|
||||
public function test_file_check_prevents_gzopen_error(): void
|
||||
{
|
||||
$nonExistentPath = '/tmp/non-existent-'.uniqid().'.nzb.gz';
|
||||
// Simulate the fix logic from streamModifiedNzbContent
|
||||
if (! file_exists($nonExistentPath)) {
|
||||
$errorMessage = '<?xml version="1.0" encoding="UTF-8"?><error>NZB file not found</error>';
|
||||
$gzopenCalled = false;
|
||||
} else {
|
||||
$gzopenCalled = true;
|
||||
$errorMessage = '';
|
||||
}
|
||||
$this->assertFalse($gzopenCalled, 'gzopen should not be called for non-existent files');
|
||||
$this->assertStringContainsString('NZB file not found', $errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that file_exists returns true for existing files
|
||||
*/
|
||||
public function test_file_exists_returns_true_for_existing_file(): void
|
||||
{
|
||||
$tempPath = '/tmp/existing-file-'.uniqid().'.nzb.gz';
|
||||
file_put_contents($tempPath, 'test content');
|
||||
try {
|
||||
$this->assertTrue(file_exists($tempPath));
|
||||
} finally {
|
||||
unlink($tempPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user