diff --git a/.github/workflows/build.yml b/.github/workflows/build-mysql.yml similarity index 54% rename from .github/workflows/build.yml rename to .github/workflows/build-mysql.yml index f492ef0..53a3487 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build-mysql.yml @@ -3,7 +3,7 @@ on: push: branches: [ 'master' ] -name: build +name: MySQL build jobs: tests: @@ -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/.github/workflows/build-pgsql.yml b/.github/workflows/build-pgsql.yml new file mode 100644 index 0000000..0f2734d --- /dev/null +++ b/.github/workflows/build-pgsql.yml @@ -0,0 +1,64 @@ +on: + pull_request: + push: + branches: [ 'master' ] + +name: PgSQL build + +jobs: + tests: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + env: + key: cache-v1 + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.0" + - "8.1" + - "8.2" + - "8.3" + + pgsql: + - 16 + + services: + postgres: + image: postgres:${{ matrix.pgsql }} + env: + POSTGRES_USER: root + POSTGRES_PASSWORD: root + POSTGRES_DB: db_test + ports: + - 5432:5432 + options: --name=postgres --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + ini-values: date.timezone='UTC' + coverage: pcov + tools: composer:v2 + + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 + + - name: Run unit tests + run: vendor/bin/codecept run Unit + + - name: Run integration tests + run: vendor/bin/codecept run PgSqlIntegration + + - name: Run preload tests + run: vendor/bin/codecept run PgSqlPreload diff --git a/CHANGELOG.md b/CHANGELOG.md index 2286a80..f7ece2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Database Populator for Codeception DB Module Change Log +## 1.1.1 under development + +- Bug #5: Fix column and table names quotation. + ## 1.1.0 August 4, 2022 - Enh: Raise minimum required versions: PHP to `^8.0`, `codeception/codeception` to `^5.0` and diff --git a/src/DatabasePopulator.php b/src/DatabasePopulator.php index 222b7ce..a8d14e4 100644 --- a/src/DatabasePopulator.php +++ b/src/DatabasePopulator.php @@ -44,7 +44,7 @@ public function loadRows(string ...$sets): void foreach ($sets as $set) { /** * @psalm-suppress UnresolvableInclude - * @psalm-var array> $data + * @psalm-var array>> $data */ $data = require $this->getRowsFilePath($set); foreach ($data as $table => $rows) { @@ -57,6 +57,7 @@ public function loadRows(string ...$sets): void /** * @param array[] $rows + * @psalm-param list> $rows */ private function insertRows(string $table, array $rows): void { @@ -75,8 +76,15 @@ private function insertRows(string $table, array $rows): void } foreach ($requests as $request) { - $columns = array_map(static fn ($c) => "`$c`", $request['columns']); - $sql = 'INSERT INTO ' . $table . ' (' . implode(',', $columns) . ') VALUES '; + $columns = array_map( + fn($c) => $this->dbDriver->getQuotedName($c), + $request['columns'] + ); + $sql = sprintf( + 'INSERT INTO %s (%s) VALUES ', + $this->dbDriver->getQuotedName($table), + implode(',', $columns), + ); $insertQuery = []; $insertData = []; diff --git a/tests/Integration.suite.yml b/tests/MySqlIntegration.suite.yml similarity index 60% rename from tests/Integration.suite.yml rename to tests/MySqlIntegration.suite.yml index 9036867..77a0aa7 100644 --- a/tests/Integration.suite.yml +++ b/tests/MySqlIntegration.suite.yml @@ -1,5 +1,5 @@ -suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\Integration -actor: IntegrationTester +suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\MySqlIntegration +actor: MySqlIntegrationTester modules: enabled: - Db: @@ -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/Integration/DatabasePopulateTest.php b/tests/MySqlIntegration/DatabasePopulateTest.php similarity index 83% rename from tests/Integration/DatabasePopulateTest.php rename to tests/MySqlIntegration/DatabasePopulateTest.php index 0a6ed8a..ea7b514 100644 --- a/tests/Integration/DatabasePopulateTest.php +++ b/tests/MySqlIntegration/DatabasePopulateTest.php @@ -2,19 +2,19 @@ declare(strict_types=1); -namespace Vjik\Codeception\DatabasePopulator\Tests\Integration; +namespace Vjik\Codeception\DatabasePopulator\Tests\MySqlIntegration; use Codeception\Exception\ModuleException; use Codeception\Test\Unit; use PDO; -use Vjik\Codeception\DatabasePopulator\Tests\IntegrationTester; +use Vjik\Codeception\DatabasePopulator\Tests\MySqlIntegrationTester; use function dirname; final class DatabasePopulateTest extends Unit { /** - * @var IntegrationTester + * @var MySqlIntegrationTester */ protected $tester; @@ -32,7 +32,7 @@ public function testLoadNotExistDump(): void $this->expectException(ModuleException::class); $this->expectExceptionMessage( "\nFile with dump doesn't exist.\nPlease, check path for SQL-file: " . - dirname(__DIR__) . '/_data/dumps/shop.sql' + dirname(__DIR__) . '/_data/dumps/mysql/shop.sql' ); $this->tester->loadDump('shop'); } diff --git a/tests/Preload.suite.yml b/tests/MySqlPreload.suite.yml similarity index 67% rename from tests/Preload.suite.yml rename to tests/MySqlPreload.suite.yml index dd62cbb..3058e65 100644 --- a/tests/Preload.suite.yml +++ b/tests/MySqlPreload.suite.yml @@ -1,5 +1,5 @@ -suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\Preload -actor: PreloadTester +suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\MySqlPreload +actor: MySqlPreloadTester modules: enabled: - Db: @@ -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/Preload/PreloadTest.php b/tests/MySqlPreload/PreloadTest.php similarity index 68% rename from tests/Preload/PreloadTest.php rename to tests/MySqlPreload/PreloadTest.php index 22c61a9..93532e5 100644 --- a/tests/Preload/PreloadTest.php +++ b/tests/MySqlPreload/PreloadTest.php @@ -2,15 +2,15 @@ declare(strict_types=1); -namespace Vjik\Codeception\DatabasePopulator\Tests\Preload; +namespace Vjik\Codeception\DatabasePopulator\Tests\MySqlPreload; use Codeception\Test\Unit; -use Vjik\Codeception\DatabasePopulator\Tests\PreloadTester; +use Vjik\Codeception\DatabasePopulator\Tests\MySqlPreloadTester; final class PreloadTest extends Unit { /** - * @var PreloadTester + * @var MySqlPreloadTester */ protected $tester; diff --git a/tests/PgSqlIntegration.suite.yml b/tests/PgSqlIntegration.suite.yml new file mode 100644 index 0000000..690567d --- /dev/null +++ b/tests/PgSqlIntegration.suite.yml @@ -0,0 +1,11 @@ +suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\PgSqlIntegration +actor: PgSqlIntegrationTester +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/PgSqlIntegration/DatabasePopulateTest.php b/tests/PgSqlIntegration/DatabasePopulateTest.php new file mode 100644 index 0000000..8d93bfb --- /dev/null +++ b/tests/PgSqlIntegration/DatabasePopulateTest.php @@ -0,0 +1,51 @@ +tester->loadDump('blog'); + $this->tester->loadRows('authors'); + + $this->tester->seeInDatabase('author', ['id' => 1, 'name' => 'Ivan']); + $this->tester->seeInDatabase('author', ['id' => 2, 'name' => 'Petr']); + } + + public function testLoadNotExistDump(): void + { + $this->expectException(ModuleException::class); + $this->expectExceptionMessage( + "\nFile with dump doesn't exist.\nPlease, check path for SQL-file: " . + dirname(__DIR__) . '/_data/dumps/pgsql/shop.sql' + ); + $this->tester->loadDump('shop'); + } + + public function testLoadEmptyDump(): void + { + $this->tester->loadDump('blog'); + $this->tester->loadDump('empty'); + + /** @var PDO $pdo */ + $pdo = $this->getModule('Db')->_getDbh(); + $tableNames = $pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema=\'public\' AND table_type=\'BASE TABLE\'')->fetchAll(PDO::FETCH_COLUMN); + + $this->assertSame([], $tableNames); + } +} diff --git a/tests/PgSqlPreload.suite.yml b/tests/PgSqlPreload.suite.yml new file mode 100644 index 0000000..6b49663 --- /dev/null +++ b/tests/PgSqlPreload.suite.yml @@ -0,0 +1,13 @@ +suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\PgSqlPreload +actor: PgSqlPreloadTester +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' + preloadDump: 'blog' + preloadRows: 'authors' diff --git a/tests/PgSqlPreload/PreloadTest.php b/tests/PgSqlPreload/PreloadTest.php new file mode 100644 index 0000000..0d4f1d6 --- /dev/null +++ b/tests/PgSqlPreload/PreloadTest.php @@ -0,0 +1,22 @@ +tester->seeInDatabase('author', ['id' => 1, 'name' => 'Ivan']); + $this->tester->seeInDatabase('author', ['id' => 2, 'name' => 'Petr']); + } +} 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..6ca52d1 --- /dev/null +++ b/tests/_data/dumps/pgsql/blog.sql @@ -0,0 +1,163 @@ +-- +-- 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 +-- + +SET search_path TO public 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/MySqlIntegrationTester.php b/tests/_support/MySqlIntegrationTester.php new file mode 100644 index 0000000..5a1a059 --- /dev/null +++ b/tests/_support/MySqlIntegrationTester.php @@ -0,0 +1,29 @@ +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/MySqlIntegrationTesterActions.php b/tests/_support/_generated/MySqlIntegrationTesterActions.php new file mode 100644 index 0000000..2256aba --- /dev/null +++ b/tests/_support/_generated/MySqlIntegrationTesterActions.php @@ -0,0 +1,404 @@ +seeNumRecords(2, 'users'); //executed on default database + * $I->amConnectedToDatabase('db_books'); + * $I->seeNumRecords(30, 'books'); //executed on db_books database + * //All the next queries will be on db_books + * ``` + * + * @throws ModuleConfigException + * @see \Codeception\Module\Db::amConnectedToDatabase() + */ + public function amConnectedToDatabase(string $databaseKey): void { + $this->getScenario()->runStep(new \Codeception\Step\Condition('amConnectedToDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Can be used with a callback if you don't want to change the current database in your test. + * + * ```php + * seeNumRecords(2, 'users'); //executed on default database + * $I->performInDatabase('db_books', function($I) { + * $I->seeNumRecords(30, 'books'); //executed on db_books database + * }); + * $I->seeNumRecords(2, 'users'); //executed on default database + * ``` + * List of actions can be pragmatically built using `Codeception\Util\ActionSequence`: + * + * ```php + * performInDatabase('db_books', ActionSequence::build() + * ->seeNumRecords(30, 'books') + * ); + * ``` + * Alternatively an array can be used: + * + * ```php + * $I->performInDatabase('db_books', ['seeNumRecords' => [30, 'books']]); + * ``` + * + * Choose the syntax you like the most and use it, + * + * Actions executed from array or ActionSequence will print debug output for actions, and adds an action name to + * exception on failure. + * + * @param $databaseKey + * @param ActionSequence|array|callable $actions + * @throws ModuleConfigException + * @see \Codeception\Module\Db::performInDatabase() + */ + public function performInDatabase($databaseKey, $actions): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('performInDatabase', func_get_args())); + } + + + /** + * [!] 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. + * + * ```php + * haveInDatabase('users', array('name' => 'miles', 'email' => 'miles@davis.com')); + * ``` + * @see \Codeception\Module\Db::haveInDatabase() + */ + public function haveInDatabase(string $table, array $data): int { + return $this->getScenario()->runStep(new \Codeception\Step\Action('haveInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that a row with the given column values exists. + * Provide table name and column values. + * + * ```php + * seeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if no such user found. + * + * Comparison expressions can be used as well: + * + * ```php + * seeInDatabase('posts', ['num_comments >=' => '0']); + * $I->seeInDatabase('users', ['email like' => 'miles@davis.com']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::seeInDatabase() + */ + public function seeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInDatabase', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Asserts that a row with the given column values exists. + * Provide table name and column values. + * + * ```php + * seeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if no such user found. + * + * Comparison expressions can be used as well: + * + * ```php + * seeInDatabase('posts', ['num_comments >=' => '0']); + * $I->seeInDatabase('users', ['email like' => 'miles@davis.com']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::seeInDatabase() + */ + public function canSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that the given number of records were found in the database. + * + * ```php + * seeNumRecords(1, 'users', ['name' => 'davert']) + * ``` + * + * @param int $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @see \Codeception\Module\Db::seeNumRecords() + */ + public function seeNumRecords(int $expectedNumber, string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumRecords', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Asserts that the given number of records were found in the database. + * + * ```php + * seeNumRecords(1, 'users', ['name' => 'davert']) + * ``` + * + * @param int $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @see \Codeception\Module\Db::seeNumRecords() + */ + public function canSeeNumRecords(int $expectedNumber, string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumRecords', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Effect is opposite to ->seeInDatabase + * + * Asserts that there is no record with the given column values in a database. + * Provide table name and column values. + * + * ``` php + * dontSeeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if such user was found. + * + * Comparison expressions can be used as well: + * + * ```php + * dontSeeInDatabase('posts', ['num_comments >=' => '0']); + * $I->dontSeeInDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::dontSeeInDatabase() + */ + public function dontSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInDatabase', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Effect is opposite to ->seeInDatabase + * + * Asserts that there is no record with the given column values in a database. + * Provide table name and column values. + * + * ``` php + * dontSeeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if such user was found. + * + * Comparison expressions can be used as well: + * + * ```php + * dontSeeInDatabase('posts', ['num_comments >=' => '0']); + * $I->dontSeeInDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::dontSeeInDatabase() + */ + public function cantSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches all values from the column in database. + * Provide table name, desired column and criteria. + * + * ``` php + * grabColumnFromDatabase('users', 'email', array('name' => 'RebOOter')); + * ``` + * @see \Codeception\Module\Db::grabColumnFromDatabase() + */ + public function grabColumnFromDatabase(string $table, string $column, array $criteria = []): array { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabColumnFromDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches a single column value from a database. + * Provide table name, desired column and criteria. + * + * ``` php + * grabFromDatabase('users', 'email', array('name' => 'Davert')); + * ``` + * Comparison expressions can be used as well: + * + * ```php + * grabFromDatabase('posts', 'num_comments', ['num_comments >=' => 100]); + * $mail = $I->grabFromDatabase('users', 'email', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * + * @return mixed Returns a single column value or false + * @see \Codeception\Module\Db::grabFromDatabase() + */ + public function grabFromDatabase(string $table, string $column, array $criteria = []) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabFromDatabase', func_get_args())); + } + + + /** + * [!] 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. + * + * Returns the number of rows in a database + * + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @return int + * @see \Codeception\Module\Db::grabNumRecords() + */ + public function grabNumRecords(string $table, array $criteria = []): int { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabNumRecords', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Update an SQL record into a database. + * + * ```php + * updateInDatabase('users', array('isAdmin' => true), array('email' => 'miles@davis.com')); + * ``` + * @see \Codeception\Module\Db::updateInDatabase() + */ + public function updateInDatabase(string $table, array $data, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('updateInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Vjik\Codeception\DatabasePopulator\Module::loadDump() + */ + public function loadDump(string $dumps = ''): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('loadDump', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Vjik\Codeception\DatabasePopulator\Module::loadRows() + */ + public function loadRows(string $sets = ''): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('loadRows', func_get_args())); + } +} diff --git a/tests/_support/_generated/MySqlPreloadTesterActions.php b/tests/_support/_generated/MySqlPreloadTesterActions.php new file mode 100644 index 0000000..d811448 --- /dev/null +++ b/tests/_support/_generated/MySqlPreloadTesterActions.php @@ -0,0 +1,404 @@ +seeNumRecords(2, 'users'); //executed on default database + * $I->amConnectedToDatabase('db_books'); + * $I->seeNumRecords(30, 'books'); //executed on db_books database + * //All the next queries will be on db_books + * ``` + * + * @throws ModuleConfigException + * @see \Codeception\Module\Db::amConnectedToDatabase() + */ + public function amConnectedToDatabase(string $databaseKey): void { + $this->getScenario()->runStep(new \Codeception\Step\Condition('amConnectedToDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Can be used with a callback if you don't want to change the current database in your test. + * + * ```php + * seeNumRecords(2, 'users'); //executed on default database + * $I->performInDatabase('db_books', function($I) { + * $I->seeNumRecords(30, 'books'); //executed on db_books database + * }); + * $I->seeNumRecords(2, 'users'); //executed on default database + * ``` + * List of actions can be pragmatically built using `Codeception\Util\ActionSequence`: + * + * ```php + * performInDatabase('db_books', ActionSequence::build() + * ->seeNumRecords(30, 'books') + * ); + * ``` + * Alternatively an array can be used: + * + * ```php + * $I->performInDatabase('db_books', ['seeNumRecords' => [30, 'books']]); + * ``` + * + * Choose the syntax you like the most and use it, + * + * Actions executed from array or ActionSequence will print debug output for actions, and adds an action name to + * exception on failure. + * + * @param $databaseKey + * @param ActionSequence|array|callable $actions + * @throws ModuleConfigException + * @see \Codeception\Module\Db::performInDatabase() + */ + public function performInDatabase($databaseKey, $actions): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('performInDatabase', func_get_args())); + } + + + /** + * [!] 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. + * + * ```php + * haveInDatabase('users', array('name' => 'miles', 'email' => 'miles@davis.com')); + * ``` + * @see \Codeception\Module\Db::haveInDatabase() + */ + public function haveInDatabase(string $table, array $data): int { + return $this->getScenario()->runStep(new \Codeception\Step\Action('haveInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that a row with the given column values exists. + * Provide table name and column values. + * + * ```php + * seeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if no such user found. + * + * Comparison expressions can be used as well: + * + * ```php + * seeInDatabase('posts', ['num_comments >=' => '0']); + * $I->seeInDatabase('users', ['email like' => 'miles@davis.com']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::seeInDatabase() + */ + public function seeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInDatabase', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Asserts that a row with the given column values exists. + * Provide table name and column values. + * + * ```php + * seeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if no such user found. + * + * Comparison expressions can be used as well: + * + * ```php + * seeInDatabase('posts', ['num_comments >=' => '0']); + * $I->seeInDatabase('users', ['email like' => 'miles@davis.com']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::seeInDatabase() + */ + public function canSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that the given number of records were found in the database. + * + * ```php + * seeNumRecords(1, 'users', ['name' => 'davert']) + * ``` + * + * @param int $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @see \Codeception\Module\Db::seeNumRecords() + */ + public function seeNumRecords(int $expectedNumber, string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumRecords', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Asserts that the given number of records were found in the database. + * + * ```php + * seeNumRecords(1, 'users', ['name' => 'davert']) + * ``` + * + * @param int $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @see \Codeception\Module\Db::seeNumRecords() + */ + public function canSeeNumRecords(int $expectedNumber, string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumRecords', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Effect is opposite to ->seeInDatabase + * + * Asserts that there is no record with the given column values in a database. + * Provide table name and column values. + * + * ``` php + * dontSeeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if such user was found. + * + * Comparison expressions can be used as well: + * + * ```php + * dontSeeInDatabase('posts', ['num_comments >=' => '0']); + * $I->dontSeeInDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::dontSeeInDatabase() + */ + public function dontSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInDatabase', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Effect is opposite to ->seeInDatabase + * + * Asserts that there is no record with the given column values in a database. + * Provide table name and column values. + * + * ``` php + * dontSeeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if such user was found. + * + * Comparison expressions can be used as well: + * + * ```php + * dontSeeInDatabase('posts', ['num_comments >=' => '0']); + * $I->dontSeeInDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::dontSeeInDatabase() + */ + public function cantSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches all values from the column in database. + * Provide table name, desired column and criteria. + * + * ``` php + * grabColumnFromDatabase('users', 'email', array('name' => 'RebOOter')); + * ``` + * @see \Codeception\Module\Db::grabColumnFromDatabase() + */ + public function grabColumnFromDatabase(string $table, string $column, array $criteria = []): array { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabColumnFromDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches a single column value from a database. + * Provide table name, desired column and criteria. + * + * ``` php + * grabFromDatabase('users', 'email', array('name' => 'Davert')); + * ``` + * Comparison expressions can be used as well: + * + * ```php + * grabFromDatabase('posts', 'num_comments', ['num_comments >=' => 100]); + * $mail = $I->grabFromDatabase('users', 'email', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * + * @return mixed Returns a single column value or false + * @see \Codeception\Module\Db::grabFromDatabase() + */ + public function grabFromDatabase(string $table, string $column, array $criteria = []) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabFromDatabase', func_get_args())); + } + + + /** + * [!] 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. + * + * Returns the number of rows in a database + * + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @return int + * @see \Codeception\Module\Db::grabNumRecords() + */ + public function grabNumRecords(string $table, array $criteria = []): int { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabNumRecords', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Update an SQL record into a database. + * + * ```php + * updateInDatabase('users', array('isAdmin' => true), array('email' => 'miles@davis.com')); + * ``` + * @see \Codeception\Module\Db::updateInDatabase() + */ + public function updateInDatabase(string $table, array $data, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('updateInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Vjik\Codeception\DatabasePopulator\Module::loadDump() + */ + public function loadDump(string $dumps = ''): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('loadDump', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Vjik\Codeception\DatabasePopulator\Module::loadRows() + */ + public function loadRows(string $sets = ''): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('loadRows', func_get_args())); + } +} diff --git a/tests/_support/_generated/PgSqlIntegrationTesterActions.php b/tests/_support/_generated/PgSqlIntegrationTesterActions.php new file mode 100644 index 0000000..6a52b61 --- /dev/null +++ b/tests/_support/_generated/PgSqlIntegrationTesterActions.php @@ -0,0 +1,404 @@ +seeNumRecords(2, 'users'); //executed on default database + * $I->amConnectedToDatabase('db_books'); + * $I->seeNumRecords(30, 'books'); //executed on db_books database + * //All the next queries will be on db_books + * ``` + * + * @throws ModuleConfigException + * @see \Codeception\Module\Db::amConnectedToDatabase() + */ + public function amConnectedToDatabase(string $databaseKey): void { + $this->getScenario()->runStep(new \Codeception\Step\Condition('amConnectedToDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Can be used with a callback if you don't want to change the current database in your test. + * + * ```php + * seeNumRecords(2, 'users'); //executed on default database + * $I->performInDatabase('db_books', function($I) { + * $I->seeNumRecords(30, 'books'); //executed on db_books database + * }); + * $I->seeNumRecords(2, 'users'); //executed on default database + * ``` + * List of actions can be pragmatically built using `Codeception\Util\ActionSequence`: + * + * ```php + * performInDatabase('db_books', ActionSequence::build() + * ->seeNumRecords(30, 'books') + * ); + * ``` + * Alternatively an array can be used: + * + * ```php + * $I->performInDatabase('db_books', ['seeNumRecords' => [30, 'books']]); + * ``` + * + * Choose the syntax you like the most and use it, + * + * Actions executed from array or ActionSequence will print debug output for actions, and adds an action name to + * exception on failure. + * + * @param $databaseKey + * @param ActionSequence|array|callable $actions + * @throws ModuleConfigException + * @see \Codeception\Module\Db::performInDatabase() + */ + public function performInDatabase($databaseKey, $actions): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('performInDatabase', func_get_args())); + } + + + /** + * [!] 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. + * + * ```php + * haveInDatabase('users', array('name' => 'miles', 'email' => 'miles@davis.com')); + * ``` + * @see \Codeception\Module\Db::haveInDatabase() + */ + public function haveInDatabase(string $table, array $data): int { + return $this->getScenario()->runStep(new \Codeception\Step\Action('haveInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that a row with the given column values exists. + * Provide table name and column values. + * + * ```php + * seeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if no such user found. + * + * Comparison expressions can be used as well: + * + * ```php + * seeInDatabase('posts', ['num_comments >=' => '0']); + * $I->seeInDatabase('users', ['email like' => 'miles@davis.com']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::seeInDatabase() + */ + public function seeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInDatabase', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Asserts that a row with the given column values exists. + * Provide table name and column values. + * + * ```php + * seeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if no such user found. + * + * Comparison expressions can be used as well: + * + * ```php + * seeInDatabase('posts', ['num_comments >=' => '0']); + * $I->seeInDatabase('users', ['email like' => 'miles@davis.com']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::seeInDatabase() + */ + public function canSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that the given number of records were found in the database. + * + * ```php + * seeNumRecords(1, 'users', ['name' => 'davert']) + * ``` + * + * @param int $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @see \Codeception\Module\Db::seeNumRecords() + */ + public function seeNumRecords(int $expectedNumber, string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumRecords', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Asserts that the given number of records were found in the database. + * + * ```php + * seeNumRecords(1, 'users', ['name' => 'davert']) + * ``` + * + * @param int $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @see \Codeception\Module\Db::seeNumRecords() + */ + public function canSeeNumRecords(int $expectedNumber, string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumRecords', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Effect is opposite to ->seeInDatabase + * + * Asserts that there is no record with the given column values in a database. + * Provide table name and column values. + * + * ``` php + * dontSeeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if such user was found. + * + * Comparison expressions can be used as well: + * + * ```php + * dontSeeInDatabase('posts', ['num_comments >=' => '0']); + * $I->dontSeeInDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::dontSeeInDatabase() + */ + public function dontSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInDatabase', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Effect is opposite to ->seeInDatabase + * + * Asserts that there is no record with the given column values in a database. + * Provide table name and column values. + * + * ``` php + * dontSeeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if such user was found. + * + * Comparison expressions can be used as well: + * + * ```php + * dontSeeInDatabase('posts', ['num_comments >=' => '0']); + * $I->dontSeeInDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::dontSeeInDatabase() + */ + public function cantSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches all values from the column in database. + * Provide table name, desired column and criteria. + * + * ``` php + * grabColumnFromDatabase('users', 'email', array('name' => 'RebOOter')); + * ``` + * @see \Codeception\Module\Db::grabColumnFromDatabase() + */ + public function grabColumnFromDatabase(string $table, string $column, array $criteria = []): array { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabColumnFromDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches a single column value from a database. + * Provide table name, desired column and criteria. + * + * ``` php + * grabFromDatabase('users', 'email', array('name' => 'Davert')); + * ``` + * Comparison expressions can be used as well: + * + * ```php + * grabFromDatabase('posts', 'num_comments', ['num_comments >=' => 100]); + * $mail = $I->grabFromDatabase('users', 'email', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * + * @return mixed Returns a single column value or false + * @see \Codeception\Module\Db::grabFromDatabase() + */ + public function grabFromDatabase(string $table, string $column, array $criteria = []) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabFromDatabase', func_get_args())); + } + + + /** + * [!] 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. + * + * Returns the number of rows in a database + * + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @return int + * @see \Codeception\Module\Db::grabNumRecords() + */ + public function grabNumRecords(string $table, array $criteria = []): int { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabNumRecords', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Update an SQL record into a database. + * + * ```php + * updateInDatabase('users', array('isAdmin' => true), array('email' => 'miles@davis.com')); + * ``` + * @see \Codeception\Module\Db::updateInDatabase() + */ + public function updateInDatabase(string $table, array $data, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('updateInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Vjik\Codeception\DatabasePopulator\Module::loadDump() + */ + public function loadDump(string $dumps = ''): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('loadDump', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Vjik\Codeception\DatabasePopulator\Module::loadRows() + */ + public function loadRows(string $sets = ''): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('loadRows', func_get_args())); + } +} diff --git a/tests/_support/_generated/PgSqlPreloadTesterActions.php b/tests/_support/_generated/PgSqlPreloadTesterActions.php new file mode 100644 index 0000000..fbed93d --- /dev/null +++ b/tests/_support/_generated/PgSqlPreloadTesterActions.php @@ -0,0 +1,404 @@ +seeNumRecords(2, 'users'); //executed on default database + * $I->amConnectedToDatabase('db_books'); + * $I->seeNumRecords(30, 'books'); //executed on db_books database + * //All the next queries will be on db_books + * ``` + * + * @throws ModuleConfigException + * @see \Codeception\Module\Db::amConnectedToDatabase() + */ + public function amConnectedToDatabase(string $databaseKey): void { + $this->getScenario()->runStep(new \Codeception\Step\Condition('amConnectedToDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Can be used with a callback if you don't want to change the current database in your test. + * + * ```php + * seeNumRecords(2, 'users'); //executed on default database + * $I->performInDatabase('db_books', function($I) { + * $I->seeNumRecords(30, 'books'); //executed on db_books database + * }); + * $I->seeNumRecords(2, 'users'); //executed on default database + * ``` + * List of actions can be pragmatically built using `Codeception\Util\ActionSequence`: + * + * ```php + * performInDatabase('db_books', ActionSequence::build() + * ->seeNumRecords(30, 'books') + * ); + * ``` + * Alternatively an array can be used: + * + * ```php + * $I->performInDatabase('db_books', ['seeNumRecords' => [30, 'books']]); + * ``` + * + * Choose the syntax you like the most and use it, + * + * Actions executed from array or ActionSequence will print debug output for actions, and adds an action name to + * exception on failure. + * + * @param $databaseKey + * @param ActionSequence|array|callable $actions + * @throws ModuleConfigException + * @see \Codeception\Module\Db::performInDatabase() + */ + public function performInDatabase($databaseKey, $actions): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('performInDatabase', func_get_args())); + } + + + /** + * [!] 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. + * + * ```php + * haveInDatabase('users', array('name' => 'miles', 'email' => 'miles@davis.com')); + * ``` + * @see \Codeception\Module\Db::haveInDatabase() + */ + public function haveInDatabase(string $table, array $data): int { + return $this->getScenario()->runStep(new \Codeception\Step\Action('haveInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that a row with the given column values exists. + * Provide table name and column values. + * + * ```php + * seeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if no such user found. + * + * Comparison expressions can be used as well: + * + * ```php + * seeInDatabase('posts', ['num_comments >=' => '0']); + * $I->seeInDatabase('users', ['email like' => 'miles@davis.com']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::seeInDatabase() + */ + public function seeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInDatabase', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Asserts that a row with the given column values exists. + * Provide table name and column values. + * + * ```php + * seeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if no such user found. + * + * Comparison expressions can be used as well: + * + * ```php + * seeInDatabase('posts', ['num_comments >=' => '0']); + * $I->seeInDatabase('users', ['email like' => 'miles@davis.com']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::seeInDatabase() + */ + public function canSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that the given number of records were found in the database. + * + * ```php + * seeNumRecords(1, 'users', ['name' => 'davert']) + * ``` + * + * @param int $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @see \Codeception\Module\Db::seeNumRecords() + */ + public function seeNumRecords(int $expectedNumber, string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumRecords', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Asserts that the given number of records were found in the database. + * + * ```php + * seeNumRecords(1, 'users', ['name' => 'davert']) + * ``` + * + * @param int $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @see \Codeception\Module\Db::seeNumRecords() + */ + public function canSeeNumRecords(int $expectedNumber, string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumRecords', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Effect is opposite to ->seeInDatabase + * + * Asserts that there is no record with the given column values in a database. + * Provide table name and column values. + * + * ``` php + * dontSeeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if such user was found. + * + * Comparison expressions can be used as well: + * + * ```php + * dontSeeInDatabase('posts', ['num_comments >=' => '0']); + * $I->dontSeeInDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::dontSeeInDatabase() + */ + public function dontSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInDatabase', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * [!] Conditional Assertion: Test won't be stopped on fail + * Effect is opposite to ->seeInDatabase + * + * Asserts that there is no record with the given column values in a database. + * Provide table name and column values. + * + * ``` php + * dontSeeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); + * ``` + * Fails if such user was found. + * + * Comparison expressions can be used as well: + * + * ```php + * dontSeeInDatabase('posts', ['num_comments >=' => '0']); + * $I->dontSeeInDatabase('users', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * @see \Codeception\Module\Db::dontSeeInDatabase() + */ + public function cantSeeInDatabase(string $table, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches all values from the column in database. + * Provide table name, desired column and criteria. + * + * ``` php + * grabColumnFromDatabase('users', 'email', array('name' => 'RebOOter')); + * ``` + * @see \Codeception\Module\Db::grabColumnFromDatabase() + */ + public function grabColumnFromDatabase(string $table, string $column, array $criteria = []): array { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabColumnFromDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fetches a single column value from a database. + * Provide table name, desired column and criteria. + * + * ``` php + * grabFromDatabase('users', 'email', array('name' => 'Davert')); + * ``` + * Comparison expressions can be used as well: + * + * ```php + * grabFromDatabase('posts', 'num_comments', ['num_comments >=' => 100]); + * $mail = $I->grabFromDatabase('users', 'email', ['email like' => 'miles%']); + * ``` + * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * + * @return mixed Returns a single column value or false + * @see \Codeception\Module\Db::grabFromDatabase() + */ + public function grabFromDatabase(string $table, string $column, array $criteria = []) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabFromDatabase', func_get_args())); + } + + + /** + * [!] 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. + * + * Returns the number of rows in a database + * + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * @return int + * @see \Codeception\Module\Db::grabNumRecords() + */ + public function grabNumRecords(string $table, array $criteria = []): int { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabNumRecords', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Update an SQL record into a database. + * + * ```php + * updateInDatabase('users', array('isAdmin' => true), array('email' => 'miles@davis.com')); + * ``` + * @see \Codeception\Module\Db::updateInDatabase() + */ + public function updateInDatabase(string $table, array $data, array $criteria = []): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('updateInDatabase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Vjik\Codeception\DatabasePopulator\Module::loadDump() + */ + public function loadDump(string $dumps = ''): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('loadDump', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Vjik\Codeception\DatabasePopulator\Module::loadRows() + */ + public function loadRows(string $sets = ''): void { + $this->getScenario()->runStep(new \Codeception\Step\Action('loadRows', func_get_args())); + } +} diff --git a/tests/_support/_generated/PreloadTesterActions.php b/tests/_support/_generated/PreloadTesterActions.php index 0789f97..78b1afb 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 @@ -