Skip to content

Add tear down test for rows created with haveInDatabaseon a table without auto increment #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -51,10 +51,10 @@ jobs:
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
run: composer install --no-progress --no-interaction

- name: Run test suite
run: php vendor/bin/codecept run
env:
PGPASSWORD: postgres
MYSQL_HOST: 127.0.0.1
MYSQL_DSN: "mysql:host=127.0.0.1;port=3306;dbname=codeception_test"
17 changes: 9 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -2,25 +2,26 @@ version: "3.9"

services:
php81:
image: codeception-module-db-php81:2.2.0
image: codeception-module-db-php81:3.x
build:
context: .
dockerfile: ./php81.Dockerfile
environment:
MYSQL_DSN: "mysql:host=host.docker.internal;port=3102;dbname=codeception"
MYSQL_USER: root
MYSQL_PASSWORD: codeception
MYSQL_DSN: ${MYSQL_DSN:-mysql:host=mysql57;port=3306;dbname=codeception}
MYSQL_USER: ${MYSQL_USER:-root}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-codeception}
XDEBUG_MODE: "debug"
XDEBUG_CONFIG: "client_host=host.docker.internal; client_port=9000; mode=debug; start_wih_request=1"
PHP_IDE_CONFIG: "serverName=codeception-module-db" # the name must be the same as in your PHP -> Server -> "name" field
volumes:
- ".:/var/www/html"

mariadb105:
image: mariadb:10.5
mysql57:
image: mysql:5.7
platform: linux/amd64
environment:
MARIADB_ROOT_PASSWORD: codeception
MARIADB_DATABASE: codeception
MYSQL_ROOT_PASSWORD: codeception
MYSQL_DATABASE: codeception
ports:
- "3102:3306"

15 changes: 12 additions & 3 deletions php81.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
FROM php:8.1-cli

ARG USERNAME=codeception
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME && \
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME

RUN apt-get update && \
apt-get install -y \
unzip \
wget \
git \
zlib1g-dev \
libzip-dev \
mariadb-client-10.5
mariadb-client

RUN docker-php-ext-install pdo pdo_mysql && docker-php-ext-enable pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
@@ -16,14 +23,16 @@ RUN docker-php-ext-install zip
RUN pecl install xdebug-3.1.5 && \
echo zend_extension=xdebug.so > $PHP_INI_DIR/conf.d/xdebug.ini

USER $USERNAME

COPY --from=composer /usr/bin/composer /usr/bin/composer

WORKDIR /var/www/html

COPY composer.json .
COPY composer.lock .
COPY composer.loc[k] .

RUN composer install --no-autoloader
RUN composer install --no-interaction --no-autoloader

COPY . .

6 changes: 6 additions & 0 deletions tests/data/dumps/mysql.sql
Original file line number Diff line number Diff line change
@@ -112,6 +112,12 @@ CREATE TABLE `auto_increment_on_composite_pk` (
PRIMARY KEY (`id`, `counter`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `no_auto_increment_at_all` (
`id` int(11) NOT NULL,
`field` varchar(255) NOT NULL,
PRIMARY KEY (`id`, `field`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `empty_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`field` varchar(255),
Binary file modified tests/data/sqlite.db
Binary file not shown.
3 changes: 1 addition & 2 deletions tests/unit/Codeception/Lib/Driver/MysqlTest.php
Original file line number Diff line number Diff line change
@@ -25,8 +25,7 @@ final class MysqlTest extends Unit

public static function _setUpBeforeClass()
{
$host = getenv('MYSQL_HOST') ? getenv('MYSQL_HOST') : 'localhost';
self::$config['dsn'] = 'mysql:host='.$host.';dbname=codeception_test';
self::$config['dsn'] = getenv('MYSQL_DSN');
self::$config['password'] = getenv('MYSQL_PASSWORD') ? getenv('MYSQL_PASSWORD') : '';

$sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/mysql.sql');
16 changes: 14 additions & 2 deletions tests/unit/Codeception/Module/Db/MySqlDbTest.php
Original file line number Diff line number Diff line change
@@ -22,10 +22,9 @@ public function getPopulator(): string

public function getConfig(): array
{
$host = getenv('MYSQL_HOST') ? getenv('MYSQL_HOST') : 'localhost';
$user = getenv('MYSQL_USER') ? getenv('MYSQL_USER') : 'root';
$password = getenv('MYSQL_PASSWORD') ? getenv('MYSQL_PASSWORD') : '';
$dsn = getenv('MYSQL_DSN') ? getenv('MYSQL_DSN') : 'mysql:host='.$host.';dbname=codeception_test';
$dsn = getenv('MYSQL_DSN') ? getenv('MYSQL_DSN') : '';

return [
'dsn' => $dsn,
@@ -177,4 +176,17 @@ public function testHaveInDatabaseAutoIncrementOnCompositePrimaryKey()

$this->module->dontSeeInDatabase('auto_increment_on_composite_pk', $testData);
}

public function testHaveInDatabaseWithoutAnyAutoIncrement()
{
$testData = [
'id' => 777,
'field' => 'codeception',
];
$this->module->haveInDatabase('no_auto_increment_at_all', $testData);
$this->module->seeInDatabase('no_auto_increment_at_all', $testData);
$this->module->_after(Stub::makeEmpty(TestInterface::class));

$this->module->dontSeeInDatabase('no_auto_increment_at_all', $testData);
}
}