feature-ui/eintrag-per-woche #23

Merged
TorstenHettstedt merged 20 commits from feature-ui/eintrag-per-woche into master 2022-02-28 16:04:31 +01:00
3 changed files with 290 additions and 23 deletions
Showing only changes of commit bcc6448fa1 - Show all commits
@@ -0,0 +1,10 @@
<?php
namespace TorstenHettstedt\TimekeepingApi\Repositories;
class RepositoryBadWhereDataException extends RepositoryException
{
}
@@ -2,6 +2,7 @@
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller; namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
use Codeception\Example;
use Codeception\Test\Unit; use Codeception\Test\Unit;
use Exception; use Exception;
use PDO; use PDO;
@@ -37,13 +38,13 @@ class WorkingHoursControllerTest extends Unit
/** @noinspection SpellCheckingInspection */ /** @noinspection SpellCheckingInspection */
$this->container = $this->makeEmpty(ContainerInterface::class, [ $this->container = $this->makeEmpty(ContainerInterface::class, [
'has' => true, 'has' => true,
'get' => new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass') 'get' => new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass'),
]); ]);
$this->request = $this->makeEmpty(Request::class, [ $this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::EXISTING_DATE, 'workingDay' => self::EXISTING_DATE,
'workingTime' => self::EXISTING_INTERVAL, 'workingTime' => self::EXISTING_INTERVAL,
] ],
]); ]);
$this->response = $this->makeEmpty(Response::class, [ $this->response = $this->makeEmpty(Response::class, [
'getBody' => $this->makeEmpty(StreamInterface::class, [ 'getBody' => $this->makeEmpty(StreamInterface::class, [
@@ -65,23 +66,202 @@ class WorkingHoursControllerTest extends Unit
public function testConstructWithNonDatabase(): void public function testConstructWithNonDatabase(): void
{ {
$this->container = $this->makeEmpty(ContainerInterface::class, [ $this->container = $this->makeEmpty(ContainerInterface::class, [
'has' => false 'has' => false,
]); ]);
$this->expectException(NotDatabasesException::class); $this->expectException(NotDatabasesException::class);
new WorkingHoursController($this->container); new WorkingHoursController($this->container);
} }
/** /**
* @return array<int, array<int, array<string, string>>>
*/
public function valideFilterDataProvider(): array
{
return [
[
[],
],
[
[
'start-date' => '2020-03-01',
'end-date' => '2020-03-31',
],
],
[
[
'start-date' => '2020-03-01',
],
],
[
[
'end-date' => '2020-03-31',
],
],
];
}
/**
* @param array<string, string> $queryParams
*
* @dataProvider valideFilterDataProvider
*
* @throws HttpInternalServerErrorException
* @throws NotDatabasesException * @throws NotDatabasesException
* @throws Exception * @throws Exception
*/ */
public function testBrowse(): void public function testBrowseWithValideParameter(array $queryParams): void
{ {
$this->request = $this->makeEmpty(Request::class, [
'getQueryParams' => $queryParams,
]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
$response = $controller->browse($this->request, $this->response, []); $response = $controller->browse($this->request, $this->response, []);
$this->assertInstanceOf(Response::class, $response); $this->assertInstanceOf(Response::class, $response);
} }
/**
* @return array<int, array<int, array<string, string|null>>>
*/
public function invalideFilterDataProvider(): array
{
return [
[
[
'start-data' => null,
'end-data' => null,
],
],
[
[
'start-data' => null,
],
],
[
[
'end-data' => null,
],
],
[
[
'start-data' => '2020-03-01',
'end-data' => null,
],
],
[
[
'start-data' => null,
'end-data' => '2020-03-31',
],
],
//
[
[
'start-data' => '2020-03-00',
'end-data' => '2020-04-31',
],
],
[
[
'start-data' => '2020-03-00',
],
],
[
[
'end-data' => '2020-04-31',
],
],
[
[
'start-data' => '2020-03-01',
'end-data' => '2020-04-31',
],
],
[
[
'start-data' => '2020-03-00',
'end-data' => '2020-03-31',
],
],
//
[
[
'start-data' => '2020-03',
'end-data' => '2020-03',
],
],
[
[
'start-data' => '2020-03',
],
],
[
[
'end-data' => '2020-03',
],
],
[
[
'start-data' => '2020-03-01',
'end-data' => '2020-03',
],
],
[
[
'start-data' => '2020-03',
'end-data' => '2020-03-31',
],
],
//
[
[
'start-data' => '2020',
'end-data' => '2020',
],
],
[
[
'start-data' => '2020',
],
],
[
[
'end-data' => '2020',
],
],
[
[
'start-data' => '2020-03-01',
'end-data' => '2020',
],
],
[
[
'start-data' => '2020',
'end-data' => '2020-03-31',
],
],
];
}
/**
* @param array<string, string> $queryParams
*
* @dataProvider invalideFilterDataProvider
*
* @throws HttpInternalServerErrorException
* @throws NotDatabasesException
* @throws Exception
*/
public function testBrowseWithInvalideParameter(array $queryParams): void
{
$this->request = $this->makeEmpty(Request::class, [
'getQueryParams' => $queryParams,
]);
$controller = new WorkingHoursController($this->container);
$this->expectException(HttpBadRequestException::class);
$controller->browse($this->request, $this->response, []);
}
/** /**
* @throws NotDatabasesException * @throws NotDatabasesException
* @throws HttpBadRequestException * @throws HttpBadRequestException
@@ -91,7 +271,7 @@ class WorkingHoursControllerTest extends Unit
{ {
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
$response = $controller->update($this->request, $this->response, [ $response = $controller->update($this->request, $this->response, [
'id' => self::EXISTING_DATE 'id' => self::EXISTING_DATE,
]); ]);
$this->assertInstanceOf(Response::class, $response); $this->assertInstanceOf(Response::class, $response);
} }
@@ -106,23 +286,23 @@ class WorkingHoursControllerTest extends Unit
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
$this->expectException(HttpNotFoundException::class); $this->expectException(HttpNotFoundException::class);
$controller->update($this->request, $this->response, [ $controller->update($this->request, $this->response, [
'id' => self::NEW_DATE 'id' => self::NEW_DATE,
]); ]);
} }
/** /**
* @return string[][] * @return string[][]
*/ */
public function invalidDataProvider(): array public function invalidCreatDataProvider(): array
{ {
return [ return [
[ [
self::NEW_DATE, self::NEW_DATE,
'07:59' '07:59',
], ],
[ [
'2020-13-33', '2020-13-33',
self::NEW_INTERVAL self::NEW_INTERVAL,
], ],
]; ];
} }
@@ -131,7 +311,7 @@ class WorkingHoursControllerTest extends Unit
* @param string $date * @param string $date
* @param string $time * @param string $time
* *
* @dataProvider invalidDataProvider * @dataProvider invalidCreatDataProvider
* *
* @throws HttpBadRequestException * @throws HttpBadRequestException
* @throws HttpConflictRequestException * @throws HttpConflictRequestException
@@ -145,7 +325,7 @@ class WorkingHoursControllerTest extends Unit
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => $date, 'workingDay' => $date,
'workingTime' => $time, 'workingTime' => $time,
] ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
$this->expectException(HttpBadRequestException::class); $this->expectException(HttpBadRequestException::class);
@@ -165,7 +345,7 @@ class WorkingHoursControllerTest extends Unit
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::NEW_DATE, 'workingDay' => self::NEW_DATE,
'workingTime' => self::NEW_INTERVAL, 'workingTime' => self::NEW_INTERVAL,
] ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
$response = $controller->creat($this->request, $this->response, []); $response = $controller->creat($this->request, $this->response, []);
@@ -185,7 +365,7 @@ class WorkingHoursControllerTest extends Unit
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::EXISTING_DATE, 'workingDay' => self::EXISTING_DATE,
'workingTime' => self::EXISTING_INTERVAL, 'workingTime' => self::EXISTING_INTERVAL,
] ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
$this->expectException(HttpConflictRequestException::class); $this->expectException(HttpConflictRequestException::class);
@@ -201,7 +381,7 @@ class WorkingHoursControllerTest extends Unit
{ {
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
$response = $controller->read($this->request, $this->response, [ $response = $controller->read($this->request, $this->response, [
'id' => self::EXISTING_DATE 'id' => self::EXISTING_DATE,
]); ]);
$this->assertInstanceOf(Response::class, $response); $this->assertInstanceOf(Response::class, $response);
} }
@@ -216,7 +396,7 @@ class WorkingHoursControllerTest extends Unit
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
$this->expectException(HttpNotFoundException::class); $this->expectException(HttpNotFoundException::class);
$controller->read($this->request, $this->response, [ $controller->read($this->request, $this->response, [
'id' => self::NEW_DATE 'id' => self::NEW_DATE,
]); ]);
} }
} }
@@ -2,6 +2,7 @@
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories; namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories;
use Codeception\Example;
use Codeception\Test\Unit; use Codeception\Test\Unit;
use DateInterval; use DateInterval;
use DateTime; use DateTime;
@@ -10,6 +11,7 @@ use InvalidArgumentException;
use PDO; use PDO;
use TorstenHettstedt\TimekeepingApi\Models\ModelInterface; use TorstenHettstedt\TimekeepingApi\Models\ModelInterface;
use TorstenHettstedt\TimekeepingApi\Models\WorkingHours; use TorstenHettstedt\TimekeepingApi\Models\WorkingHours;
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryBadWhereDataException;
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordAlreadyExistException; use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordAlreadyExistException;
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordNotFoundException; use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordNotFoundException;
use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursRepository; use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursRepository;
@@ -34,7 +36,7 @@ class WorkingHoursRepositoryTest extends Unit
/** /**
* @throws Exception * @throws Exception
*/ */
public function testFindAll(): void public function testFindAllWithBlankParameter(): void
{ {
$repository = new WorkingHoursRepository($this->pdoObject); $repository = new WorkingHoursRepository($this->pdoObject);
$models = $repository->findAll(); $models = $repository->findAll();
@@ -43,6 +45,81 @@ class WorkingHoursRepositoryTest extends Unit
$this->assertCount(self::RECORDS_COUNT, $models); $this->assertCount(self::RECORDS_COUNT, $models);
} }
/**
* @return array<int, array<int|string|null>>
*/
public function valideFilterParameter(): array
{
return [
[null, null, 61,],
['2020-04-01', null, 0,],
['2020-04-01', '2020-04-30', 0,],
[null, '2020-04-30', 61,],
['2020-03-01', null, 22,],
['2020-03-01', '2020-03-31', 22,],
['2020-03-01', '2020-03-07', 5,],
];
}
/**
* @param string|null $start
* @param string|null $ende
* @param int $count
*
* @dataProvider valideFilterParameter
*
* @throws Exception
*/
public function testFindAllWithValideParameter(?string $start, ?string $ende, int $count): void
{
$repository = new WorkingHoursRepository($this->pdoObject);
$models = $repository->findFiltered($start, $ende);
$this->assertIsArray($models);
$this->assertContainsOnly(WorkingHours::class, $models);
$this->assertCount($count, $models);
}
/**
* @return array<int, array<int|string|null>>
*/
public function invalideFilterParameter(): array
{
return [
['2020-04-31',null],
[null, '2020-04-31'],
['2020-04-00','2020-04-31'],
['2020-04-01','2020-04-31'],
['2020-04-00','2020-04-30'],
//
['2020-04', null],
[null, '2020-04'],
['2020-04', '2020-04'],
['2020-04-01','2020-04'],
['2020-04', '2020-04-30'],
//
['2020', null],
[null, '2020'],
['2020', '2020'],
['2020-04-01','2020'],
['2020', '2020-04-30'],
];
}
/**
* @param string|null $start
* @param string|null $ende
*
* @dataProvider invalideFilterParameter
*
* @throws Exception
*/
public function testFindAllWithInvalideParameter(?string $start, ?string $ende): void
{
$repository = new WorkingHoursRepository($this->pdoObject);
$this->expectException(RepositoryBadWhereDataException::class);
$repository->findFiltered($start, $ende);
}
/** /**
* @throws RepositoryRecordNotFoundException * @throws RepositoryRecordNotFoundException
*/ */