mirror of
https://github.com/php/web-bugs.git
synced 2026-03-24 07:42:08 +01:00
- Added filter to phpunit config - This enables support for coverage support - Moved unit tests to dedicated directory - Also created constants for the locations of the fixtures and mocks for testing so we do not have to use relative paths in tests - Updated phpunit to 8 - Added type information to tests - Added return type and parameter type declarations for tests - Added strict types to tests - CS fixes in tests - Aligning arrays, consistent string concatenation, removed unused local vars - Added constant for test cache directory - Make the autoloader also properly work on windows - Windows does not care about the directory separator used so just trim both variant from the end.
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\Utils;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
use PHPUnit\Framework\TestCase;
|
|
use App\Utils\Uploader;
|
|
|
|
class UploaderTest extends TestCase
|
|
{
|
|
/** @var string */
|
|
private $fixturesDirectory = TEST_FIXTURES_DIRECTORY . '/files';
|
|
|
|
/**
|
|
* @dataProvider filesProvider
|
|
*/
|
|
public function testUpload(string $validExtension, array $file): void
|
|
{
|
|
$_FILES = ['uploaded' => $file];
|
|
|
|
/** @var Uploader|MockObject $uploader */
|
|
$uploader = $this->getMockBuilder(Uploader::class)
|
|
->setMethods(['isUploadedFile', 'moveUploadedFile'])
|
|
->getMock();
|
|
|
|
$uploader->expects($this->once())
|
|
->method('isUploadedFile')
|
|
->will($this->returnValue(true));
|
|
|
|
$uploader->expects($this->once())
|
|
->method('moveUploadedFile')
|
|
->will($this->returnValue(true));
|
|
|
|
$uploader->setMaxFileSize(100 * 1024);
|
|
$uploader->setValidExtension($validExtension);
|
|
$uploader->setDir(TEST_VAR_DIRECTORY . '/uploads');
|
|
$tmpFile = $uploader->upload('uploaded');
|
|
|
|
$this->assertNotNull($tmpFile);
|
|
}
|
|
|
|
public function filesProvider(): array
|
|
{
|
|
return [
|
|
[
|
|
'txt',
|
|
[
|
|
'name' => 'patch.txt',
|
|
'tmp_name' => $this->fixturesDirectory . '/patch.txt',
|
|
'size' => filesize($this->fixturesDirectory . '/patch.txt'),
|
|
'error' => UPLOAD_ERR_OK,
|
|
]
|
|
],
|
|
];
|
|
}
|
|
}
|