8000 [bugfix] #49 Fix last insert id return type in case of dblib (2.x) by szhajdu · Pull Request #55 · Codeception/module-db · GitHub
[go: up one dir, main page]

Skip to content

[bugfix] #49 Fix last insert id return type in case of dblib (2.x) #55

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

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,40 @@ jobs:
--health-retries 5
ports:
- 5432:5432
mssql:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
SA_PASSWORD: P@ssw0rd
ACCEPT_EULA: 'Y'
ports:
- 1433:1433
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'P@ssw0rd' -d master -Q 'SELECT COUNT(*) FROM master.dbo.spt_values;& 8000 #39;"
--health-interval 10s
--health-timeout 5s
--health-retries 5

strategy:
matrix:
php: [7.4, 8.0]
include:
- php: 7.4
sqlsrv: 5.9.0
- php: 8.0
sqlsrv: 5.10.1

steps:
- name: Create default database for sqlsrv as image does not support it
run: /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'P@ssw0rd' -Q 'CREATE DATABASE codeception_test'

- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo, pgsql, mysql, sqlite
extensions: pdo, pgsql, mysql, sqlite, sqlsrv-${{ matrix.sqlsrv }}, pdo_sqlsrv-${{ matrix.sqlsrv }}, pdo_dblib
coverage: none

- name: Validate composer.json and composer.lock
Expand All @@ -56,5 +76,11 @@ jobs:
- name: Run test suite
run: php vendor/bin/codecept run
env:
PGPASSWORD: postgres
MYSQL_HOST: 127.0.0.1
MYSQL_DB: codeception_test
PG_HOST: 127.0.0.1
PG_DB: codeception_test
PG_PASSWORD: postgres
MSSQL_HOST: 127.0.0.1
MSSQL_DB: codeception_test
MSSQL_PASSWORD: P@ssw0rd
51 changes: 41 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
version: "3.9"

services:

php74:
image: codeception-module-db-php74:2.2.0
build:
context: .
dockerfile: ./php74.Dockerfile
environment:
MYSQL_DSN: "mysql:host=host.docker.internal;port=3102;dbname=codeception"
MYSQL_USER: root
MYSQL_HOST: host.docker.internal
MYSQL_DB: codeception
MYSQL_PASSWORD: codeception
PG_HOST: host.docker.internal
PG_DB: codeception
PG_PASSWORD: codeception
MSSQL_HOST: host.docker.internal
MSSQL_DB: codeception
MSSQL_PASSWORD: 'P@ssw0rd'
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
Expand All @@ -23,20 +28,46 @@ services:
context: .
dockerfile: ./php81.Dockerfile
environment:
MYSQL_DSN: "mysql:host=host.docker.internal;port=3102;dbname=codeception"
MYSQL_USER: root
MYSQL_HOST: host.docker.internal
MYSQL_DB: codeception
MYSQL_PASSWORD: codeception
PG_HOST: host.docker.internal
PG_DB: codeception
PG_PASSWORD: codeception
MSSQL_HOST: host.docker.internal
MSSQL_DB: codeception
MSSQL_PASSWORD: 'P@ssw0rd'
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
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: codeception
MYSQL_DATABASE: codeception
ports:
- "3306:3306"

postgres:
image: postgres
environment:
MARIADB_ROOT_PASSWORD: codeception
MARIADB_DATABASE: codeception
POSTGRES_PASSWORD: codeception
POSTGRES_DB: codeception
ports:
- "3102:3306"
- "5432:5432"

mssql:
image: mcr.microsoft.com/mssql/server:2019-latest
environment:
SA_PASSWORD: 'P@ssw0rd'
MSSQL_DATABASE: codeception
ACCEPT_EULA: 'Y'
ports:
- "1433:1433"
volumes:
- ./tests/data/scripts:/scripts:ro
entrypoint: [ "/bin/bash", "-c", "/scripts/mssql.sh" ]

30 changes: 13 additions & 17 deletions php74.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
FROM php:7.4-cli

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/

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

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
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
libpq-dev \
mariadb-client-10.5

RUN install-php-extensions \
pdo_mysql-stable \
pdo_pgsql-stable \
pdo_dblib-stable \
pdo_sqlsrv-5.9.0 \
pgsql-stable \
zip-stable \
xdebug-3.1.5

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

WORKDIR /var/www/html

COPY composer.json .
COPY composer.lock .

RUN composer install --no-autoloader

COPY . .

RUN composer dump-autoload -o

ENTRYPOINT ["tail"]
CMD ["-f", "/dev/null"]
30 changes: 13 additions & 17 deletions php81.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
FROM php:8.1-cli

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/

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

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
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
libpq-dev \
mariadb-client-10.5

