Test erweitert um die Coverage zu erhöhen.
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use PDO;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Slim\Psr7\Request;
|
||||
use Slim\Psr7\Response;
|
||||
use TorstenHettstedt\TimekeepingApi\Controller\NotDatabasesException;
|
||||
use TorstenHettstedt\TimekeepingApi\Controller\WorkingHoursViewController;
|
||||
|
||||
class WorkingHoursViewControllerTest extends Unit
|
||||
{
|
||||
protected ContainerInterface $container;
|
||||
protected Request $request;
|
||||
protected Response $response;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _before(): void
|
||||
{
|
||||
parent::_before();
|
||||
/** @noinspection SpellCheckingInspection */
|
||||
$this->container = $this->makeEmpty(ContainerInterface::class, [
|
||||
'has' => true,
|
||||
'get' => new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass')
|
||||
]);
|
||||
$this->request = $this->makeEmpty(Request::class, []);
|
||||
$this->response = $this->makeEmpty(Response::class, [
|
||||
'getBody' => $this->makeEmpty(StreamInterface::class, [
|
||||
'write' => function (mixed $data) {
|
||||
$this->assertIsString($data);
|
||||
$this->assertJson($data);
|
||||
},
|
||||
]),
|
||||
'withHeader' => $this->makeEmpty(Response::class, [
|
||||
'withStatus' => $this->makeEmpty(Response::class),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testBrowseMonthlyWithNonDatabase(): void
|
||||
{
|
||||
$this->container = $this->makeEmpty(ContainerInterface::class, [
|
||||
'has' => false
|
||||
]);
|
||||
$controller = new WorkingHoursViewController($this->container);
|
||||
$this->expectException(NotDatabasesException::class);
|
||||
$controller->browseMonthly($this->request, $this->response, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testBrowseMonthly(): void
|
||||
{
|
||||
$controller = new WorkingHoursViewController($this->container);
|
||||
$response = $controller->browseMonthly($this->request, $this->response, []);
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testBrowseYearlyWithNonDatabase(): void
|
||||
{
|
||||
$this->container = $this->makeEmpty(ContainerInterface::class, [
|
||||
'has' => false
|
||||
]);
|
||||
$controller = new WorkingHoursViewController($this->container);
|
||||
$this->expectException(NotDatabasesException::class);
|
||||
$controller->browseYearly($this->request, $this->response, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testBrowseYearly(): void
|
||||
{
|
||||
$controller = new WorkingHoursViewController($this->container);
|
||||
$response = $controller->browseYearly($this->request, $this->response, []);
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testBrowseWeeklyWithNonDatabase(): void
|
||||
{
|
||||
$this->container = $this->makeEmpty(ContainerInterface::class, [
|
||||
'has' => false
|
||||
]);
|
||||
$controller = new WorkingHoursViewController($this->container);
|
||||
$this->expectException(NotDatabasesException::class);
|
||||
$controller->browseWeekly($this->request, $this->response, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testBrowseWeekly(): void
|
||||
{
|
||||
$controller = new WorkingHoursViewController($this->container);
|
||||
$response = $controller->browseWeekly($this->request, $this->response, []);
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user