camera-picture-slide/test/AppTest/Service/CameraPictureManagerServiceTest.php
Dávid Danyi 139116d76f * camera images ordered by mtime
* display image by camera is now second to last, not the last one
* indent changes in javascript code
* js code should now be more roboust if there are camera folders getting deleted
2018-01-25 15:44:39 +01:00

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 = 'imgXX.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);
}
}