CommonTestClass::fileDataset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 23
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 30
rs 9.552
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
5
6
class CommonTestClass extends TestCase
7
{
8
    protected function entryDataset(): array
9
    {
10
        return [
11
            'foo' => 'val1',
12
            'bar' => ['bal1', 'bal2'],
13
            'baz' => true,
14
            'aff' => 42,
15
        ];
16
    }
17
18
    protected function strangeEntryDataset(): array
19
    {
20
        return [
21
            'foo  ' => ' val1 ',
22
            'ba' . chr(0) . 'r' => ["<script>alert('XSS!!!')</script>", 'bal2'],
23
            'b<a>z' => false,
24
            'a**ff' => '<?php echo "ded!";',
25
        ];
26
    }
27
28
    protected function fileDataset(): array
29
    {
30
        return [
31
            'files' => [ // simple upload
32
                'name' => 'facepalm.jpg',
33
                'type' => 'image/jpeg',
34
                'tmp_name' => '/tmp/php3zU3t5',
35
                'error' => UPLOAD_ERR_OK,
36
                'size' => 591387,
37
            ],
38
            'download' => [ // multiple upload
39
                'name' => [
40
                    'file1' => 'MyFile.txt',
41
                    'file2' => 'MyFile.jpg',
42
                ],
43
                'type' => [
44
                    'file1' => 'text/plain',
45
                    'file2' => 'image/jpeg',
46
                ],
47
                'tmp_name' => [
48
                    'file1' => '/tmp/php/phpgj46fg',
49
                    'file2' => '/tmp/php/php7s4ag4',
50
                ],
51
                'error' => [
52
                    'file1' => UPLOAD_ERR_CANT_WRITE,
53
                    'file2' => UPLOAD_ERR_PARTIAL,
54
                ],
55
                'size' => [
56
                    'file1' => 816,
57
                    'file2' => 3075,
58
                ],
59
            ],
60
        ];
61
    }
62
63
    protected function strangeFileDataset(): array
64
    {
65
        return [
66
            'fi' . chr(0) . 'les' => [ // simple upload
67
                'name' => 'face' . chr(0) . 'palm.jpg',
68
                'type' => 'image<?= \'/\'; ?>jpeg',
69
                'tmp_name' => '/tmp/php3zU3t5',
70
                'error' => UPLOAD_ERR_OK,
71
                'size' => '591387',
72
            ],
73
            'download' => [ // multiple upload
74
                'name' => [
75
                    'file1' => 'C:\System\MyFile.txt',
76
                    'file2' => 'A:\MyFile.jpg',
77
                ],
78
                'type' => [
79
                    'file1' => 'text/plain',
80
                    'file2' => 'image/jpeg',
81
                ],
82
                'tmp_name' => [
83
                    'file1' => '/tmp/php/phpgj46fg',
84
                    'file2' => '/tmp/php/php7s4ag4',
85
                ],
86
                'error' => [
87
                    'file1' => UPLOAD_ERR_CANT_WRITE,
88
                    'file2' => UPLOAD_ERR_PARTIAL,
89
                ],
90
                'size' => [
91
                    'file1' => 816,
92
                    'file2' => 6874,
93
                ],
94
            ],
95
        ];
96
    }
97
98
    protected function cliDataset(): array
99
    {
100
        return [
101
            '--testing=foo',
102
            '--bar=baz',
103
            '--bar=eek',
104
            '--mko=',
105
            '--der',
106
            '--file1=./data/tester.gif',
107
            '--file2=data/testing.1.txt',
108
            '--file3=./data/testing.2.txt',
109
            '-abc',
110
            'known',
111
            'what',
112
        ];
113
    }
114
115
    protected function strangeCliDataset(): array
116
    {
117
        return [
118
            '--tes' . chr(0) . 'ting=f<o>o',
119
            '---bar=b**a**z',
120
            '-a-*c',
121
        ];
122
    }
123
124
    protected function jsonDataset(): string
125
    {
126
        return '{"foo": "bar", "baz": {"rfv": 123, "edc": 456}, "sbr": ["cde", "dgs"]}';
127
    }
128
129
    protected function jsonStringDataset(): string
130
    {
131
        return '"Just content"';
132
    }
133
134
    protected function jsonFileDataset(): string
135
    {
136
        return '{"foo": {"rfv": 123, "FILE": "This won\u0000t be changed"}, "bar": {"ijn": {"FILE": "This will be cha\u0000nged"}}}';
137
    }
138
}
139