Test: Erzeuge die Tests für die gefilterte Abfragen
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
|
||||
|
||||
use Codeception\Example;
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use PDO;
|
||||
@@ -25,8 +26,8 @@ class WorkingHoursControllerTest extends Unit
|
||||
const NEW_INTERVAL = '07:59:00';
|
||||
|
||||
protected ContainerInterface $container;
|
||||
protected Request $request;
|
||||
protected Response $response;
|
||||
protected Request $request;
|
||||
protected Response $response;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
@@ -37,16 +38,16 @@ class WorkingHoursControllerTest extends Unit
|
||||
/** @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')
|
||||
'get' => new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass'),
|
||||
]);
|
||||
$this->request = $this->makeEmpty(Request::class, [
|
||||
'getParsedBody' => [
|
||||
'workingDay' => self::EXISTING_DATE,
|
||||
'workingTime' => self::EXISTING_INTERVAL,
|
||||
]
|
||||
'getParsedBody' => [
|
||||
'workingDay' => self::EXISTING_DATE,
|
||||
'workingTime' => self::EXISTING_INTERVAL,
|
||||
],
|
||||
]);
|
||||
$this->response = $this->makeEmpty(Response::class, [
|
||||
'getBody' => $this->makeEmpty(StreamInterface::class, [
|
||||
'getBody' => $this->makeEmpty(StreamInterface::class, [
|
||||
'write' => function (mixed $data) {
|
||||
$this->assertIsString($data);
|
||||
$this->assertJson($data);
|
||||
@@ -65,23 +66,202 @@ class WorkingHoursControllerTest extends Unit
|
||||
public function testConstructWithNonDatabase(): void
|
||||
{
|
||||
$this->container = $this->makeEmpty(ContainerInterface::class, [
|
||||
'has' => false
|
||||
'has' => false,
|
||||
]);
|
||||
$this->expectException(NotDatabasesException::class);
|
||||
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 Exception
|
||||
*/
|
||||
public function testBrowse(): void
|
||||
public function testBrowseWithValideParameter(array $queryParams): void
|
||||
{
|
||||
$this->request = $this->makeEmpty(Request::class, [
|
||||
'getQueryParams' => $queryParams,
|
||||
]);
|
||||
$controller = new WorkingHoursController($this->container);
|
||||
$response = $controller->browse($this->request, $this->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 HttpBadRequestException
|
||||
@@ -91,7 +271,7 @@ class WorkingHoursControllerTest extends Unit
|
||||
{
|
||||
$controller = new WorkingHoursController($this->container);
|
||||
$response = $controller->update($this->request, $this->response, [
|
||||
'id' => self::EXISTING_DATE
|
||||
'id' => self::EXISTING_DATE,
|
||||
]);
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
}
|
||||
@@ -106,23 +286,23 @@ class WorkingHoursControllerTest extends Unit
|
||||
$controller = new WorkingHoursController($this->container);
|
||||
$this->expectException(HttpNotFoundException::class);
|
||||
$controller->update($this->request, $this->response, [
|
||||
'id' => self::NEW_DATE
|
||||
'id' => self::NEW_DATE,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function invalidDataProvider(): array
|
||||
public function invalidCreatDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
self::NEW_DATE,
|
||||
'07:59'
|
||||
'07:59',
|
||||
],
|
||||
[
|
||||
'2020-13-33',
|
||||
self::NEW_INTERVAL
|
||||
self::NEW_INTERVAL,
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -131,7 +311,7 @@ class WorkingHoursControllerTest extends Unit
|
||||
* @param string $date
|
||||
* @param string $time
|
||||
*
|
||||
* @dataProvider invalidDataProvider
|
||||
* @dataProvider invalidCreatDataProvider
|
||||
*
|
||||
* @throws HttpBadRequestException
|
||||
* @throws HttpConflictRequestException
|
||||
@@ -145,7 +325,7 @@ class WorkingHoursControllerTest extends Unit
|
||||
'getParsedBody' => [
|
||||
'workingDay' => $date,
|
||||
'workingTime' => $time,
|
||||
]
|
||||
],
|
||||
]);
|
||||
$controller = new WorkingHoursController($this->container);
|
||||
$this->expectException(HttpBadRequestException::class);
|
||||
@@ -165,7 +345,7 @@ class WorkingHoursControllerTest extends Unit
|
||||
'getParsedBody' => [
|
||||
'workingDay' => self::NEW_DATE,
|
||||
'workingTime' => self::NEW_INTERVAL,
|
||||
]
|
||||
],
|
||||
]);
|
||||
$controller = new WorkingHoursController($this->container);
|
||||
$response = $controller->creat($this->request, $this->response, []);
|
||||
@@ -185,7 +365,7 @@ class WorkingHoursControllerTest extends Unit
|
||||
'getParsedBody' => [
|
||||
'workingDay' => self::EXISTING_DATE,
|
||||
'workingTime' => self::EXISTING_INTERVAL,
|
||||
]
|
||||
],
|
||||
]);
|
||||
$controller = new WorkingHoursController($this->container);
|
||||
$this->expectException(HttpConflictRequestException::class);
|
||||
@@ -201,7 +381,7 @@ class WorkingHoursControllerTest extends Unit
|
||||
{
|
||||
$controller = new WorkingHoursController($this->container);
|
||||
$response = $controller->read($this->request, $this->response, [
|
||||
'id' => self::EXISTING_DATE
|
||||
'id' => self::EXISTING_DATE,
|
||||
]);
|
||||
$this->assertInstanceOf(Response::class, $response);
|
||||
}
|
||||
@@ -216,7 +396,7 @@ class WorkingHoursControllerTest extends Unit
|
||||
$controller = new WorkingHoursController($this->container);
|
||||
$this->expectException(HttpNotFoundException::class);
|
||||
$controller->read($this->request, $this->response, [
|
||||
'id' => self::NEW_DATE
|
||||
'id' => self::NEW_DATE,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user