Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Jul 18, 2024
1 parent 120177b commit 493cedd
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 33 deletions.
25 changes: 8 additions & 17 deletions .github/workflows/build.yml → .github/workflows/build-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion tests/Preload.suite.yml → tests/MySqlPreload.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
11 changes: 11 additions & 0 deletions tests/PgSqlIntegration.suite.yml
Original file line number Diff line number Diff line change
@@ -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'
13 changes: 13 additions & 0 deletions tests/PgSqlPreload.suite.yml
Original file line number Diff line number Diff line change
@@ -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'
File renamed without changes.
File renamed without changes.
162 changes: 162 additions & 0 deletions tests/_data/dumps/pgsql/blog.sql
Original file line number Diff line number Diff line change
@@ -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
--

Empty file.
71 changes: 65 additions & 6 deletions tests/_support/_generated/IntegrationTesterActions.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php //[STAMP] 6e30fe49b98241f00675a6d908595f79
<?php //[STAMP] c24edd3767fa499960577b11b53d2923
// phpcs:ignoreFile
namespace Vjik\Codeception\DatabasePopulator\Tests\_generated;

// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
// @codingStandardsIgnoreFile

trait IntegrationTesterActions
{
Expand Down Expand Up @@ -79,8 +79,8 @@ public function performInDatabase($databaseKey, $actions): void {
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Inserts an SQL record into a database. This record will be erased after the test,
* unless you've configured "skip_cleanup_if_failed", and the test fails.
* Inserts an SQL record into a database. This record will be erased after the test,
* unless you've configured "skip_cleanup_if_failed", and the test fails.
*
* ```php
* <?php
Expand Down Expand Up @@ -277,8 +277,8 @@ public function grabColumnFromDatabase(string $table, string $column, array $cri
*
* ```php
* <?php
* $post = $I->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`.
Expand All @@ -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
* <?php
* $mail = $I->grabEntryFromDatabase('users', array('name' => 'Davert'));
* ```
* Comparison expressions can be used as well:
*
* ```php
* <?php
* $post = $I->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
* <?php
* $mail = $I->grabEntriesFromDatabase('users', array('name' => 'Davert'));
* ```
* Comparison expressions can be used as well:
*
* ```php
* <?php
* $post = $I->grabEntriesFromDatabase('posts', ['num_comments >=' => 100]);
* $user = $I->grabEntriesFromDatabase('users', ['email like' => 'miles%']);
* ```
*
* Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`.
*
* @return array<array<string, mixed>> 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.
*
Expand Down
Loading

0 comments on commit 493cedd

Please sign in to comment.