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