FileUploadExceptionTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 50
rs 10
c 3
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A itShouldReturnErrorForNonMultipleFilesArray() 0 18 1
A itShouldReturnErrorForMultipleFilesArray() 0 22 1
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()
0 ignored issues
show
Coding Style introduced by
itShouldReturnErrorForNonMultipleFilesArray uses the super-global variable $_FILES which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
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()
0 ignored issues
show
Coding Style introduced by
itShouldReturnErrorForMultipleFilesArray uses the super-global variable $_FILES which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
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