@@ -438,7 +438,7 @@ public function testAfterDeleteOk()
438
438
$ this ->entity ->expects ($ this ->any ())
439
439
->method ('get ' )
440
440
->with ('field ' )
441
- ->will ($ this ->returnValue ($ this -> dataOk [ ' field ' ] ));
441
+ ->will ($ this ->returnValue (' file.txt ' ));
442
442
$ behavior ->expects ($ this ->any ())
443
443
->method ('getPathProcessor ' )
444
444
->willReturn ($ this ->processor );
@@ -463,7 +463,7 @@ public function testAfterDeleteFail()
463
463
$ this ->entity ->expects ($ this ->any ())
464
464
->method ('get ' )
465
465
->with ('field ' )
466
- ->will ($ this ->returnValue ($ this -> dataOk [ ' field ' ] ));
466
+ ->will ($ this ->returnValue (' file.txt ' ));
467
467
$ behavior ->expects ($ this ->any ())
468
468
->method ('getPathProcessor ' )
469
469
->willReturn ($ this ->processor );
@@ -498,13 +498,7 @@ public function testAfterDeleteSkip()
498
498
public function testAfterDeleteUsesPathProcessorToDetectPathToTheFile ()
499
499
{
500
500
$ dir = '/some/path/ ' ;
501
- $ field = new UploadedFile (
502
- fopen ('php://temp ' , 'wb+ ' ),
503
- 1 ,
504
- UPLOAD_ERR_OK ,
505
- 'file.txt ' ,
506
- 'text/plain '
507
- );
501
+ $ field = 'file.txt ' ;
508
502
509
503
$ methods = array_diff ($ this ->behaviorMethods , ['afterDelete ' , 'config ' , 'setConfig ' , 'getConfig ' ]);
510
504
$ behavior = $ this ->getMockBuilder ('Josegonzalez\Upload\Model\Behavior\UploadBehavior ' )
@@ -540,7 +534,7 @@ public function testAfterDeleteUsesPathProcessorToDetectPathToTheFile()
540
534
// and here we check that file with right path will be deleted
541
535
$ this ->writer ->expects ($ this ->once ())
542
536
->method ('delete ' )
543
- ->with ([$ dir . $ field-> getClientFilename () ])
537
+ ->with ([$ dir . $ field ])
544
538
->willReturn ([true ]);
545
539
546
540
$ behavior ->afterDelete (new Event ('fake.event ' ), $ this ->entity , new ArrayObject ());
@@ -549,13 +543,7 @@ public function testAfterDeleteUsesPathProcessorToDetectPathToTheFile()
549
543
public function testAfterDeletePrefersStoredPathOverPathProcessor ()
550
544
{
551
545
$ dir = '/some/path/ ' ;
552
- $ field = new UploadedFile (
553
- fopen ('php://temp ' , 'wb+ ' ),
554
- 1 ,
555
- UPLOAD_ERR_OK ,
556
- 'file.txt ' ,
557
- 'text/plain '
558
- );
546
+ $ field = 'file.txt ' ;
559
547
560
548
$ methods = array_diff ($ this ->behaviorMethods , ['afterDelete ' , 'config ' , 'setConfig ' , 'getConfig ' ]);
561
549
$ behavior = $ this ->getMockBuilder ('Josegonzalez\Upload\Model\Behavior\UploadBehavior ' )
@@ -582,15 +570,15 @@ public function testAfterDeletePrefersStoredPathOverPathProcessor()
582
570
583
571
$ this ->writer ->expects ($ this ->once ())
584
572
->method ('delete ' )
585
- ->with ([$ dir . $ field-> getClientFilename () ])
573
+ ->with ([$ dir . $ field ])
586
574
->will ($ this ->returnValue ([true ]));
587
575
588
576
$ this ->assertTrue ($ behavior ->afterDelete (new Event ('fake.event ' ), $ this ->entity , new ArrayObject ()));
589
577
}
590
578
591
579
public function testAfterDeleteNoDeleteCallback ()
592
580
{
593
- $ this -> entity -> field = rand (1000 , 9999 );
581
+ $ field = ( string ) rand (1000 , 9999 );
594
582
$ path = rand (1000 , 9999 ) . DIRECTORY_SEPARATOR ;
595
583
$ methods = array_diff ($ this ->behaviorMethods , ['afterDelete ' , 'config ' , 'setConfig ' , 'getConfig ' ]);
596
584
$ behavior = $ this ->getMockBuilder ('Josegonzalez\Upload\Model\Behavior\UploadBehavior ' )
@@ -601,12 +589,12 @@ public function testAfterDeleteNoDeleteCallback()
601
589
$ this ->configOk ['field ' ]['deleteCallback ' ] = null ;
602
590
603
591
$ behavior ->setConfig ($ this ->configOk );
604
- $ this ->entity ->expects ($ this ->any ( ))
592
+ $ this ->entity ->expects ($ this ->exactly ( 2 ))
605
593
->method ('get ' )
606
594
->with ('field ' )
607
- ->will ($ this ->returnValue ($ this -> dataOk [ ' field ' ] ));
595
+ ->will ($ this ->returnValue ($ field ));
608
596
$ behavior ->expects ($ this ->once ())->method ('getPathProcessor ' )
609
- ->with ($ this ->entity , $ this -> dataOk [ ' field ' ] , 'field ' , $ this ->configOk ['field ' ])
597
+ ->with ($ this ->entity , $ field , 'field ' , $ this ->configOk ['field ' ])
610
598
->willReturn ($ this ->processor );
611
599
$ this ->processor ->expects ($ this ->once ())->method ('basepath ' )
612
600
->willReturn ($ path );
@@ -616,7 +604,7 @@ public function testAfterDeleteNoDeleteCallback()
616
604
$ this ->writer ->expects ($ this ->once ())
617
605
->method ('delete ' )
618
606
->with ([
619
- $ path . $ this -> entity -> field . $ this -> dataOk [ ' field ' ]-> getClientFilename () ,
607
+ $ path . $ field ,
620
608
])
621
609
->willReturn ([true , true , true ]);
622
610
@@ -625,7 +613,7 @@ public function testAfterDeleteNoDeleteCallback()
625
613
626
614
public function testAfterDeleteUsesDeleteCallback ()
627
615
{
628
- $ this -> entity -> field = rand (1000 , 9999 );
616
+ $ field = ( string ) rand (1000 , 9999 );
629
617
$ path = rand (1000 , 9999 ) . DIRECTORY_SEPARATOR ;
630
618
$ methods = array_diff ($ this ->behaviorMethods , ['afterDelete ' , 'config ' , 'setConfig ' , 'getConfig ' ]);
631
619
$ behavior = $ this ->getMockBuilder ('Josegonzalez\Upload\Model\Behavior\UploadBehavior ' )
@@ -635,19 +623,19 @@ public function testAfterDeleteUsesDeleteCallback()
635
623
636
624
$ this ->configOk ['field ' ]['deleteCallback ' ] = function ($ path , $ entity , $ field , $ settings ) {
637
625
return [
638
- $ path . $ entity ->{ $ field} ,
639
- $ path . 'sm- ' . $ entity ->{ $ field} ,
640
- $ path . 'lg- ' . $ entity ->{ $ field} ,
626
+ $ path . $ entity ->get ( $ field) ,
627
+ $ path . 'sm- ' . $ entity ->get ( $ field) ,
628
+ $ path . 'lg- ' . $ entity ->get ( $ field) ,
641
629
];
642
630
};
643
631
644
632
$ behavior ->setConfig ($ this ->configOk );
645
- $ this ->entity ->expects ($ this ->any ( ))
633
+ $ this ->entity ->expects ($ this ->exactly ( 4 ))
646
634
->method ('get ' )
647
635
->with ('field ' )
648
- ->will ($ this ->returnValue ($ this -> dataOk [ ' field ' ] ));
636
+ ->will ($ this ->returnValue ($ field ));
649
637
$ behavior ->expects ($ this ->once ())->method ('getPathProcessor ' )
650
- ->with ($ this ->entity , $ this -> dataOk [ ' field ' ] , 'field ' , $ this ->configOk ['field ' ])
638
+ ->with ($ this ->entity , $ field , 'field ' , $ this ->configOk ['field ' ])
651
639
->willReturn ($ this ->processor );
652
640
$ this ->processor ->expects ($ this ->once ())->method ('basepath ' )
653
641
->willReturn ($ path );
@@ -657,9 +645,9 @@ public function testAfterDeleteUsesDeleteCallback()
657
645
$ this ->writer ->expects ($ this ->once ())
658
646
->method ('delete ' )
659
647
->with ([
660
- $ path . $ this -> entity -> field ,
661
- $ path . 'sm- ' . $ this -> entity -> field ,
662
- $ path . 'lg- ' . $ this -> entity -> field ,
648
+ $ path . $ field ,
649
+ $ path . 'sm- ' . $ field ,
650
+ $ path . 'lg- ' . $ field ,
663
651
])
664
652
->willReturn ([true , true , true ]);
665
653
0 commit comments