diff --git a/fixtures/doc.pdf b/fixtures/doc.pdf new file mode 100644 index 0000000..00e868b --- /dev/null +++ b/fixtures/doc.pdf @@ -0,0 +1,14 @@ +%PDF-1.4 +1 0 obj<>endobj +2 0 obj<>endobj +3 0 obj<>>>endobj +xref +0 4 +0000000000 65535 f +0000000009 00000 n +0000000054 00000 n +0000000099 00000 n +trailer<> +startxref +168 +%%EOF diff --git a/fixtures/photo.png b/fixtures/photo.png new file mode 100644 index 0000000..909c66d Binary files /dev/null and b/fixtures/photo.png differ diff --git a/src/Scenario/UploadsScenario.php b/src/Scenario/UploadsScenario.php index d9a6339..005baa1 100644 --- a/src/Scenario/UploadsScenario.php +++ b/src/Scenario/UploadsScenario.php @@ -17,6 +17,18 @@ final class UploadsScenario extends AbstractScenario private const DEFAULT_PHOTO_URL = 'https://placehold.co/600x400/png'; private const DEFAULT_FILE_URL = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'; + /** + * Look for a fixture in storage/uploads/ (override, gitignored) first, fall back to fixtures/ (committed). + */ + private static function fixturePath(string $filename): string + { + $override = __DIR__ . '/../../storage/uploads/' . $filename; + if (is_file($override)) { + return $override; + } + return __DIR__ . '/../../fixtures/' . $filename; + } + public function handle(MessageCreatedUpdate $update, ParsedCommand $command): void { switch ($command->name) { @@ -49,9 +61,9 @@ final class UploadsScenario extends AbstractScenario private function uploadPhotoFromFile(MessageCreatedUpdate $update, ParsedCommand $command): void { - $path = $command->arg(0, __DIR__ . '/../../storage/uploads/photo.png'); + $path = $command->arg(0, self::fixturePath('photo.png')); if (!is_file($path)) { - $this->replyMarkdown($update, "File not found: `$path`. Положи PNG в storage/uploads/photo.png."); + $this->replyMarkdown($update, "File not found: `$path`. Положи PNG в fixtures/photo.png или storage/uploads/photo.png."); return; } $tokens = $this->api->uploads->uploadPhotoFromFile($path); @@ -85,15 +97,15 @@ final class UploadsScenario extends AbstractScenario private function uploadMediaFromFile(MessageCreatedUpdate $update, ParsedCommand $command, UploadType $type): void { - $default = __DIR__ . '/../../storage/uploads/' . match ($type) { + $filename = match ($type) { UploadType::Audio => 'audio.mp3', UploadType::Video => 'video.mp4', UploadType::File => 'doc.pdf', UploadType::Photo => 'photo.png', }; - $path = $command->arg(0, $default); + $path = $command->arg(0, self::fixturePath($filename)); if (!is_file($path)) { - $this->replyMarkdown($update, "File not found: `$path`. Положи файл в storage/uploads/."); + $this->replyMarkdown($update, "File not found: `$path`. Положи файл в fixtures/ или storage/uploads/."); return; } $info = $this->api->uploads->uploadMediaFromFile($type, $path);