diff --git a/api/codeception.dist.yml b/api/codeception.dist.yml new file mode 100644 index 0000000..02eccdb --- /dev/null +++ b/api/codeception.dist.yml @@ -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 diff --git a/api/composer.json b/api/composer.json index aa57726..a3900ac 100644 --- a/api/composer.json +++ b/api/composer.json @@ -26,7 +26,8 @@ "phpstan/phpstan": "^0.12.80", "codeception/codeception": "^4.1.18", "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": { "psr-4": { diff --git a/api/tests/_data/dump.sql b/api/tests/_data/dump.sql new file mode 100644 index 0000000..96ad096 --- /dev/null +++ b/api/tests/_data/dump.sql @@ -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 +\.