22
33namespace Http \Psr7Test ;
44
5+ use Psr \Http \Message \StreamInterface ;
56use Psr \Http \Message \UploadedFileInterface ;
67
78/**
8- * TODO Write me.
9- *
109 * @author Tobias Nyholm <tobias.nyholm@gmail.com>
1110 */
1211abstract class UploadedFileIntegrationTest extends BaseTest
@@ -26,17 +25,133 @@ abstract class UploadedFileIntegrationTest extends BaseTest
2625 */
2726 abstract public function createSubject ();
2827
28+ public static function setUpBeforeClass ()
29+ {
30+ @mkdir ('.tmp ' );
31+ parent ::setUpBeforeClass ();
32+ }
33+
2934 protected function setUp ()
3035 {
3136 $ this ->uploadedFile = $ this ->createSubject ();
3237 }
3338
34- public function testNothing ()
39+ public function testGetStream ()
3540 {
3641 if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
3742 $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
3843 }
3944
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+ }
41156 }
42157}
0 commit comments