Commit 38e33e0f authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

CS.

parent 016a9968
No related merge requests found
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
Showing with 11 additions and 15 deletions
+11 -15
......@@ -6,9 +6,9 @@
namespace Irstea\FileUploadBundle\Listener;
use Xenolope\Quahog\Client;
use Irstea\FileUploadBundle\Event\FileUploadCompleteEvent;
use Irstea\FileUploadBundle\Exception\RejectedFileException;
use Xenolope\Quahog\Client;
use Xenolope\Quahog\Exception\ConnectionException;
/**
......@@ -21,7 +21,6 @@ class VirusScannerListener
*/
private $client;
/**
* @param Client $client
*/
......@@ -30,7 +29,6 @@ class VirusScannerListener
$this->client = $client;
}
/**
* @param FileUploadCompleteEvent $event
*/
......@@ -60,16 +58,17 @@ class VirusScannerListener
}
/**
* @return Client
* @throws ConnectionException
*
* @return Client
*/
private function getClient(): Client
{
try {
// Check clamd server's state
$this->client->ping();
return $this->client;
return $this->client;
} catch (ConnectionException $connectionException) {
throw $connectionException;
}
......
......@@ -8,9 +8,9 @@ namespace Irstea\FileUploadBundle\Tests\Listener;
use Irstea\FileUploadBundle\Event\FileUploadCompleteEvent;
use Irstea\FileUploadBundle\Listener\VirusScannerListener;
use Irstea\FileUploadBundle\Model\UploadedFileInterface;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit_Framework_TestCase;
use Irstea\FileUploadBundle\Model\UploadedFileInterface;
use Xenolope\Quahog\Client;
use Xenolope\Quahog\Exception\ConnectionException;
......@@ -55,13 +55,12 @@ class VirusScannerListenerTest extends PHPUnit_Framework_TestCase
$this->listener = new VirusScannerListener($this->client);
}
public function testOnFileUploadCompletedResultOk()
{
$result = [
'filename' => 'footpath',
'reason' => null,
'status' => Client::RESULT_OK
'reason' => null,
'status' => Client::RESULT_OK,
];
$this->client->expects($this->any())->method('scanFile')->with('foopath')->willReturn($result);
......@@ -77,11 +76,11 @@ class VirusScannerListenerTest extends PHPUnit_Framework_TestCase
{
$result = [
'filename' => 'footpath',
'reason' => 'Terrible virus',
'status' => Client::RESULT_FOUND
'reason' => 'Terrible virus',
'status' => Client::RESULT_FOUND,
];
$this->client->expects($this->any())
$this->client->expects($this->any())
->method('scanFile')
->with('foopath')
->willReturn($result);
......@@ -94,7 +93,7 @@ class VirusScannerListenerTest extends PHPUnit_Framework_TestCase
}
/**
* @expectedException Xenolope\Quahog\Exception\ConnectionException
* @expectedException \Xenolope\Quahog\Exception\ConnectionException
*/
public function testGetClientFailed()
{
......@@ -102,11 +101,9 @@ class VirusScannerListenerTest extends PHPUnit_Framework_TestCase
$this->listener->onFileUploadCompleted($this->event);
}
public function testGetClientSucceed()
{
$this->client->expects($this->any())->method('ping')->willReturn(true);
$this->listener->onFileUploadCompleted($this->event);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment