Skip to content

Commit

Permalink
Test enhancement (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k authored Jun 23, 2020
1 parent 1b7327f commit 18c992b
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4

before_script:
- composer selfupdate
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "File uploading library capable of handling large/chunked/multiple file uploads",
"license": "MIT",
"autoload": {
"psr-0": {
"FileUpload\\": "src/"
"psr-4": {
"FileUpload\\": "src/FileUpload"
}
},
"require": {
Expand Down
6 changes: 5 additions & 1 deletion src/FileUpload/FileNameGenerator/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ public function getFileName($source_name, $type, $tmp_name, $index, $content_ran
*/
protected function getUniqueFilename($name, $type, $index, $content_range)
{
if (! is_array($content_range)) {
$content_range = [0];
}

while ($this->filesystem->isDir($this->pathresolver->getUploadPath($name))) {
$name = $this->pathresolver->upcountName($name);
}

$uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1]));
$uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1] ?? $content_range[0]));

while ($this->filesystem->isFile($this->pathresolver->getUploadPath($name))) {
if ($uploaded_bytes == $this->filesystem->getFilesize($this->pathresolver->getUploadPath($name))) {
Expand Down
8 changes: 6 additions & 2 deletions src/FileUpload/FileNameGenerator/Slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ public function getFileName($source_name, $type, $tmp_name, $index, $content_ran
*/
protected function getUniqueFilename($name, $type, $index, $content_range)
{
if (! is_array($content_range)) {
$content_range = [0];
}

while ($this->filesystem->isDir($this->pathresolver->getUploadPath($this->getSluggedFileName($name)))) {
$name = $this->pathresolver->upcountName($name);
}

$uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1]));
$uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1] ?? $content_range[0]));

while ($this->filesystem->isFile($this->pathresolver->getUploadPath($this->getSluggedFileName($name)))) {
if ($uploaded_bytes == $this->filesystem->getFilesize($this->pathresolver->getUploadPath($this->getSluggedFileName($name)))) {
Expand Down Expand Up @@ -107,7 +111,7 @@ private function slugify($text)
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);

if (empty($text)) {
return 'n-a';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FileUpload/FileNameGenerator/MD5Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MD5Test extends TestCase
{
protected $filesystem;

public function setUp()
protected function setUp()
{
$playground_path = __DIR__ . '/../../playground';
$fixtures_path = __DIR__ . '/../../fixtures';
Expand Down
4 changes: 2 additions & 2 deletions tests/FileUpload/FileSystem/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SimpleTest extends TestCase
{
protected $filesystem;

public function setUp()
protected function setUp()
{
$playground_path = __DIR__ . '/../../playground';
$fixtures_path = __DIR__ . '/../../fixtures';
Expand Down Expand Up @@ -42,7 +42,7 @@ public function testWriteToFile()
$path = __DIR__ . '/../../playground/test.1.txt';

$this->filesystem->writeToFile($path, $this->filesystem->getFileStream($yadda));
$this->assertEquals(file_get_contents($yadda), file_get_contents($path));
$this->assertFileEquals($yadda, $path);

$this->filesystem->unlink($path);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FileUpload/FileUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class FileUploadTest extends TestCase
{
public function setUp()
protected function setUp()
{
$playground_path = __DIR__ . '/../playground';
$fixtures_path = __DIR__ . '/../fixtures';
Expand Down
2 changes: 1 addition & 1 deletion tests/FileUpload/Validator/DimensionValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function testSetErrorMessages()
);
}

public function setUp()
protected function setUp()
{
$this->directory = __DIR__ . '/../../fixtures/';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FileUpload/Validator/MimeTypeValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testInvalidMimeType()
$this->assertFalse($this->validator->validate($file, $_FILES['file']['size']));
}

public function setUp()
protected function setUp()
{
$this->directory = __DIR__ . '/../../fixtures/';

Expand Down
2 changes: 1 addition & 1 deletion tests/FileUpload/Validator/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testSetErrorMessages()
$this->assertEquals($errorMessage, $file->error);
}

public function setUp()
protected function setUp()
{
$this->directory = __DIR__ . '/../../fixtures/';

Expand Down
2 changes: 1 addition & 1 deletion tests/FileUpload/Validator/SizeValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SizeValidatorTest extends TestCase
protected $validator;
protected $file;

public function setUp()
protected function setUp()
{
$this->directory = __DIR__ . '/../../fixtures/';

Expand Down

0 comments on commit 18c992b

Please sign in to comment.