Defined variables for the file data

This commit is contained in:
DeveloperMarius
2021-03-24 13:32:15 +01:00
parent fef65313e5
commit 3e1333ccd4
+20 -14
View File
@@ -1,5 +1,7 @@
<?php <?php
use Pecee\Http\Input\InputFile;
require_once 'Dummy/DummyMiddleware.php'; require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php'; require_once 'Dummy/DummyController.php';
require_once 'Dummy/Handler/ExceptionHandler.php'; require_once 'Dummy/Handler/ExceptionHandler.php';
@@ -116,14 +118,18 @@ class InputHandlerTest extends \PHPUnit\Framework\TestCase
global $_FILES; global $_FILES;
$temp_dir = sys_get_temp_dir(); $temp_dir = sys_get_temp_dir();
$_FILES = array( $test_file_input_name = 'test_input';
'test' => array( $test_file = array(
'name' => 'test.txt', 'name' => 'test.txt',
'type' => 'text/plain', 'type' => 'text/plain',
'tmp_name' => $temp_dir . '/phpYfWUiw', 'tmp_name' => $temp_dir . '/phpYfWUiw',
'error' => 0, 'error' => 0,
'size' => 4 'size' => 4
) );
$test_file_content = 'test_content';
$_FILES = array(
$test_file_input_name => $test_file
); );
$router = TestRouter::router(); $router = TestRouter::router();
@@ -131,20 +137,20 @@ class InputHandlerTest extends \PHPUnit\Framework\TestCase
$router->getRequest()->setMethod('post'); $router->getRequest()->setMethod('post');
$handler = TestRouter::request()->getInputHandler(); $handler = TestRouter::request()->getInputHandler();
$file = $handler->file('test'); $file = $handler->file($test_file_input_name);
$this->assertInstanceOf(\Pecee\Http\Input\InputFile::class, $file); $this->assertInstanceOf(InputFile::class, $file);
$this->assertEquals('test.txt', $file->getFilename()); $this->assertEquals($test_file['name'], $file->getFilename());
$this->assertEquals('text/plain', $file->getType()); $this->assertEquals($test_file['type'], $file->getType());
$this->assertEquals($temp_dir . '/phpYfWUiw', $file->getTmpName()); $this->assertEquals($test_file['tmp_name'], $file->getTmpName());
$this->assertEquals(0, $file->getError()); $this->assertEquals($test_file['error'], $file->getError());
$this->assertEquals(4, $file->getSize()); $this->assertEquals($test_file['size'], $file->getSize());
$this->assertEquals('txt', $file->getExtension()); $this->assertEquals(pathinfo($test_file['name'], PATHINFO_EXTENSION), $file->getExtension());
file_put_contents($temp_dir . '/phpYfWUiw', 'test'); file_put_contents($test_file['tmp_name'], $test_file_content);
$this->assertEquals('test', $file->getContents()); $this->assertEquals($test_file_content, $file->getContents());
//cleanup //cleanup
unlink($temp_dir . '/phpYfWUiw'); unlink($test_file['tmp_name']);
} }
public function testFiles() public function testFiles()