use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\FileValidator;
-use Symfony\Component\Validator\Validation;
+use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
-abstract class FileValidatorTest extends AbstractConstraintValidatorTest
+abstract class FileValidatorTest extends ConstraintValidatorTestCase
{
protected $path;
protected $file;
- protected function getApiVersion()
- {
- return Validation::API_VERSION_2_5;
- }
-
protected function createValidator()
{
return new FileValidator();
{
parent::setUp();
- $this->path = sys_get_temp_dir().DIRECTORY_SEPARATOR.'FileValidatorTest';
+ $this->path = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'FileValidatorTest';
$this->file = fopen($this->path, 'w');
fwrite($this->file, ' ', 1);
}
{
parent::tearDown();
- if (is_resource($this->file)) {
+ if (\is_resource($this->file)) {
fclose($this->file);
}
'{{ suffix }}' => 'bytes',
), '1');
+ // access FileValidator::factorizeSizes() private method to format max file size
+ $reflection = new \ReflectionClass(\get_class(new FileValidator()));
+ $method = $reflection->getMethod('factorizeSizes');
+ $method->setAccessible(true);
+ list($sizeAsString, $limit, $suffix) = $method->invokeArgs(new FileValidator(), array(0, UploadedFile::getMaxFilesize(), false));
+
// it correctly parses the maxSize option and not only uses simple string comparison
// 1000M should be bigger than the ini value
$tests[] = array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', array(
- '{{ limit }}' => UploadedFile::getMaxFilesize() / 1048576,
- '{{ suffix }}' => 'MiB',
+ '{{ limit }}' => $limit,
+ '{{ suffix }}' => $suffix,
), '1000M');
// it correctly parses the maxSize option and not only uses simple string comparison