Skip to content

Commit

Permalink
Merge pull request #517 from DeveloperMarius/file-tests
Browse files Browse the repository at this point in the history
PHPUnit file tests
  • Loading branch information
skipperbent authored Mar 25, 2021
2 parents 2b9403d + 3e1333c commit fdf11bb
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions tests/Pecee/SimpleRouter/InputHandlerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Pecee\Http\Input\InputFile;

require_once 'Dummy/DummyMiddleware.php';
require_once 'Dummy/DummyController.php';
require_once 'Dummy/Handler/ExceptionHandler.php';
Expand Down Expand Up @@ -122,8 +124,42 @@ public function testGet()

public function testFile()
{
// TODO: implement test-file
$this->assertEquals(true, true);
global $_FILES;
$temp_dir = sys_get_temp_dir();

$test_file_input_name = 'test_input';
$test_file = array(
'name' => 'test.txt',
'type' => 'text/plain',
'tmp_name' => $temp_dir . '/phpYfWUiw',
'error' => 0,
'size' => 4
);
$test_file_content = 'test_content';

$_FILES = array(
$test_file_input_name => $test_file
);

$router = TestRouter::router();
$router->reset();
$router->getRequest()->setMethod('post');

$handler = TestRouter::request()->getInputHandler();
$file = $handler->file($test_file_input_name);
$this->assertInstanceOf(InputFile::class, $file);
$this->assertEquals($test_file['name'], $file->getFilename());
$this->assertEquals($test_file['type'], $file->getType());
$this->assertEquals($test_file['tmp_name'], $file->getTmpName());
$this->assertEquals($test_file['error'], $file->getError());
$this->assertEquals($test_file['size'], $file->getSize());
$this->assertEquals(pathinfo($test_file['name'], PATHINFO_EXTENSION), $file->getExtension());

file_put_contents($test_file['tmp_name'], $test_file_content);
$this->assertEquals($test_file_content, $file->getContents());

//cleanup
unlink($test_file['tmp_name']);
}

public function testFiles()
Expand Down

0 comments on commit fdf11bb

Please sign in to comment.