RUN install-php-extensions \
pdo_mysql-stable \
pdo_pgsql-stable \
pdo_dblib-stable \
pdo_sqlsrv-5.11.0 \
pgsql-stable \
zip-stable \
xdebug-3.1.5

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

WORKDIR /var/www/html

COPY composer.json .
COPY composer.lock .

RUN composer install --no-autoloader

COPY . .

RUN composer dump-autoload -o

ENTRYPOINT ["tail"]
CMD ["-f", "/dev/null"]
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Driver/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function deleteQueryByCriteria(string $tableName, array $criteria): void

public function lastInsertId(string $tableName): string
{
return $this->getDbh()->lastInsertId();
return (string)$this->getDbh()->lastInsertId();
}

public function getQuotedName(string $name): string
Expand Down
76 changes: 76 additions & 0 deletions tests/data/dumps/mssql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
CREATE TABLE [dbo].[groups] (
[id] INT NOT NULL IDENTITY(1,1),
[name] VARCHAR(100) NULL,
[enabled] BIT NULL,
[created_at] DATETIME NOT NULL CONSTRAINT DF_groups_created_at DEFAULT GETDATE(),
CONSTRAINT PK_groups PRIMARY KEY CLUSTERED ([id] ASC)
);

INSERT INTO [dbo].[groups]([name],[enabled],[created_at])
VALUES
('coders', 1, '2012-02-01 21:17:50'),
('jazzman', 0, '2012-02-01 21:18:40');


CREATE TABLE [dbo].[users] (
[id] INT NOT NULL IDENTITY(1,1),
[uuid] BINARY(16) NULL,
[name] VARCHAR(30) NULL,
[email] VARCHAR(255) NULL,
[is_active] BIT NOT NULL CONSTRAINT DF_users_is_active DEFAULT 1,
[created_at] DATETIME NOT NULL CONSTRAINT DF_users_created_at DEFAULT GETDATE(),
CONSTRAINT PK_users PRIMARY KEY CLUSTERED ([id] ASC)
);

INSERT INTO [dbo].[users]([uuid],[name],[email],[is_active],[created_at])
VALUES
(0x11edc34b01d972fa9c1d0242ac120006, 'davert', 'davert@mail.ua', 1, '2012-02-01 21:17:04'),
(null, 'nick', 'nick@mail.ua', 1, '2012-02-01 21:17:15'),
(null, 'miles', 'miles@davis.com', 1, '2012-02-01 21:17:25'),
(null, 'bird', 'charlie@parker.com', 0, '2012-02-01 21:17:39');


CREATE TABLE [dbo].[permissions] (
[id] INT NOT NULL IDENTITY(1,1),
[user_id] INT NULL,
[group_id] INT NULL,
[role] VARCHAR(30) NULL,
CONSTRAINT PK_permissions PRIMARY KEY CLUSTERED ([id] ASC),
CONSTRAINT FK_permissions FOREIGN KEY ([group_id]) REFERENCES [dbo].[groups] ([id]) ON DELETE CASCADE,
CONSTRAINT FK_users FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([id]) ON DELETE CASCADE
);

INSERT INTO [dbo].[permissions]([user_id],[group_id],[role])
VALUES
(1,1,'member'),
(2,1,'member'),
(3,2,'member'),
(4,2,'admin');


CREATE TABLE [dbo].[order] (
[id] INT NOT NULL IDENTITY(1,1),
[name] VARCHAR(255) NOT NULL,
[status] VARCHAR(255) NOT NULL,
CONSTRAINT PK_order PRIMARY KEY CLUSTERED ([id] ASC)
);

INSERT INTO [dbo].[order]([name],[status]) VALUES ('main', 'open');


CREATE TABLE [dbo].[composite_pk] (
[group_id] INT NOT NULL,
[id] INT NOT NULL,
[status] VARCHAR(255) NOT NULL,
CONSTRAINT PK_composite_pk PRIMARY KEY CLUSTERED ([group_id] ASC, [id] ASC)
);

CREATE TABLE [dbo].[no_pk] (
[status] varchar(255) NOT NULL
);

CREATE TABLE [dbo].[empty_table] (
[id] int NOT NULL IDENTITY(1,1),
[field] varchar(255),
CONSTRAINT [PK_empty_table] PRIMARY KEY CLUSTERED ([id])
);
19 changes: 19 additions & 0 deletions tests/data/scripts/mssql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

/opt/mssql/bin/sqlservr &
/scripts/wait-for-it.sh 127.0.0.1:1433

for i in {1..50};
do
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -d master -Q "CREATE DATABASE $MSSQL_DATABASE;"
if [ $? -eq 0 ]
then
echo "database created"
break
else
echo "not ready yet..."
sleep 1
fi
done

sleep infinity # Keep the container running forever
Loading
0