VirusScannerListenerTest.php 2.62 KiB
<?php declare(strict_types=1);
/*
 * Copyright (C) 2015-2017 IRSTEA
 * All rights reserved.
 */
namespace Irstea\FileUploadBundle\Tests\Listener;
use Irstea\FileUploadBundle\Event\FileUploadCompleteEvent;
use Irstea\FileUploadBundle\Listener\VirusScannerListener;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit_Framework_TestCase;
use Irstea\FileUploadBundle\Model\UploadedFileInterface;
use Xenolope\Quahog\Client;
/**
 * Generated by PHPUnit_SkeletonGenerator on 2015-01-29 at 14:43:16.
class VirusScannerListenerTest extends PHPUnit_Framework_TestCase
    /**
     * @var VirusScannerListener
    protected $listener;
    /**
     * @var PHPUnit_Framework_MockObject_MockObject
    protected $client;
    /**
     * @var FileUploadCompleteEvent
    protected $event;
    /**
     * @var PHPUnit_Framework_MockObject_MockObject
    protected $file;
    /**
     * {@inheritDoc}
    protected function setUp()
        $this->client = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock();
        $this->file = $this->getMock(UploadedFileInterface::class);
        $this->file->expects(static::once())->method('getLocalPath')->willReturn('foopath');
        $this->file->expects(static::once())->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(static::once())->method('scanFile')->with('foopath')->willReturn($result);
        $this->file->expects(static::once())->method('setMetadata')->with(['virus_scanner' => ['has_virus' => false]]);
        $this->listener->onFileUploadCompleted($this->event);
717273747576777879808182838485868788899091929394
/** * @expectedException \Irstea\FileUploadBundle\Exception\RejectedFileException */ public function testOnFileUploadCompletedVirusFound() { $result = [ 'filename' => 'footpath', 'reason' => 'Terrible virus', 'status' => Client::RESULT_FOUND ]; $this->client->expects($this->any()) ->method('scanFile') ->with('foopath') ->willReturn($result); $this->file->expects(static::once()) ->method('setMetadata') ->with(['virus_scanner' => ['has_virus' => true, 'detected' => 'Terrible virus']]); $this->listener->onFileUploadCompleted($this->event); } }