2
2
3
3
namespace Http \Psr7Test ;
4
4
5
+ use Psr \Http \Message \StreamInterface ;
5
6
use Psr \Http \Message \UploadedFileInterface ;
6
7
7
8
/**
8
- * TODO Write me.
9
- *
10
9
* @author Tobias Nyholm <[email protected] >
11
10
*/
12
11
abstract class UploadedFileIntegrationTest extends BaseTest
@@ -26,17 +25,133 @@ abstract class UploadedFileIntegrationTest extends BaseTest
26
25
*/
27
26
abstract public function createSubject ();
28
27
28
+ public static function setUpBeforeClass ()
29
+ {
30
+ @mkdir ('.tmp ' );
31
+ parent ::setUpBeforeClass ();
32
+ }
33
+
29
34
protected function setUp ()
30
35
{
31
36
$ this ->uploadedFile = $ this ->createSubject ();
32
37
}
33
38
34
- public function testNothing ()
39
+ public function testGetStream ()
35
40
{
36
41
if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
37
42
$ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
38
43
}
39
44
40
- $ this ->assertTrue (true );
45
+ $ file = $ this ->createSubject ();
46
+
47
+ $ stream = $ file ->getStream ();
48
+ $ this ->assertTrue ($ stream instanceof StreamInterface);
49
+ }
50
+
51
+ public function testGetStreamAfterMoveTo ()
52
+ {
53
+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
54
+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
55
+ }
56
+
57
+ $ file = $ this ->createSubject ();
58
+ $ this ->expectException (\RuntimeException::class);
59
+ $ file ->moveTo (sys_get_temp_dir ().'/foo ' );
60
+ $ file ->getStream ();
61
+ }
62
+
63
+ public function testMoveToAbsolute ()
64
+ {
65
+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
66
+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
67
+ }
68
+
69
+ $ file = $ this ->createSubject ();
70
+ $ targetPath = sys_get_temp_dir ().'/ ' .uniqid ('foo ' , true );
71
+
72
+ $ this ->assertFalse (is_file ($ targetPath ));
73
+ $ file ->moveTo ($ targetPath );
74
+ $ this ->assertTrue (is_file ($ targetPath ));
75
+ }
76
+
77
+ public function testMoveToRelative ()
78
+ {
79
+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
80
+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
81
+ }
82
+
83
+ $ file = $ this ->createSubject ();
84
+ $ targetPath = '.tmp/ ' .uniqid ('foo ' , true );
85
+
86
+ $ this ->assertFalse (is_file ($ targetPath ));
87
+ $ file ->moveTo ($ targetPath );
88
+ $ this ->assertTrue (is_file ($ targetPath ));
89
+ }
90
+
91
+ public function testMoveToTwice ()
92
+ {
93
+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
94
+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
95
+ }
96
+ $ this ->expectException (\RuntimeException::class);
97
+
98
+ $ file = $ this ->createSubject ();
99
+ $ file ->moveTo ('.tmp/ ' .uniqid ('foo ' , true ));
100
+ $ file ->moveTo ('.tmp/ ' .uniqid ('foo ' , true ));
101
+ }
102
+
103
+ public function testGetSize ()
104
+ {
105
+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
106
+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
107
+ }
108
+
109
+ $ file = $ this ->createSubject ();
110
+ $ size = $ file ->getSize ();
111
+ if ($ size ) {
112
+ $ this ->assertRegExp ('|^[0-9]+$| ' , (string ) $ size );
113
+ } else {
114
+ $ this ->assertNull ($ size );
115
+ }
116
+ }
117
+
118
+ public function testGetError ()
119
+ {
120
+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
121
+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
122
+ }
123
+
124
+ $ file = $ this ->createSubject ();
125
+ $ this ->assertEquals (UPLOAD_ERR_OK , $ file ->getError ());
126
+ }
127
+
128
+ public function testGetClientFilename ()
129
+ {
130
+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
131
+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
132
+ }
133
+
134
+ $ file = $ this ->createSubject ();
135
+ $ name = $ file ->getClientFilename ();
136
+ if ($ name ) {
137
+ $ this ->assertTrue (is_string ($ name ));
138
+ } else {
139
+ $ this ->assertNull ($ name );
140
+ }
141
+ }
142
+
143
+ public function testGetClientMediaType ()
144
+ {
145
+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
146
+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
147
+ }
148
+
149
+ $ file = $ this ->createSubject ();
150
+ $ type = $ file ->getClientMediaType ();
151
+ if ($ type ) {
152
+ $ this ->assertTrue (is_string ($ type ));
153
+ } else {
154
+ $ this ->assertNull ($ type );
155
+ }
41
156
}
42
157
}
0 commit comments