* initial commit
This commit is contained in:
38
test/AppTest/Action/GetLatestCameraPicturesActionTest.php
Normal file
38
test/AppTest/Action/GetLatestCameraPicturesActionTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\GetLatestCameraPicturesAction;
|
||||
use App\Service\CameraPictureManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class GetLatestCameraPicturesActionTest extends TestCase
|
||||
{
|
||||
/** @var CameraPictureManagerService */
|
||||
protected $cameraPictureManager;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->cameraPictureManager = $this->prophesize(CameraPictureManagerService::class);
|
||||
// $this->cameraPictureManager->getLatestCameraPictures()
|
||||
// ->willReturn([]);
|
||||
}
|
||||
|
||||
public function testReturnsJsonResponse()
|
||||
{
|
||||
$homePage = new GetLatestCameraPicturesAction(
|
||||
$this->cameraPictureManager->reveal()
|
||||
);
|
||||
|
||||
$response = $homePage->process(
|
||||
$this->prophesize(ServerRequestInterface::class)->reveal(),
|
||||
$this->prophesize(DelegateInterface::class)->reveal()
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
}
|
||||
}
|
||||
39
test/AppTest/Action/GetLatestCameraPicturesFactoryTest.php
Normal file
39
test/AppTest/Action/GetLatestCameraPicturesFactoryTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\GetLatestCameraPicturesAction;
|
||||
use App\Action\GetLatestCameraPicturesFactory;
|
||||
use App\Service\CameraPictureManagerService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class GetLatestCameraPicturesFactoryTest extends TestCase
|
||||
{
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = $this->prophesize(ContainerInterface::class);
|
||||
$cameraPictureManager = $this->prophesize(CameraPictureManagerService::class);
|
||||
$this->container->get(CameraPictureManagerService::class)->willReturn($cameraPictureManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function testFactory()
|
||||
{
|
||||
$factory = new GetLatestCameraPicturesFactory();
|
||||
$this->assertInstanceOf(GetLatestCameraPicturesFactory::class, $factory);
|
||||
|
||||
$getLatestCameraPicturesAction = $factory($this->container->reveal());
|
||||
$this->assertInstanceOf(GetLatestCameraPicturesAction::class, $getLatestCameraPicturesAction);
|
||||
}
|
||||
}
|
||||
48
test/AppTest/Action/HomePageActionTest.php
Normal file
48
test/AppTest/Action/HomePageActionTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\HomePageAction;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Diactoros\Response\HtmlResponse;
|
||||
use Zend\Expressive\Router\RouterInterface;
|
||||
use Zend\Expressive\Template\TemplateRendererInterface;
|
||||
|
||||
class HomePageActionTest extends TestCase
|
||||
{
|
||||
/** @var RouterInterface */
|
||||
protected $router;
|
||||
|
||||
/** @var TemplateRendererInterface */
|
||||
protected $renderer;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->router = $this->prophesize(RouterInterface::class);
|
||||
$this->renderer = $this->prophesize(TemplateRendererInterface::class);
|
||||
}
|
||||
|
||||
public function testReturnsHtmlResponse()
|
||||
{
|
||||
$this->renderer
|
||||
->render('app::home-page', Argument::type('array'))
|
||||
->willReturn('');
|
||||
|
||||
$homePage = new HomePageAction(
|
||||
$this->router->reveal(),
|
||||
$this->renderer->reveal(),
|
||||
$this->prophesize(Config::class)->reveal()
|
||||
);
|
||||
|
||||
$response = $homePage->process(
|
||||
$this->prophesize(ServerRequestInterface::class)->reveal(),
|
||||
$this->prophesize(DelegateInterface::class)->reveal()
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(HtmlResponse::class, $response);
|
||||
}
|
||||
}
|
||||
45
test/AppTest/Action/HomePageFactoryTest.php
Normal file
45
test/AppTest/Action/HomePageFactoryTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\HomePageAction;
|
||||
use App\Action\HomePageFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Zend\Expressive\Router\RouterInterface;
|
||||
use Zend\Expressive\Template\TemplateRendererInterface;
|
||||
|
||||
class HomePageFactoryTest extends TestCase
|
||||
{
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = $this->prophesize(ContainerInterface::class);
|
||||
|
||||
$router = $this->prophesize(RouterInterface::class);
|
||||
$templateRenderer = $this->prophesize(TemplateRendererInterface::class);
|
||||
|
||||
$this->container->get(TemplateRendererInterface::class)->willReturn($templateRenderer);
|
||||
$this->container->get(RouterInterface::class)->willReturn($router);
|
||||
$this->container->get("config")->willReturn(['application'=>[]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function testFactory()
|
||||
{
|
||||
$factory = new HomePageFactory();
|
||||
$this->assertInstanceOf(HomePageFactory::class, $factory);
|
||||
|
||||
$homePage = $factory($this->container->reveal());
|
||||
$this->assertInstanceOf(HomePageAction::class, $homePage);
|
||||
}
|
||||
}
|
||||
47
test/AppTest/Action/ShowCameraImageActionTest.php
Normal file
47
test/AppTest/Action/ShowCameraImageActionTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\ShowCameraImageAction;
|
||||
use App\Service\CameraPictureManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class ShowCameraImageActionTest extends TestCase
|
||||
{
|
||||
const CAM_DIR = "cam1";
|
||||
const IMG_FILE = "img1.png";
|
||||
|
||||
/** @var CameraPictureManagerService */
|
||||
protected $cameraPictureManager;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->cameraPictureManager = $this->prophesize(CameraPictureManagerService::class);
|
||||
$this->cameraPictureManager->getCameraImage(self::CAM_DIR, self::IMG_FILE)
|
||||
->willReturn($this->prophesize(JsonResponse::class));
|
||||
}
|
||||
|
||||
public function testReturnsJsonResponse()
|
||||
{
|
||||
$homePage = new ShowCameraImageAction(
|
||||
$this->cameraPictureManager->reveal()
|
||||
);
|
||||
|
||||
$request = $this->prophesize(ServerRequestInterface::class);
|
||||
$request->getAttribute('camera')
|
||||
->willReturn('cam1');
|
||||
$request->getAttribute('image')
|
||||
->willReturn('img1.png');
|
||||
|
||||
$response = $homePage->process(
|
||||
$request->reveal(),
|
||||
$this->prophesize(DelegateInterface::class)->reveal()
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
}
|
||||
}
|
||||
39
test/AppTest/Action/ShowCameraImageFactoryTest.php
Normal file
39
test/AppTest/Action/ShowCameraImageFactoryTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\ShowCameraImageAction;
|
||||
use App\Action\ShowCameraImageFactory;
|
||||
use App\Service\CameraPictureManagerService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class ShowCameraImageFactoryTest extends TestCase
|
||||
{
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = $this->prophesize(ContainerInterface::class);
|
||||
$cameraPictureManager = $this->prophesize(CameraPictureManagerService::class);
|
||||
$this->container->get(CameraPictureManagerService::class)->willReturn($cameraPictureManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function testFactory()
|
||||
{
|
||||
$factory = new ShowCameraImageFactory();
|
||||
$this->assertInstanceOf(ShowCameraImageFactory::class, $factory);
|
||||
|
||||
$showCameraImageAction = $factory($this->container->reveal());
|
||||
$this->assertInstanceOf(ShowCameraImageAction::class, $showCameraImageAction);
|
||||
}
|
||||
}
|
||||
17
test/AppTest/ConfigProviderTest.php
Normal file
17
test/AppTest/ConfigProviderTest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest;
|
||||
|
||||
use App\ConfigProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ConfigProviderTest extends TestCase
|
||||
{
|
||||
public function testFactory()
|
||||
{
|
||||
$factory = new ConfigProvider();
|
||||
$configProvided = $factory();
|
||||
$this->assertArrayHasKey('dependencies', $configProvided);
|
||||
$this->assertArrayHasKey('templates', $configProvided);
|
||||
}
|
||||
}
|
||||
54
test/AppTest/Entity/CameraImageTest.php
Normal file
54
test/AppTest/Entity/CameraImageTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Entity;
|
||||
|
||||
use App\Entity\CameraImage;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CameraImageTest extends TestCase
|
||||
{
|
||||
private static $testData;
|
||||
|
||||
/** @var CameraImage */
|
||||
private $cameraImage;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$testData = [
|
||||
"camera" => "cam1",
|
||||
"imageName" => "img1.png",
|
||||
"createdAt" => new \DateTime(),
|
||||
"text" => "cam1",
|
||||
];
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->cameraImage = new CameraImage();
|
||||
}
|
||||
|
||||
public function testCanGetAndSet()
|
||||
{
|
||||
$this->cameraImage
|
||||
->setCamera(self::$testData["camera"])
|
||||
->setImageName(self::$testData["imageName"])
|
||||
->setCreatedAt(self::$testData["createdAt"])
|
||||
->setText(self::$testData["text"]);
|
||||
|
||||
$this->assertEquals(self::$testData["camera"], $this->cameraImage->getCamera());
|
||||
$this->assertEquals(self::$testData["imageName"], $this->cameraImage->getImageName());
|
||||
$this->assertEquals(self::$testData["createdAt"], $this->cameraImage->getCreatedAt());
|
||||
$this->assertEquals(self::$testData["text"], $this->cameraImage->getText());
|
||||
}
|
||||
|
||||
public function testJsonSerialize()
|
||||
{
|
||||
$this->cameraImage
|
||||
->setCamera(self::$testData["camera"])
|
||||
->setImageName(self::$testData["imageName"])
|
||||
->setCreatedAt(self::$testData["createdAt"])
|
||||
->setText(self::$testData["text"]);
|
||||
$result = json_encode($this->cameraImage);
|
||||
$this->assertInternalType("string", $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Service;
|
||||
|
||||
use App\Service\CameraPictureManagerService;
|
||||
use App\Service\CameraPictureManagerServiceFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class CameraPictureManagerServiceFactoryTest extends TestCase
|
||||
{
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = $this->prophesize(ContainerInterface::class);
|
||||
$this->container->get("config")->willReturn(['application'=>[]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function testFactory()
|
||||
{
|
||||
$factory = new CameraPictureManagerServiceFactory();
|
||||
$this->assertInstanceOf(CameraPictureManagerServiceFactory::class, $factory);
|
||||
|
||||
$cameraPictureManager = $factory($this->container->reveal());
|
||||
$this->assertInstanceOf(CameraPictureManagerService::class, $cameraPictureManager);
|
||||
}
|
||||
}
|
||||
69
test/AppTest/Service/CameraPictureManagerServiceTest.php
Normal file
69
test/AppTest/Service/CameraPictureManagerServiceTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user