client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock(); $this->file = $this->createMock(UploadedFileInterface::class); $this->file->expects($this->any())->method('getLocalPath')->willReturn('foopath'); $this->file->expects($this->any())->method('getMetadata')->willReturn([]); $this->event = new FileUploadCompleteEvent($this->file); $this->listener = new VirusScannerListener($this->client); } public function testOnFileUploadCompletedResultOk() { $result = [ 'filename' => 'footpath', 'reason' => null, 'status' => Client::RESULT_OK, ]; $this->client->expects($this->once())->method('scanFile')->with('foopath')->willReturn($result); $this->file->expects($this->once())->method('setMetadata')->with(['virus_scanner' => ['has_virus' => false]]); $this->listener->onFileUploadCompleted($this->event); } /** * @expectedException \Irstea\FileUploadBundle\Exception\RejectedFileException */ public function testOnFileUploadCompletedVirusFound() { $result = [ 'filename' => 'foopath', 'reason' => 'Terrible virus', 'status' => Client::RESULT_FOUND, ]; $this->client->expects($this->once()) ->method('scanFile') ->with('foopath') ->willReturn($result); $this->file->expects($this->once()) ->method('setMetadata') ->with(['virus_scanner' => ['has_virus' => true, 'detected' => 'Terrible virus']]); $this->listener->onFileUploadCompleted($this->event); } /** * @expectedException \Xenolope\Quahog\Exception\ConnectionException */ public function testGetClientFailed() { $this->client->expects($this->once())->method('ping')->willThrowException(new ConnectionException()); $this->listener->onFileUploadCompleted($this->event); } public function testGetClientSucceed() { $this->client->expects($this->once())->method('ping')->willReturn(true); $this->listener->onFileUploadCompleted($this->event); } }