From 493cedd7d2b82c2a174856c2f4b899f78dffb5c4 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 18 Jul 2024 13:03:12 +0300 Subject: [PATCH] improve --- .../workflows/{build.yml => build-mysql.yml} | 25 +-- ...n.suite.yml => MySqlIntegration.suite.yml} | 2 +- ...eload.suite.yml => MySqlPreload.suite.yml} | 2 +- tests/PgSqlIntegration.suite.yml | 11 ++ tests/PgSqlPreload.suite.yml | 13 ++ tests/_data/dumps/{ => mysql}/blog.sql | 0 tests/_data/dumps/{ => mysql}/empty.sql | 0 tests/_data/dumps/pgsql/blog.sql | 162 ++++++++++++++++++ tests/_data/dumps/pgsql/empty.sql | 0 .../_generated/IntegrationTesterActions.php | 71 +++++++- .../_generated/PreloadTesterActions.php | 71 +++++++- .../_support/_generated/UnitTesterActions.php | 4 +- 12 files changed, 328 insertions(+), 33 deletions(-) rename .github/workflows/{build.yml => build-mysql.yml} (55%) rename tests/{Integration.suite.yml => MySqlIntegration.suite.yml} (87%) rename tests/{Preload.suite.yml => MySqlPreload.suite.yml} (89%) create mode 100644 tests/PgSqlIntegration.suite.yml create mode 100644 tests/PgSqlPreload.suite.yml rename tests/_data/dumps/{ => mysql}/blog.sql (100%) rename tests/_data/dumps/{ => mysql}/empty.sql (100%) create mode 100644 tests/_data/dumps/pgsql/blog.sql create mode 100644 tests/_data/dumps/pgsql/empty.sql diff --git a/.github/workflows/build.yml b/.github/workflows/build-mysql.yml similarity index 55% rename from .github/workflows/build.yml rename to .github/workflows/build-mysql.yml index f492ef0..58804f9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build-mysql.yml @@ -50,23 +50,14 @@ jobs: coverage: pcov tools: composer:v2 - - name: Determine composer cache directory on Linux - if: matrix.os == 'ubuntu-latest' - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - - name: Update composer - run: composer self-update + - name: Run unit tests + run: vendor/bin/codecept run Unit - - name: Install dependencies with composer - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + - name: Run integration tests + run: vendor/bin/codecept run MySqlIntegration - - name: Run tests with codeception - run: vendor/bin/codecept run + - name: Run preload tests + run: vendor/bin/codecept run MySqlPreload diff --git a/tests/Integration.suite.yml b/tests/MySqlIntegration.suite.yml similarity index 87% rename from tests/Integration.suite.yml rename to tests/MySqlIntegration.suite.yml index 9036867..77cbec6 100644 --- a/tests/Integration.suite.yml +++ b/tests/MySqlIntegration.suite.yml @@ -7,5 +7,5 @@ modules: user: '%DB_USERNAME%' password: '%DB_PASSWORD%' - Vjik\Codeception\DatabasePopulator\Module: - dumpsPath: 'tests/_data/dumps' + dumpsPath: 'tests/_data/dumps/mysql' rowsPath: 'tests/_data/rows' diff --git a/tests/Preload.suite.yml b/tests/MySqlPreload.suite.yml similarity index 89% rename from tests/Preload.suite.yml rename to tests/MySqlPreload.suite.yml index dd62cbb..b0c1330 100644 --- a/tests/Preload.suite.yml +++ b/tests/MySqlPreload.suite.yml @@ -7,7 +7,7 @@ modules: user: '%DB_USERNAME%' password: '%DB_PASSWORD%' - Vjik\Codeception\DatabasePopulator\Module: - dumpsPath: 'tests/_data/dumps' + dumpsPath: 'tests/_data/dumps/mysql' rowsPath: 'tests/_data/rows' preloadDump: 'blog' preloadRows: 'authors' diff --git a/tests/PgSqlIntegration.suite.yml b/tests/PgSqlIntegration.suite.yml new file mode 100644 index 0000000..b1b3423 --- /dev/null +++ b/tests/PgSqlIntegration.suite.yml @@ -0,0 +1,11 @@ +suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\Integration +actor: IntegrationTester +modules: + enabled: + - Db: + dsn: 'pgsql:host=%DB_HOST%;dbname=%DB_NAME%' + user: '%DB_USERNAME%' + password: '%DB_PASSWORD%' + - Vjik\Codeception\DatabasePopulator\Module: + dumpsPath: 'tests/_data/dumps/pgsql' + rowsPath: 'tests/_data/rows' diff --git a/tests/PgSqlPreload.suite.yml b/tests/PgSqlPreload.suite.yml new file mode 100644 index 0000000..7e89e4a --- /dev/null +++ b/tests/PgSqlPreload.suite.yml @@ -0,0 +1,13 @@ +suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\Preload +actor: PreloadTester +modules: + enabled: + - Db: + dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%' + user: '%DB_USERNAME%' + password: '%DB_PASSWORD%' + - Vjik\Codeception\DatabasePopulator\Module: + dumpsPath: 'tests/_data/dumps/pgsql' + rowsPath: 'tests/_data/rows' + preloadDump: 'blog' + preloadRows: 'authors' diff --git a/tests/_data/dumps/blog.sql b/tests/_data/dumps/mysql/blog.sql similarity index 100% rename from tests/_data/dumps/blog.sql rename to tests/_data/dumps/mysql/blog.sql diff --git a/tests/_data/dumps/empty.sql b/tests/_data/dumps/mysql/empty.sql similarity index 100% rename from tests/_data/dumps/empty.sql rename to tests/_data/dumps/mysql/empty.sql diff --git a/tests/_data/dumps/pgsql/blog.sql b/tests/_data/dumps/pgsql/blog.sql new file mode 100644 index 0000000..ef0811c --- /dev/null +++ b/tests/_data/dumps/pgsql/blog.sql @@ -0,0 +1,162 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 16.3 (Debian 16.3-1.pgdg120+1) +-- Dumped by pg_dump version 16.3 (Debian 16.3-1.pgdg120+1) + +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; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: author; Type: TABLE; Schema: public; Owner: root +-- + +CREATE TABLE public.author ( + id bigint NOT NULL, + name character varying(255) +); + + +ALTER TABLE public.author OWNER TO root; + +-- +-- Name: id_id_seq; Type: SEQUENCE; Schema: public; Owner: root +-- + +CREATE SEQUENCE public.id_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.id_id_seq OWNER TO root; + +-- +-- Name: id_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: root +-- + +ALTER SEQUENCE public.id_id_seq OWNED BY public.author.id; + + +-- +-- Name: post; Type: TABLE; Schema: public; Owner: root +-- + +CREATE TABLE public.post ( + id bigint NOT NULL, + author_id bigint NOT NULL, + name character varying(255) NOT NULL, + body text NOT NULL +); + + +ALTER TABLE public.post OWNER TO root; + +-- +-- Name: post_id_seq; Type: SEQUENCE; Schema: public; Owner: root +-- + +CREATE SEQUENCE public.post_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.post_id_seq OWNER TO root; + +-- +-- Name: post_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: root +-- + +ALTER SEQUENCE public.post_id_seq OWNED BY public.post.id; + + +-- +-- Name: author id; Type: DEFAULT; Schema: public; Owner: root +-- + +ALTER TABLE ONLY public.author ALTER COLUMN id SET DEFAULT nextval('public.id_id_seq'::regclass); + + +-- +-- Name: post id; Type: DEFAULT; Schema: public; Owner: root +-- + +ALTER TABLE ONLY public.post ALTER COLUMN id SET DEFAULT nextval('public.post_id_seq'::regclass); + + +-- +-- Data for Name: author; Type: TABLE DATA; Schema: public; Owner: root +-- + +COPY public.author (id, name) FROM stdin; +\. + + +-- +-- Data for Name: post; Type: TABLE DATA; Schema: public; Owner: root +-- + +COPY public.post (id, author_id, name, body) FROM stdin; +\. + + +-- +-- Name: id_id_seq; Type: SEQUENCE SET; Schema: public; Owner: root +-- + +SELECT pg_catalog.setval('public.id_id_seq', 1, false); + + +-- +-- Name: post_id_seq; Type: SEQUENCE SET; Schema: public; Owner: root +-- + +SELECT pg_catalog.setval('public.post_id_seq', 1, false); + + +-- +-- Name: author id_pk; Type: CONSTRAINT; Schema: public; Owner: root +-- + +ALTER TABLE ONLY public.author + ADD CONSTRAINT id_pk PRIMARY KEY (id); + + +-- +-- Name: post post_pk; Type: CONSTRAINT; Schema: public; Owner: root +-- + +ALTER TABLE ONLY public.post + ADD CONSTRAINT post_pk PRIMARY KEY (id); + + +-- +-- Name: post post_author_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: root +-- + +ALTER TABLE ONLY public.post + ADD CONSTRAINT post_author_id_fk FOREIGN KEY (author_id) REFERENCES public.author(id); + + +-- +-- PostgreSQL database dump complete +-- + diff --git a/tests/_data/dumps/pgsql/empty.sql b/tests/_data/dumps/pgsql/empty.sql new file mode 100644 index 0000000..e69de29 diff --git a/tests/_support/_generated/IntegrationTesterActions.php b/tests/_support/_generated/IntegrationTesterActions.php index 88b06f5..465da76 100644 --- a/tests/_support/_generated/IntegrationTesterActions.php +++ b/tests/_support/_generated/IntegrationTesterActions.php @@ -1,9 +1,9 @@ -grabFromDatabase('posts', ['num_comments >=' => 100]); - * $user = $I->grabFromDatabase('users', ['email like' => 'miles%']); + * $postNum = $I->grabFromDatabase('posts', 'num_comments', ['num_comments >=' => 100]); + * $mail = $I->grabFromDatabase('users', 'email', ['email like' => 'miles%']); * ``` * * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. @@ -291,6 +291,65 @@ public function grabFromDatabase(string $table, string $column, array $criteria } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches a whole entry from a database. + * Make the test fail if the entry is not found. + * Provide table name, desired column and criteria. + * + * ``` php + * grabEntryFromDatabase('users', array('name' => 'Davert')); + * ``` + * Comparison expressions can be used as well: + * + * ```php + * grabEntryFromDatabase('posts', ['num_comments >=' => 100]); + * $user = $I->grabEntryFromDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * + * @return array Returns a single entry value + * @throws PDOException|Exception + * @see \Codeception\Module\Db::grabEntryFromDatabase() + */ + public function grabEntryFromDatabase(string $table, array $criteria = []): array { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabEntryFromDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches a set of entries from a database. + * Provide table name and criteria. + * + * ``` php + * grabEntriesFromDatabase('users', array('name' => 'Davert')); + * ``` + * Comparison expressions can be used as well: + * + * ```php + * grabEntriesFromDatabase('posts', ['num_comments >=' => 100]); + * $user = $I->grabEntriesFromDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * + * @return array> Returns an array of all matched rows + * @throws PDOException|Exception + * @see \Codeception\Module\Db::grabEntriesFromDatabase() + */ + public function grabEntriesFromDatabase(string $table, array $criteria = []): array { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabEntriesFromDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * diff --git a/tests/_support/_generated/PreloadTesterActions.php b/tests/_support/_generated/PreloadTesterActions.php index 0789f97..29c8c4a 100644 --- a/tests/_support/_generated/PreloadTesterActions.php +++ b/tests/_support/_generated/PreloadTesterActions.php @@ -1,9 +1,9 @@ -grabFromDatabase('posts', ['num_comments >=' => 100]); - * $user = $I->grabFromDatabase('users', ['email like' => 'miles%']); + * $postNum = $I->grabFromDatabase('posts', 'num_comments', ['num_comments >=' => 100]); + * $mail = $I->grabFromDatabase('users', 'email', ['email like' => 'miles%']); * ``` * * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. @@ -291,6 +291,65 @@ public function grabFromDatabase(string $table, string $column, array $criteria } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches a whole entry from a database. + * Make the test fail if the entry is not found. + * Provide table name, desired column and criteria. + * + * ``` php + * grabEntryFromDatabase('users', array('name' => 'Davert')); + * ``` + * Comparison expressions can be used as well: + * + * ```php + * grabEntryFromDatabase('posts', ['num_comments >=' => 100]); + * $user = $I->grabEntryFromDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * + * @return array Returns a single entry value + * @throws PDOException|Exception + * @see \Codeception\Module\Db::grabEntryFromDatabase() + */ + public function grabEntryFromDatabase(string $table, array $criteria = []): array { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabEntryFromDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches a set of entries from a database. + * Provide table name and criteria. + * + * ``` php + * grabEntriesFromDatabase('users', array('name' => 'Davert')); + * ``` + * Comparison expressions can be used as well: + * + * ```php + * grabEntriesFromDatabase('posts', ['num_comments >=' => 100]); + * $user = $I->grabEntriesFromDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * + * @return array> Returns an array of all matched rows + * @throws PDOException|Exception + * @see \Codeception\Module\Db::grabEntriesFromDatabase() + */ + public function grabEntriesFromDatabase(string $table, array $criteria = []): array { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabEntriesFromDatabase', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * diff --git a/tests/_support/_generated/UnitTesterActions.php b/tests/_support/_generated/UnitTesterActions.php index 69fdb3d..3184cd3 100644 --- a/tests/_support/_generated/UnitTesterActions.php +++ b/tests/_support/_generated/UnitTesterActions.php @@ -1,9 +1,9 @@ -