Compare commits
5
Commits
e6b9180432
...
7e8ed66cb7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e8ed66cb7 | ||
|
|
93f52af52b | ||
|
|
610e892063 | ||
|
|
7e8d4fbdf4 | ||
|
|
5141fff827 |
@@ -0,0 +1,19 @@
|
|||||||
|
paths:
|
||||||
|
tests: tests
|
||||||
|
output: tests/_output
|
||||||
|
data: tests/_data
|
||||||
|
support: tests/_support
|
||||||
|
envs: tests/_envs
|
||||||
|
actor_suffix: Tester
|
||||||
|
extensions:
|
||||||
|
enabled:
|
||||||
|
- Codeception\Extension\RunFailed
|
||||||
|
modules:
|
||||||
|
enabled:
|
||||||
|
- Db:
|
||||||
|
dsn: 'pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb'
|
||||||
|
user: 'bruce'
|
||||||
|
password: 'mypass'
|
||||||
|
dump: tests/_data/dump.sql
|
||||||
|
cleanup: true # reload dump between tests
|
||||||
|
populate: true # load dump before all tests
|
||||||
+2
-1
@@ -26,7 +26,8 @@
|
|||||||
"phpstan/phpstan": "^0.12.80",
|
"phpstan/phpstan": "^0.12.80",
|
||||||
"codeception/codeception": "^4.1.18",
|
"codeception/codeception": "^4.1.18",
|
||||||
"codeception/module-phpbrowser": "^1.0.0",
|
"codeception/module-phpbrowser": "^1.0.0",
|
||||||
"codeception/module-asserts": "^1.0.0"
|
"codeception/module-asserts": "^1.0.0",
|
||||||
|
"codeception/module-db": "^1.1.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class RepositoryException extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
||||||
|
|
||||||
|
|
||||||
|
class RepositoryModelAlreadyExists extends RepositoryException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T of \TorstenHettstedt\TimekeepingApi\Models\ModelInterface
|
||||||
|
*/
|
||||||
|
interface RepositoryReaderInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Gibt alle vorhandenen Einträge zurück
|
||||||
|
*
|
||||||
|
* @return T[]
|
||||||
|
*/
|
||||||
|
public function findAll(): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt den Eintrag zurück, der durch die ID
|
||||||
|
*
|
||||||
|
* @param mixed $primary_key
|
||||||
|
*
|
||||||
|
* @return T
|
||||||
|
* @throws RepositoryRecordNotFoundException
|
||||||
|
*/
|
||||||
|
public function findByKey(mixed $primary_key);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
||||||
|
|
||||||
|
|
||||||
|
class RepositoryRecordNotFoundException extends RepositoryException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T of \TorstenHettstedt\TimekeepingApi\Models\ModelInterface
|
||||||
|
*/
|
||||||
|
interface RepositoryWriterInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param T $model
|
||||||
|
*
|
||||||
|
* @throws RepositoryModelAlreadyExists
|
||||||
|
*/
|
||||||
|
public function insert(mixed $model): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param T $model
|
||||||
|
*
|
||||||
|
* @throws RepositoryRecordNotFoundException
|
||||||
|
*/
|
||||||
|
public function update(mixed $model): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param T $model
|
||||||
|
*
|
||||||
|
* @throws RepositoryRecordNotFoundException
|
||||||
|
*/
|
||||||
|
public function delete(mixed $model): void;
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace TorstenHettstedt\TimekeepingApi\Repositories;
|
||||||
|
|
||||||
|
|
||||||
|
use DateInterval;
|
||||||
|
use DateTime;
|
||||||
|
use Exception;
|
||||||
|
use PDO;
|
||||||
|
use PDOException;
|
||||||
|
use TorstenHettstedt\TimekeepingApi\Models\ModelInterface;
|
||||||
|
use TorstenHettstedt\TimekeepingApi\Models\WorkingHours;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @implements RepositoryReaderInterface<WorkingHours>
|
||||||
|
* @implements RepositoryWriterInterface<WorkingHours>
|
||||||
|
*/
|
||||||
|
class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWriterInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
protected PDO $database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WorkingHoursRepository constructor.
|
||||||
|
*
|
||||||
|
* @param PDO $database
|
||||||
|
*/
|
||||||
|
public function __construct(PDO $database)
|
||||||
|
{
|
||||||
|
$this->database = $database;
|
||||||
|
$this->database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Gibt alle vorhandenen Einträge zurück
|
||||||
|
*
|
||||||
|
* @return WorkingHours[]
|
||||||
|
* @throws Exception
|
||||||
|
* @throws PDOException
|
||||||
|
*/
|
||||||
|
public function findAll(): array
|
||||||
|
{
|
||||||
|
$models = [];
|
||||||
|
$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']));
|
||||||
|
$models[] = $model;
|
||||||
|
}
|
||||||
|
return $models;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt den Eintrag zurück, der durch die ID
|
||||||
|
*
|
||||||
|
* @param mixed $primary_key
|
||||||
|
*
|
||||||
|
* @return WorkingHours
|
||||||
|
* @throws RepositoryRecordNotFoundException
|
||||||
|
* @throws Exception
|
||||||
|
* @throws PDOException
|
||||||
|
*/
|
||||||
|
public function findByKey(mixed $primary_key): WorkingHours
|
||||||
|
{
|
||||||
|
$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();
|
||||||
|
if ($row === false) {
|
||||||
|
throw new RepositoryRecordNotFoundException();
|
||||||
|
}
|
||||||
|
$model = new WorkingHours();
|
||||||
|
$model
|
||||||
|
->setWorkingDay(new DateTime($row['workingday']))
|
||||||
|
->setWorkingTime(new DateInterval('P0000-00-00T'.$row['workingtime']));
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param WorkingHours|ModelInterface $model
|
||||||
|
*/
|
||||||
|
public function insert(mixed $model): void
|
||||||
|
{
|
||||||
|
// TODO: Implement insert() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param WorkingHours|ModelInterface $model
|
||||||
|
*/
|
||||||
|
public function update(mixed $model): void
|
||||||
|
{
|
||||||
|
// TODO: Implement update() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param WorkingHours|ModelInterface $model
|
||||||
|
*/
|
||||||
|
public function delete(mixed $model): void
|
||||||
|
{
|
||||||
|
// TODO: Implement delete() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
--
|
||||||
|
-- PostgreSQL database dump
|
||||||
|
--
|
||||||
|
|
||||||
|
SET statement_timeout = 0;
|
||||||
|
SET lock_timeout = 0;
|
||||||
|
SET idle_in_transaction_session_timeout = 0;
|
||||||
|
SET client_encoding = 'UTF8';
|
||||||
|
SET standard_conforming_strings = on;
|
||||||
|
SELECT pg_catalog.set_config('search_path', '', false);
|
||||||
|
SET check_function_bodies = false;
|
||||||
|
SET xmloption = content;
|
||||||
|
SET client_min_messages = warning;
|
||||||
|
SET row_security = off;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS public."Arbeitszeiten";
|
||||||
|
DROP VIEW IF EXISTS public."Arbeitszeiten - Woche";
|
||||||
|
DROP VIEW IF EXISTS public."Arbeitszeiten - Monat";
|
||||||
|
DROP VIEW IF EXISTS public."Arbeitszeiten - Jahr";
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: Arbeitszeiten; Type: TABLE; Schema: public; Owner: torsten
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE public."Arbeitszeiten" (
|
||||||
|
"Datum" date NOT NULL,
|
||||||
|
"Arbeitszeit" interval
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE public."Arbeitszeiten" OWNER TO bruce;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: Arbeitszeiten - Jahr; Type: VIEW; Schema: public; Owner: torsten
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public."Arbeitszeiten - Jahr" AS
|
||||||
|
SELECT (date_part('year'::text, "Arbeitszeiten"."Datum"))::text AS "Jahr",
|
||||||
|
sum("Arbeitszeiten"."Arbeitszeit") AS "Gesamtarbeitszeit",
|
||||||
|
count("Arbeitszeiten"."Datum") AS "Arbeitstage",
|
||||||
|
(sum("Arbeitszeiten"."Arbeitszeit") - ((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden"
|
||||||
|
FROM public."Arbeitszeiten"
|
||||||
|
GROUP BY (date_part('year'::text, "Arbeitszeiten"."Datum"))
|
||||||
|
ORDER BY (date_part('year'::text, "Arbeitszeiten"."Datum"));
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE public."Arbeitszeiten - Jahr" OWNER TO bruce;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: Arbeitszeiten - Monat; Type: VIEW; Schema: public; Owner: torsten
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public."Arbeitszeiten - Monat" AS
|
||||||
|
SELECT to_char(date_trunc('month'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone), 'TMYYYY TMMonth'::text) AS "Monat",
|
||||||
|
sum("Arbeitszeiten"."Arbeitszeit") AS "Gesamtarbeitszeit",
|
||||||
|
count("Arbeitszeiten"."Datum") AS "Arbeitstage",
|
||||||
|
(sum("Arbeitszeiten"."Arbeitszeit") - ((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden"
|
||||||
|
FROM public."Arbeitszeiten"
|
||||||
|
GROUP BY (date_trunc('month'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone))
|
||||||
|
ORDER BY (date_trunc('month'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone));
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE public."Arbeitszeiten - Monat" OWNER TO bruce;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: Arbeitszeiten - Woche; Type: VIEW; Schema: public; Owner: torsten
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public."Arbeitszeiten - Woche" AS
|
||||||
|
SELECT to_char(date_trunc('week'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone), 'TMYYYY#WW'::text) AS "Woche",
|
||||||
|
sum("Arbeitszeiten"."Arbeitszeit") AS "Gesamtarbeitszeit",
|
||||||
|
count("Arbeitszeiten"."Datum") AS "Arbeitstage",
|
||||||
|
(sum("Arbeitszeiten"."Arbeitszeit") - ((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden"
|
||||||
|
FROM public."Arbeitszeiten"
|
||||||
|
GROUP BY (date_trunc('week'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone))
|
||||||
|
ORDER BY (date_trunc('week'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone));
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE public."Arbeitszeiten - Woche" OWNER TO bruce;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Data for Name: Arbeitszeiten; Type: TABLE DATA; Schema: public; Owner: torsten
|
||||||
|
--
|
||||||
|
|
||||||
|
COPY public."Arbeitszeiten" ("Datum", "Arbeitszeit") FROM stdin;
|
||||||
|
2020-01-07 08:06:00
|
||||||
|
2020-01-08 08:16:00
|
||||||
|
2020-01-09 07:49:00
|
||||||
|
2020-01-10 07:30:00
|
||||||
|
2020-01-13 08:06:00
|
||||||
|
2020-01-14 08:04:00
|
||||||
|
2020-01-15 08:20:00
|
||||||
|
2020-01-16 07:13:00
|
||||||
|
2020-01-17 07:57:00
|
||||||
|
2020-01-20 07:53:00
|
||||||
|
2020-01-21 07:49:00
|
||||||
|
2020-01-22 07:56:00
|
||||||
|
2020-01-23 07:55:00
|
||||||
|
2020-01-24 07:08:00
|
||||||
|
2020-01-27 08:23:00
|
||||||
|
2020-01-28 07:20:00
|
||||||
|
2020-01-29 08:13:00
|
||||||
|
2020-01-30 08:43:00
|
||||||
|
2020-01-31 07:21:00
|
||||||
|
2020-02-03 07:56:00
|
||||||
|
2020-02-04 08:05:00
|
||||||
|
2020-02-05 07:58:00
|
||||||
|
2020-02-06 08:01:00
|
||||||
|
2020-02-07 07:59:00
|
||||||
|
2020-02-10 07:50:00
|
||||||
|
2020-02-11 08:01:00
|
||||||
|
2020-02-12 08:14:00
|
||||||
|
2020-02-13 08:12:00
|
||||||
|
2020-02-14 07:51:00
|
||||||
|
2020-02-17 07:59:00
|
||||||
|
2020-02-18 08:05:00
|
||||||
|
2020-02-19 07:34:00
|
||||||
|
2020-02-20 07:33:00
|
||||||
|
2020-02-21 07:56:00
|
||||||
|
2020-02-24 08:02:00
|
||||||
|
2020-02-25 08:13:00
|
||||||
|
2020-02-26 08:42:00
|
||||||
|
2020-02-27 07:49:00
|
||||||
|
2020-02-28 08:16:00
|
||||||
|
2020-03-02 08:22:00
|
||||||
|
2020-03-03 08:20:00
|
||||||
|
2020-03-04 08:12:00
|
||||||
|
2020-03-05 08:32:00
|
||||||
|
2020-03-06 04:41:00
|
||||||
|
2020-03-09 07:05:00
|
||||||
|
2020-03-10 07:34:00
|
||||||
|
2020-03-11 07:39:00
|
||||||
|
2020-03-12 07:50:00
|
||||||
|
2020-03-13 08:26:00
|
||||||
|
2020-03-16 07:51:00
|
||||||
|
2020-03-17 07:50:00
|
||||||
|
2020-03-18 07:19:00
|
||||||
|
2020-03-19 07:55:00
|
||||||
|
2020-03-20 05:43:00
|
||||||
|
2020-03-23 08:05:00
|
||||||
|
2020-03-24 08:21:00
|
||||||
|
2020-03-25 08:10:00
|
||||||
|
2020-03-26 10:31:00
|
||||||
|
2020-03-27 04:55:00
|
||||||
|
2020-03-30 08:21:00
|
||||||
|
2020-03-31 08:01:00
|
||||||
|
\.
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories;
|
||||||
|
|
||||||
|
use Codeception\Test\Unit;
|
||||||
|
use DateInterval;
|
||||||
|
use DateTime;
|
||||||
|
use Exception;
|
||||||
|
use PDO;
|
||||||
|
use PDOStatement;
|
||||||
|
use TorstenHettstedt\TimekeepingApi\Models\WorkingHours;
|
||||||
|
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryModelAlreadyExists;
|
||||||
|
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordNotFoundException;
|
||||||
|
use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursRepository;
|
||||||
|
|
||||||
|
class WorkingHoursRepositoryTest extends Unit
|
||||||
|
{
|
||||||
|
const EXISTING_DATE = '2020-01-28';
|
||||||
|
const EXISTING_INTERVAL = 'PT7H20M';
|
||||||
|
const NEW_DATE = '2020-04-01';
|
||||||
|
const NEW_INTERVAL = 'PT7H59M';
|
||||||
|
const RECORDS_COUNT = 61;
|
||||||
|
|
||||||
|
protected PDO $pdoObject;
|
||||||
|
protected PDOStatement $pdoStatement;
|
||||||
|
|
||||||
|
protected function _before(): void
|
||||||
|
{
|
||||||
|
$this->pdoObject = new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass');
|
||||||
|
parent::_before();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFindAll(): void
|
||||||
|
{
|
||||||
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
|
$models = $repository->findAll();
|
||||||
|
$this->assertIsArray($models);
|
||||||
|
$this->assertContainsOnly(WorkingHours::class, $models);
|
||||||
|
$this->assertCount(self::RECORDS_COUNT, $models);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws RepositoryRecordNotFoundException
|
||||||
|
*/
|
||||||
|
public function testExistingFindByKey(): void
|
||||||
|
{
|
||||||
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
|
$model = $repository->findByKey(self::EXISTING_DATE);
|
||||||
|
$this->assertInstanceOf(WorkingHours::class, $model);
|
||||||
|
$this->assertEquals(new DateTime(self::EXISTING_DATE), $model->getWorkingDay());
|
||||||
|
$this->assertEquals(new DateInterval(self::EXISTING_INTERVAL), $model->getWorkingTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotExistingFindByKey(): void
|
||||||
|
{
|
||||||
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
|
$this->expectException(RepositoryRecordNotFoundException::class);
|
||||||
|
$repository->findByKey(self::NEW_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws RepositoryRecordNotFoundException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testNewInsert(): void
|
||||||
|
{
|
||||||
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
|
$model = $this->make(WorkingHours::class, [
|
||||||
|
'workingDay' => new DateTime(self::NEW_DATE),
|
||||||
|
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||||
|
]);
|
||||||
|
$repository->insert($model);
|
||||||
|
$model = $repository->findByKey(self::NEW_DATE);
|
||||||
|
$this->assertInstanceOf(WorkingHours::class, $model);
|
||||||
|
$this->assertEquals(new DateTime(self::NEW_DATE), $model->getWorkingDay());
|
||||||
|
$this->assertEquals(new DateInterval(self::NEW_INTERVAL), $model->getWorkingTime());
|
||||||
|
$this->assertCount(self::RECORDS_COUNT + 1, $repository->findAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testExistingInsert(): void
|
||||||
|
{
|
||||||
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
|
$model = $this->make(WorkingHours::class, [
|
||||||
|
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||||
|
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||||
|
]);
|
||||||
|
$this->expectException(RepositoryModelAlreadyExists::class);
|
||||||
|
$repository->insert($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws RepositoryRecordNotFoundException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testExistsDelete(): void
|
||||||
|
{
|
||||||
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
|
$model = $this->make(WorkingHours::class, [
|
||||||
|
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||||
|
'workingTime' => new DateInterval(self::EXISTING_INTERVAL),
|
||||||
|
]);
|
||||||
|
$repository->delete($model);
|
||||||
|
$this->expectException(RepositoryRecordNotFoundException::class);
|
||||||
|
$repository->findByKey(self::EXISTING_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotExistsDelete(): void
|
||||||
|
{
|
||||||
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
|
$model = $this->make(WorkingHours::class, [
|
||||||
|
'workingDay' => new DateTime(self::NEW_DATE),
|
||||||
|
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||||
|
]);
|
||||||
|
$this->expectException(RepositoryRecordNotFoundException::class);
|
||||||
|
$repository->delete($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws RepositoryRecordNotFoundException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testExistsUpdate(): void
|
||||||
|
{
|
||||||
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
|
$model = $this->make(WorkingHours::class, [
|
||||||
|
'workingDay' => new DateTime(self::EXISTING_DATE),
|
||||||
|
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||||
|
]);
|
||||||
|
$repository->update($model);
|
||||||
|
$model_db = $repository->findByKey(self::EXISTING_DATE);
|
||||||
|
$this->assertEquals(new DateInterval(self::NEW_INTERVAL), $model_db->getWorkingTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testNotExistsUpdate(): void
|
||||||
|
{
|
||||||
|
$repository = new WorkingHoursRepository($this->pdoObject);
|
||||||
|
$model = $this->make(WorkingHours::class, [
|
||||||
|
'workingDay' => new DateTime(self::NEW_DATE),
|
||||||
|
'workingTime' => new DateInterval(self::NEW_INTERVAL),
|
||||||
|
]);
|
||||||
|
$this->expectException(RepositoryRecordNotFoundException::class);
|
||||||
|
$repository->update($model);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user