@@ -687,6 +687,49 @@ public function testAfterDeleteWithProtectedFieldName()
687687 $ this ->assertTrue ($ behavior ->afterDelete (new Event ('fake.event ' ), $ this ->entity , new ArrayObject ()));
688688 }
689689
690+ public function testAfterDeleteWithNoFile ()
691+ {
692+ $ dir = '/some/path/ ' ;
693+
694+ $ methods = array_diff ($ this ->behaviorMethods , ['afterDelete ' , 'config ' , 'setConfig ' , 'getConfig ' ]);
695+ $ behavior = $ this ->getMockBuilder ('Josegonzalez\Upload\Model\Behavior\UploadBehavior ' )
696+ ->onlyMethods ($ methods )
697+ ->setConstructorArgs ([$ this ->table , $ this ->settings ])
698+ ->getMock ();
699+ $ behavior ->setConfig ($ this ->configOk );
700+
701+ $ this ->entity ->expects ($ this ->once ())
702+ ->method ('has ' )
703+ ->with ('dir ' )
704+ ->will ($ this ->returnValue (false ));
705+
706+ $ this ->entity ->expects ($ this ->exactly (2 ))
707+ ->method ('get ' )
708+ ->with ('field ' )
709+ ->will ($ this ->returnValue (null ));
710+
711+ $ behavior ->expects ($ this ->once ())
712+ ->method ('getPathProcessor ' )
713+ ->with ($ this ->entity , null , 'field ' , $ this ->configOk ['field ' ])
714+ ->willReturn ($ this ->processor );
715+
716+ $ this ->processor ->expects ($ this ->once ())
717+ ->method ('basepath ' )
718+ ->willReturn ($ dir );
719+
720+ $ behavior ->expects ($ this ->once ())
721+ ->method ('getWriter ' )
722+ ->with ($ this ->entity , null , 'field ' , $ this ->configOk ['field ' ])
723+ ->willReturn ($ this ->writer );
724+
725+ $ this ->writer ->expects ($ this ->once ())
726+ ->method ('delete ' )
727+ ->with ([$ dir ])
728+ ->willReturn ([false ]);
729+
730+ $ behavior ->afterDelete (new Event ('fake.event ' ), $ this ->entity , new ArrayObject ());
731+ }
732+
690733 public function testGetWriter ()
691734 {
692735 $ processor = $ this ->behavior ->getWriter ($ this ->entity , new UploadedFile (fopen ('php://temp ' , 'rw+ ' ), 1 , UPLOAD_ERR_OK , 'file.txt ' ), 'field ' , []);
0 commit comments