1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Author: Nil Portugués Calderó <[email protected]> |
4
|
|
|
* Date: 9/26/14 |
5
|
|
|
* Time: 7:43 PM |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Tests\NilPortugues\Validator\Validation\FileUpload; |
12
|
|
|
|
13
|
|
|
use NilPortugues\Validator\Validation\FileUpload\FileUploadException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class FileUploadExceptionTest |
17
|
|
|
* @package Tests\NilPortugues\Validator\Validation\FileUploadAttribute |
18
|
|
|
*/ |
19
|
|
|
class FileUploadExceptionTest extends \PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @test |
23
|
|
|
*/ |
24
|
|
|
public function itShouldReturnErrorForNonMultipleFilesArray() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$_FILES = [ |
27
|
|
|
'image' => [ |
28
|
|
|
'name' => 'sample.png', |
29
|
|
|
'type' => 'image/png', |
30
|
|
|
'tmp_name' => \realpath(\dirname(__FILE__)).'/resources/phpGpKMlf', |
31
|
|
|
'error' => 1, |
32
|
|
|
'size' => '203868', |
33
|
|
|
], |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
$this->setExpectedException( |
37
|
|
|
'NilPortugues\Validator\Validation\FileUpload\FileUploadException', |
38
|
|
|
'FileUpload::UPLOAD_ERR_INI_SIZE' |
39
|
|
|
); |
40
|
|
|
throw new FileUploadException('image'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
*/ |
46
|
|
|
public function itShouldReturnErrorForMultipleFilesArray() |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$_FILES = [ |
49
|
|
|
'image' => [ |
50
|
|
|
'name' => ['sample.png', 'sample.png', 'sample.png'], |
51
|
|
|
'type' => ['image/png', 'image/png', 'image/png'], |
52
|
|
|
'tmp_name' => [ |
53
|
|
|
\realpath(\dirname(__FILE__)).'/resources/phpGpKMlf', |
54
|
|
|
\realpath(\dirname(__FILE__)).'/resources/phpGpKMlf', |
55
|
|
|
\realpath(\dirname(__FILE__)).'/resources/phpGpKMlf', |
56
|
|
|
], |
57
|
|
|
'error' => [1, 1, 1], |
58
|
|
|
'size' => [203868, 203868, 203868], |
59
|
|
|
], |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
$this->setExpectedException( |
63
|
|
|
'NilPortugues\Validator\Validation\FileUpload\FileUploadException', |
64
|
|
|
'FileUpload::UPLOAD_ERR_INI_SIZE' |
65
|
|
|
); |
66
|
|
|
throw new FileUploadException('image'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: