diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 89e0a8f7..39b5f197 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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" diff --git a/docker-compose.yml b/docker-compose.yml index b164309f..55572438 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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" diff --git a/php81.Dockerfile b/php81.Dockerfile index 9e6b8bcd..489c9bab 100644 --- a/php81.Dockerfile +++ b/php81.Dockerfile @@ -1,5 +1,12 @@ 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 \ @@ -7,7 +14,7 @@ RUN apt-get update && \ 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 . . diff --git a/tests/data/dumps/mysql.sql b/tests/data/dumps/mysql.sql index 3617afd5..b73cf8a8 100644 --- a/tests/data/dumps/mysql.sql +++ b/tests/data/dumps/mysql.sql @@ -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), diff --git a/tests/data/sqlite.db b/tests/data/sqlite.db index b8b0d252..9f8a6e31 100644 Binary files a/tests/data/sqlite.db and b/tests/data/sqlite.db differ diff --git a/tests/unit/Codeception/Lib/Driver/MysqlTest.php b/tests/unit/Codeception/Lib/Driver/MysqlTest.php index eda908ae..27f245d3 100644 --- a/tests/unit/Codeception/Lib/Driver/MysqlTest.php +++ b/tests/unit/Codeception/Lib/Driver/MysqlTest.php @@ -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'); diff --git a/tests/unit/Codeception/Module/Db/MySqlDbTest.php b/tests/unit/Codeception/Module/Db/MySqlDbTest.php index 058aa4f5..f9f7dadb 100644 --- a/tests/unit/Codeception/Module/Db/MySqlDbTest.php +++ b/tests/unit/Codeception/Module/Db/MySqlDbTest.php @@ -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); + } }