Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d11070ffbb | ||
|
|
5cdc11d9df | ||
|
|
add7895191 | ||
|
|
20fec2dc07 |
@@ -17,3 +17,7 @@ modules:
|
||||
dump: tests/_data/dump.sql
|
||||
cleanup: true # reload dump between tests
|
||||
populate: true # load dump before all tests
|
||||
coverage:
|
||||
enabled: true
|
||||
include:
|
||||
- src/*
|
||||
@@ -8,8 +8,16 @@ use Slim\Psr7\Request;
|
||||
|
||||
class HelloWorldController
|
||||
{
|
||||
/** @noinspection PhpUnusedParameterInspection */
|
||||
public function read(Request $request, Response $response, $args): Response
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param mixed[] $args
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @noinspection PhpUnusedParameterInspection
|
||||
*/
|
||||
public function read(Request $request, Response $response, array $args): Response
|
||||
{
|
||||
$payload = json_encode('Hallo World');
|
||||
|
||||
|
||||
@@ -101,13 +101,7 @@ abstract class AbstractWorkingHoursViewRepository implements RepositoryReaderInt
|
||||
$minutes = (int)$time_array[1];
|
||||
$seconds = (int)$time_array[2];
|
||||
$interval = new DateInterval(sprintf('PT%dH%dM%dS', abs($hours), abs($minutes), abs($seconds)));
|
||||
if ($hours < 0) {
|
||||
$interval->invert = 1;
|
||||
}
|
||||
if ($minutes < 0) {
|
||||
$interval->invert = 1;
|
||||
}
|
||||
if ($seconds < 0) {
|
||||
if (($hours < 0 || ($minutes < 0) || ($seconds < 0))) {
|
||||
$interval->invert = 1;
|
||||
}
|
||||
return $interval;
|
||||
|
||||
@@ -44,13 +44,13 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
|
||||
public function findAll(): array
|
||||
{
|
||||
$models = [];
|
||||
$stmt = $this->database->prepare('select "Datum" as workingDay, "Arbeitszeit" as workingTime from public."Arbeitszeiten"');
|
||||
$stmt = $this->database->prepare('select "Datum" as "workingDay", "Arbeitszeit" as "workingTime" from public."Arbeitszeiten"');
|
||||
$stmt->execute();
|
||||
while ($row = $stmt->fetch()) {
|
||||
$model = new WorkingHours();
|
||||
$model
|
||||
->setWorkingDay(new DateTime($row['workingday']))
|
||||
->setWorkingTime(new DateInterval('P0000-00-00T' . $row['workingtime']));
|
||||
->setWorkingDay(new DateTime($row['workingDay']))
|
||||
->setWorkingTime(new DateInterval('P0000-00-00T' . $row['workingTime']));
|
||||
$models[] = $model;
|
||||
}
|
||||
return $models;
|
||||
@@ -68,7 +68,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
|
||||
*/
|
||||
public function findByKey(mixed $primary_key): WorkingHours
|
||||
{
|
||||
$stmt = $this->database->prepare('select "Datum" as workingDay, "Arbeitszeit" as workingTime from public."Arbeitszeiten" where "Datum" = ?');
|
||||
$stmt = $this->database->prepare('select "Datum" as "workingDay", "Arbeitszeit" as "workingTime" from public."Arbeitszeiten" where "Datum" = ?');
|
||||
$stmt->bindParam(1, $primary_key);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
@@ -77,8 +77,8 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
|
||||
}
|
||||
$model = new WorkingHours();
|
||||
$model
|
||||
->setWorkingDay(new DateTime($row['workingday']))
|
||||
->setWorkingTime(new DateInterval('P0000-00-00T' . $row['workingtime']));
|
||||
->setWorkingDay(new DateTime($row['workingDay']))
|
||||
->setWorkingTime(new DateInterval('P0000-00-00T' . $row['workingTime']));
|
||||
return $model;
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
|
||||
* @param WorkingHours|ModelInterface $model
|
||||
*
|
||||
* @throws RepositoryModelAlreadyExists
|
||||
* @throws Exception
|
||||
*/
|
||||
public function insert(mixed $model): void
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ use Exception;
|
||||
use InvalidArgumentException;
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use stdClass;
|
||||
use TorstenHettstedt\TimekeepingApi\Models\ModelInterface;
|
||||
use TorstenHettstedt\TimekeepingApi\Models\WorkingHours;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryModelAlreadyExists;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordNotFoundException;
|
||||
@@ -28,10 +28,14 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
|
||||
protected function _before(): void
|
||||
{
|
||||
/** @noinspection SpellCheckingInspection */
|
||||
$this->pdoObject = new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass');
|
||||
parent::_before();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testFindAll(): void
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
@@ -66,10 +70,7 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
public function testInsertWithInvalidModel(): void
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$model = $this->make(stdClass::class, [
|
||||
'workingDay' => new DateTime(self::NEW_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
]);
|
||||
$model = $this->makeEmpty(ModelInterface::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$repository->insert($model);
|
||||
}
|
||||
@@ -114,10 +115,7 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
public function testDeleteWithInvalidModel(): void
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$model = $this->make(stdClass::class, [
|
||||
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||
'workingTime' => new DateInterval(self::EXISTING_INTERVAL),
|
||||
]);
|
||||
$model = $this->makeEmpty(ModelInterface::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$repository->delete($model);
|
||||
}
|
||||
@@ -138,6 +136,10 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
$repository->findByKey(self::EXISTING_DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RepositoryRecordNotFoundException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testNotExistsDelete(): void
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
@@ -156,11 +158,7 @@ class WorkingHoursRepositoryTest extends Unit
|
||||
public function testUpdateWithInvalidModel(): void
|
||||
{
|
||||
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||
$model = $this->make(stdClass::class, [
|
||||
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||
]);
|
||||
|
||||
$model = $this->makeEmpty(ModelInterface::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$repository->update($model);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories;
|
||||
use Codeception\Test\Unit;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use PDO;
|
||||
use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordNotFoundException;
|
||||
@@ -37,6 +38,7 @@ class WorkingHoursViewRepositoryTest extends Unit
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function existingObjectProvider(): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user