11
11
12
12
namespace Symfony \Component \Validator \Tests \Constraints ;
13
13
14
+ use Symfony \Component \HttpFoundation \File \File as FileObject ;
14
15
use Symfony \Component \HttpFoundation \File \UploadedFile ;
15
16
use Symfony \Component \Validator \Constraints \File ;
16
17
use Symfony \Component \Validator \Constraints \FileValidator ;
@@ -283,21 +284,10 @@ public function testBinaryFormat($bytesWritten, $limit, $binaryFormat, $sizeAsSt
283
284
284
285
public function testValidMimeType ()
285
286
{
286
- $ file = $ this
287
- ->getMockBuilder ('Symfony\Component\HttpFoundation\File\File ' )
288
- ->setConstructorArgs ([__DIR__ .'/Fixtures/foo ' ])
289
- ->getMock ();
290
- $ file
291
- ->expects ($ this ->once ())
292
- ->method ('getPathname ' )
293
- ->willReturn ($ this ->path );
294
- $ file
295
- ->expects ($ this ->once ())
296
- ->method ('getMimeType ' )
297
- ->willReturn ('image/jpg ' );
287
+ $ file = new FileObject (__DIR__ .'/Fixtures/blank.jpg ' );
298
288
299
289
$ constraint = new File ([
300
- 'mimeTypes ' => ['image/png ' , 'image/jpg ' ],
290
+ 'mimeTypes ' => ['image/png ' , 'image/jpeg ' ],
301
291
]);
302
292
303
293
$ this ->validator ->validate ($ file , $ constraint );
@@ -307,18 +297,7 @@ public function testValidMimeType()
307
297
308
298
public function testValidWildcardMimeType ()
309
299
{
310
- $ file = $ this
311
- ->getMockBuilder ('Symfony\Component\HttpFoundation\File\File ' )
312
- ->setConstructorArgs ([__DIR__ .'/Fixtures/foo ' ])
313
- ->getMock ();
314
- $ file
315
- ->expects ($ this ->once ())
316
- ->method ('getPathname ' )
317
- ->willReturn ($ this ->path );
318
- $ file
319
- ->expects ($ this ->once ())
320
- ->method ('getMimeType ' )
321
- ->willReturn ('image/jpg ' );
300
+ $ file = new FileObject (__DIR__ .'/Fixtures/test.gif ' );
322
301
323
302
$ constraint = new File ([
324
303
'mimeTypes ' => ['image/* ' ],
@@ -331,62 +310,40 @@ public function testValidWildcardMimeType()
331
310
332
311
public function testInvalidMimeType ()
333
312
{
334
- $ file = $ this
335
- ->getMockBuilder ('Symfony\Component\HttpFoundation\File\File ' )
336
- ->setConstructorArgs ([__DIR__ .'/Fixtures/foo ' ])
337
- ->getMock ();
338
- $ file
339
- ->expects ($ this ->once ())
340
- ->method ('getPathname ' )
341
- ->willReturn ($ this ->path );
342
- $ file
343
- ->expects ($ this ->once ())
344
- ->method ('getMimeType ' )
345
- ->willReturn ('application/pdf ' );
313
+ $ file = new FileObject (__DIR__ .'/Fixtures/blank.pdf ' );
346
314
347
315
$ constraint = new File ([
348
- 'mimeTypes ' => ['image/png ' , 'image/jpg ' ],
316
+ 'mimeTypes ' => ['image/png ' , 'image/jpeg ' ],
349
317
'mimeTypesMessage ' => 'myMessage ' ,
350
318
]);
351
319
352
320
$ this ->validator ->validate ($ file , $ constraint );
353
321
354
322
$ this ->buildViolation ('myMessage ' )
355
323
->setParameter ('{{ type }} ' , '"application/pdf" ' )
356
- ->setParameter ('{{ types }} ' , '"image/png", "image/jpg " ' )
357
- ->setParameter ('{{ file }} ' , '" ' .$ this -> path .'" ' )
358
- ->setParameter ('{{ name }} ' , '" ' . basename ( $ this -> path ). ' " ' )
324
+ ->setParameter ('{{ types }} ' , '"image/png", "image/jpeg " ' )
325
+ ->setParameter ('{{ file }} ' , '" ' .__DIR__ . ' /Fixtures/blank.pdf ' .'" ' )
326
+ ->setParameter ('{{ name }} ' , '"blank.pdf " ' )
359
327
->setCode (File::INVALID_MIME_TYPE_ERROR )
360
328
->assertRaised ();
361
329
}
362
330
363
331
public function testInvalidWildcardMimeType ()
364
332
{
365
- $ file = $ this
366
- ->getMockBuilder ('Symfony\Component\HttpFoundation\File\File ' )
367
- ->setConstructorArgs ([__DIR__ .'/Fixtures/foo ' ])
368
- ->getMock ();
369
- $ file
370
- ->expects ($ this ->once ())
371
- ->method ('getPathname ' )
372
- ->willReturn ($ this ->path );
373
- $ file
374
- ->expects ($ this ->once ())
375
- ->method ('getMimeType ' )
376
- ->willReturn ('application/pdf ' );
333
+ $ file = new FileObject (__DIR__ .'/Fixtures/blank.pdf ' );
377
334
378
335
$ constraint = new File ([
379
- 'mimeTypes ' => ['image/* ' , 'image/jpg ' ],
336
+ 'mimeTypes ' => ['image/* ' , 'image/jpeg ' ],
380
337
'mimeTypesMessage ' => 'myMessage ' ,
381
338
]);
382
339
383
340
$ this ->validator ->validate ($ file , $ constraint );
384
341
385
342
$ this ->buildViolation ('myMessage ' )
386
343
->setParameter ('{{ type }} ' , '"application/pdf" ' )
387
- ->setParameter ('{{ types }} ' , '"image/*", "image/jpg " ' )
388
- ->setParameter ('{{ file }} ' , '" ' .$ this -> path .'" ' )
389
- ->setParameter ('{{ name }} ' , '" ' . basename ( $ this -> path ). ' " ' )
344
+ ->setParameter ('{{ types }} ' , '"image/*", "image/jpeg " ' )
345
+ ->setParameter ('{{ file }} ' , '" ' .__DIR__ . ' /Fixtures/blank.pdf ' .'" ' )
346
+ ->setParameter ('{{ name }} ' , '"blank.pdf " ' )
390
347
->setCode (File::INVALID_MIME_TYPE_ERROR )
391
348
->assertRaised ();
392
349
}
0 commit comments