Files
fil/e2e/php/tests/ErrorTest.php

74 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2026-06-01 23:40:55 +02:00
<?php
// This file is auto-generated by alef — DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
// To regenerate: alef generate
// To verify freshness: alef verify --exit-code
// Issues & docs: https://github.com/kreuzberg-dev/alef
declare(strict_types=1);
namespace Kreuzberg\E2e;
use PHPUnit\Framework\TestCase;
use Kreuzberg\Kreuzberg;
use Kreuzberg\ExtractionConfig;
/** E2e tests for category: error. */
final class ErrorTest extends TestCase
{
/** Graceful handling of empty bytes (should not error) */
public function test_error_empty_bytes(): void
{
$contentBytes = file_get_contents("text/empty.txt");
if ($contentBytes === false) { $this->fail("failed to read fixture: text/empty.txt"); }
$config = \Kreuzberg\ExtractionConfig::from_json('{}');
$this->expectNotToPerformAssertions();
$result = Kreuzberg::extractBytesSync($contentBytes, "text/plain", $config);
}
/** Error when extracting with empty MIME type */
public function test_error_empty_mime(): void
{
$this->expectException(\Exception::class); $contentBytes = file_get_contents("text/plain.txt");
if ($contentBytes === false) { $this->fail("failed to read fixture: text/plain.txt"); }
$config = \Kreuzberg\ExtractionConfig::from_json('{}');
Kreuzberg::extractBytesSync($contentBytes, "", $config);
}
/** extract_bytes force+disable OCR */
public function test_error_extract_bytes_conflicting_ocr(): void
{
$this->expectException(\Exception::class); $contentBytes = file_get_contents("text/fake_text.txt");
if ($contentBytes === false) { $this->fail("failed to read fixture: text/fake_text.txt"); }
$config = \Kreuzberg\ExtractionConfig::from_json(json_encode(["disableOcr" => true, "forceOcr" => true]));
Kreuzberg::extractBytesSync($contentBytes, "text/plain", $config);
}
/** Error when extracting with invalid MIME type format */
public function test_error_invalid_mime_format(): void
{
$this->expectException(\Exception::class); $contentBytes = file_get_contents("text/plain.txt");
if ($contentBytes === false) { $this->fail("failed to read fixture: text/plain.txt"); }
$config = \Kreuzberg\ExtractionConfig::from_json('{}');
Kreuzberg::extractBytesSync($contentBytes, "not-a-mime", $config);
}
/** Error when extracting with unsupported MIME type */
public function test_error_unsupported_mime(): void
{
$this->expectException(\Exception::class); $contentBytes = file_get_contents("text/plain.txt");
if ($contentBytes === false) { $this->fail("failed to read fixture: text/plain.txt"); }
$config = \Kreuzberg\ExtractionConfig::from_json('{}');
Kreuzberg::extractBytesSync($contentBytes, "application/x-nonexistent", $config);
}
}