70 lines
2.6 KiB
PHP
70 lines
2.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace AppTest\Service;
|
||
|
|
|
||
|
|
use App\Service\CameraPictureManagerService;
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
use Prophecy\Argument;
|
||
|
|
use Zend\Config\Config;
|
||
|
|
use Zend\Diactoros\Response;
|
||
|
|
|
||
|
|
class CameraPictureManagerServiceTest extends TestCase
|
||
|
|
{
|
||
|
|
const EXISTING_CAM_DIR = 'cam1';
|
||
|
|
const EXISTING_IMAGE = 'img1.png';
|
||
|
|
const MISSING_IMAGE = 'img9.png';
|
||
|
|
const TEST_DATA_DIR = 'test/data';
|
||
|
|
|
||
|
|
/** @var Config */
|
||
|
|
protected $config;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
||
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
||
|
|
*/
|
||
|
|
protected function setUp()
|
||
|
|
{
|
||
|
|
$this->config = $this->prophesize(Config::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testThrowsExceptionOnMissingConfig()
|
||
|
|
{
|
||
|
|
$this->config->get('cameraImageBaseFolder', Argument::any())->willReturn(false);
|
||
|
|
$cameraPictureManager = new CameraPictureManagerService($this->config->reveal());
|
||
|
|
$this->expectException(\InvalidArgumentException::class);
|
||
|
|
$cameraPictureManager->getLatestCameraPictures();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testThrowsExceptionOnBadConfig()
|
||
|
|
{
|
||
|
|
$this->config->get('cameraImageBaseFolder', Argument::any())->willReturn("--sadf");
|
||
|
|
$cameraPictureManager = new CameraPictureManagerService($this->config->reveal());
|
||
|
|
$this->expectException(\InvalidArgumentException::class);
|
||
|
|
$cameraPictureManager->getLatestCameraPictures();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testReturnsImages()
|
||
|
|
{
|
||
|
|
$this->config->get('cameraImageBaseFolder', Argument::any())->willReturn(self::TEST_DATA_DIR);
|
||
|
|
$cameraPictureManager = new CameraPictureManagerService($this->config->reveal());
|
||
|
|
$result = $cameraPictureManager->getLatestCameraPictures();
|
||
|
|
$this->assertCount(3, $result);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testThrowsExceptionOnBadImage()
|
||
|
|
{
|
||
|
|
$this->config->get('cameraImageBaseFolder', Argument::any())->willReturn(self::TEST_DATA_DIR);
|
||
|
|
$cameraPictureManager = new CameraPictureManagerService($this->config->reveal());
|
||
|
|
$this->expectException(\InvalidArgumentException::class);
|
||
|
|
$cameraPictureManager->getCameraImage(self::EXISTING_CAM_DIR, self::MISSING_IMAGE);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testReturnsResponseOnExistingImage()
|
||
|
|
{
|
||
|
|
$this->config->get('cameraImageBaseFolder', Argument::any())->willReturn(self::TEST_DATA_DIR);
|
||
|
|
$cameraPictureManager = new CameraPictureManagerService($this->config->reveal());
|
||
|
|
$result = $cameraPictureManager->getCameraImage(self::EXISTING_CAM_DIR, self::EXISTING_IMAGE);
|
||
|
|
$this->assertInstanceOf(Response::class, $result);
|
||
|
|
}
|
||
|
|
}
|