Skip to content

Commit

Permalink
fixed response test
Browse files Browse the repository at this point in the history
  • Loading branch information
brainfoolong committed Jan 27, 2024
1 parent 9f073f2 commit 1485588
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions appdata/modules/FramelixTests/tests/Network/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@
use Framelix\Framelix\Network\Response;
use Framelix\Framelix\Utils\Buffer;
use Framelix\Framelix\Utils\FileUtils;
use Framelix\FramelixTests\Storable\TestStorableFile;
use Framelix\FramelixTests\TestCase;

use function file_get_contents;
use function file_put_contents;
use function http_response_code;
use function ob_get_level;
use function unlink;

final class ResponseTest extends TestCase
{

public function tests(): void
{
FileUtils::deleteDirectory(FileUtils::getUserdataFilepath("storablefile", true));

Buffer::start();
try {
Response::download("@filecontent", "foo");
Expand All @@ -34,27 +29,23 @@ public function tests(): void
}, [], StopExecution::class);
$this->assertSame(file_get_contents(__FILE__), Buffer::get());

$file = new TestStorableFile();
$file->relativePathOnDisk = "test.txt";
$filePath = $file->getPath(false);
$testFilePath = __DIR__ . "/../../test-files/imageutils/test-image.jpg";

// not exist test
Buffer::start();
$this->assertExceptionOnCall(function () use ($filePath) {
file_put_contents($filePath, "foobar");
Response::download($filePath);
$this->assertExceptionOnCall(function () use ($testFilePath) {
Response::download($testFilePath);
}, [], StopExecution::class);
$this->assertSame("foobar", Buffer::get());
unlink($file->getPath());
$this->assertSame(file_get_contents($testFilePath), Buffer::get());

// not exist test
$this->assertExceptionOnCall(function () {
Response::download(__FILE__ . "NotExist");
}, [], StopExecution::class);

// not exist test
$this->assertExceptionOnCall(function () use ($file) {
Response::download($file);
$this->assertExceptionOnCall(function () {
Response::download("blub");
}, [], StopExecution::class);

// test form validation response
Expand Down

0 comments on commit 1485588

Please sign in to comment.