8000 #49 Cast last insert id to string to avoid type error when pdo return… · Codeception/module-db@2f752db · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 2f752db

Browse files
authored
#49 Cast last insert id to string to avoid type error when pdo returns with false in case of dblib (#55)
1 parent 96fcd4c commit 2f752db

File tree

15 files changed

+526
-62
lines changed

15 files changed

+526
-62
lines changed

.github/workflows/main.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,40 @@ jobs:
3131
--health-retries 5
3232
ports:
3333
- 5432:5432
34+
mssql:
35+
image: mcr.microsoft.com/mssql/server:2019-latest
36+
env:
37+
SA_PASSWORD: P@ssw0rd
38+
ACCEPT_EULA: 'Y'
39+
ports:
40+
- 1433:1433
41+
options: >-
42+
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'P@ssw0rd' -d master -Q 'SELECT COUNT(*) FROM master.dbo.spt_values;'"
43+
--health-interval 10s
44+
--health-timeout 5s
45+
--health-retries 5
3446
3547
strategy:
3648
matrix:
3749
php: [7.4, 8.0]
50+
include:
51+
- php: 7.4
52+
sqlsrv: 5.9.0
53+
- php: 8.0
54+
sqlsrv: 5.10.1
3855

3956
steps:
57+
- name: Create default database for sqlsrv as image does not support it
58+
run: /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'P@ssw0rd' -Q 'CREATE DATABASE codeception_test'
59+
4060
- name: Checkout code
4161
uses: actions/checkout@v2
4262

4363
- name: Setup PHP
4464
uses: shivammathur/setup-php@v2
4565
with:
4666
php-version: ${{ matrix.php }}
47-
extensions: pdo, pgsql, mysql, sqlite
67+
extensions: pdo, pgsql, mysql, sqlite, sqlsrv-${{ matrix.sqlsrv }}, pdo_sqlsrv-${{ matrix.sqlsrv }}, pdo_dblib
4868
coverage: none
4969

5070
- name: Validate composer.json and composer.lock
@@ -56,5 +76,11 @@ jobs:
5676
- name: Run test suite
5777
run: php vendor/bin/codecept run
5878
env:
59-
PGPASSWORD: postgres
6079
MYSQL_HOST: 127.0.0.1
80+
MYSQL_DB: codeception_test
81+
PG_HOST: 127.0.0.1
82+
PG_DB: codeception_test
83+
PG_PASSWORD: postgres
84+
MSSQL_HOST: 127.0.0.1
85+
MSSQL_DB: codeception_test
86+
MSSQL_PASSWORD: P@ssw0rd

docker-compose.yml

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
version: "3.9"
22

33
services:
4-
54
php74:
65
image: codeception-module-db-php74:2.2.0
76
build:
87
context: .
98
dockerfile: ./php74.Dockerfile
109
environment:
11-
MYSQL_DSN: "mysql:host=host.docker.internal;port=3102;dbname=codeception"
12-
MYSQL_USER: root
10+
MYSQL_HOST: host.docker.internal
11+
MYSQL_DB: codeception
1312
MYSQL_PASSWORD: codeception
13+
PG_HOST: host.docker.internal
14+
PG_DB: codeception
15+
PG_PASSWORD: codeception
16+
MSSQL_HOST: host.docker.internal
17+
MSSQL_DB: codeception
18+
MSSQL_PASSWORD: 'P@ssw0rd'
1419
XDEBUG_MODE: "debug"
1520
XDEBUG_CONFIG: "client_host=host.docker.internal; client_port=9000; mode=debug; start_wih_request=1"
1621
PHP_IDE_CONFIG: "serverName=codeception-module-db" # the name must be the same as in your PHP -> Server -> "name" field
@@ -23,20 +28,46 @@ services:
2328
context: .
2429
dockerfile: ./php81.Dockerfile
2530
environment:
26-
MYSQL_DSN: "mysql:host=host.docker.internal;port=3102;dbname=codeception"
27-
MYSQL_USER: root
31+
MYSQL_HOST: host.docker.internal
32+
MYSQL_DB: codeception
2833
MYSQL_PASSWORD: codeception
34+
PG_HOST: host.docker.internal
35+
PG_DB: codeception
36+
PG_PASSWORD: codeception
37+
MSSQL_HOST: host.docker.internal
38+
MSSQL_DB: codeception
39+
MSSQL_PASSWORD: 'P@ssw0rd'
2940
XDEBUG_MODE: "debug"
3041
XDEBUG_CONFIG: "client_host=host.docker.internal; client_port=9000; mode=debug; start_wih_request=1"
3142
PHP_IDE_CONFIG: "serverName=codeception-module-db" # the name must be the same as in your PHP -> Server -> "name" field
3243
volumes:
3344
- ".:/var/www/html"
3445

35-
mariadb105:
36-
image: mariadb:10.5
46+
mysql:
47+
image: mysql:5.7
48+
environment:
49+
MYSQL_ROOT_PASSWORD: codeception
50+
MYSQL_DATABASE: codeception
51+
ports:
52+
- "3306:3306"
53+
54+
postgres:
55+
image: postgres
3756
environment:
38-
MARIADB_ROOT_PASSWORD: codeception
39-
MARIADB_DATABASE: codeception
57+
POSTGRES_PASSWORD: codeception
58+
POSTGRES_DB: codeception
4059
ports:
41-
- "3102:3306"
60+
- "5432:5432"
61+
62+
mssql:
63+
image: mcr.microsoft.com/mssql/server:2019-latest
64+
environment:
65+
SA_PASSWORD: 'P@ssw0rd'
66+
MSSQL_DATABASE: codeception
67+
ACCEPT_EULA: 'Y'
68+
ports:
69+
- "1433:1433"
70+
volumes:
71+
- ./tests/data/scripts:/scripts:ro
72+
entrypoint: [ "/bin/bash", "-c", "/scripts/mssql.sh" ]
4273

php74.Dockerfile

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
FROM php:7.4-cli
22

3+
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
4+
35
RUN apt-get update && \
46
apt-get install -y \
57
unzip \
68
wget \
79
git \
810
zlib1g-dev \
911
libzip-dev \
10-
mariadb-client-10.5
11-
12-
RUN docker-php-ext-install pdo pdo_mysql && docker-php-ext-enable pdo pdo_mysql
13-
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
14-
RUN docker-php-ext-install zip
15-
16-
RUN pecl install xdebug-3.1.5 && \
17-
echo zend_extension=xdebug.so > $PHP_INI_DIR/conf.d/xdebug.ini
12+
libpq-dev \
13+
mariadb-client-10.5
14+
15+
RUN install-php-extensions \
16+
pdo_mysql-stable \
17+
pdo_pgsql-stable \
18+
pdo_dblib-stable \
19+
pdo_sqlsrv-5.9.0 \
20+
pgsql-stable \
21+
zip-stable \
22+
xdebug-3.1.5
1823

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

2126
WORKDIR /var/www/html
2227

23-
COPY composer.json .
24-
COPY composer.lock .
25-
26-
RUN composer install --no-autoloader
27-
28-
COPY . .
29-
30-
RUN composer dump-autoload -o
31-
3228
ENTRYPOINT ["tail"]
3329
CMD ["-f", "/dev/null"]

php81.Dockerfile

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
FROM php:8.1-cli
22

3+
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
4+
35
RUN apt-get update && \
46
apt-get install -y \
57
unzip \
68
wget \
79
git \
810
zlib1g-dev \
911
libzip-dev \
10-
mariadb-client-10.5
11-
12-
RUN docker-php-ext-install pdo pdo_mysql && docker-php-ext-enable pdo pdo_mysql
13-
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
14-
RUN docker-php-ext-install zip
15-
16-
RUN pecl install xdebug-3.1.5 && \
17-
echo zend_extension=xdebug.so > $PHP_INI_DIR/conf.d/xdebug.ini
12+
libpq-dev \
13+
mariadb-client-10.5
14+
15+
RUN install-php-extensions \
16+
pdo_mysql-stable \
17+
pdo_pgsql-stable \
18+
pdo_dblib-stable \
19+
pdo_sqlsrv-5.11.0 \
20+
pgsql-stable \
21+
zip-stable \
22+
xdebug-3.1.5
1823

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

2126
WORKDIR /var/www/html
2227

23-
COPY composer.json .
24-
COPY composer.lock .
25-
26-
RUN composer install --no-autoloader
27-
28-
COPY . .
29-
30-
RUN composer dump-autoload -o
31-
3228
ENTRYPOINT ["tail"]
3329
CMD ["-f", "/dev/null"]

src/Codeception/Lib/Driver/Db.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function deleteQueryByCriteria(string $tableName, array $criteria): void
250250

251251
public function lastInsertId(string $tableName): string
252252
{
253-
return $this->getDbh()->lastInsertId();
253+
return (string)$this->getDbh()->lastInsertId();
254254
}
255255

256256
public function getQuotedName(string $name): string

tests/data/dumps/mssql.sql

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
CREATE TABLE [dbo].[groups] (
2+
[id] INT NOT NULL IDENTITY(1,1),
3+
[name] VARCHAR(100) NULL,
4+
[enabled] BIT NULL,
5+
[created_at] DATETIME NOT NULL CONSTRAINT DF_groups_created_at DEFAULT GETDATE(),
6+
CONSTRAINT PK_groups PRIMARY KEY CLUSTERED ([id] ASC)
7+
);
8+
9+
INSERT INTO [dbo].[groups]([name],[enabled],[created_at])
10+
VALUES
11+
('coders', 1, '2012-02-01 21:17:50'),
12+
('jazzman', 0, '2012-02-01 21:18:40');
13+
14+
15+
CREATE TABLE [dbo].[users] (
16+
[id] INT NOT NULL IDENTITY(1,1),
17+
[uuid] BINARY(16) NULL,
18+
[name] VARCHAR(30) NULL,
19+
[email] VARCHAR(255) NULL,
20+
[is_active] BIT NOT NULL CONSTRAINT DF_users_is_active DEFAULT 1,
21+
[created_at] DATETIME NOT NULL CONSTRAINT DF_users_created_at DEFAULT GETDATE(),
22+
CONSTRAINT PK_users PRIMARY KEY CLUSTERED ([id] ASC)
23+
);
24+
25+
INSERT INTO [dbo].[users]([uuid],[name],[email],[is_active],[created_at])
26+
VALUES
27+
(0x11edc34b01d972fa9c1d0242ac120006, 'davert', 'davert@mail.ua', 1, '2012-02-01 21:17:04'),
28+
(null, 'nick', 'nick@mail.ua', 1, '2012-02-01 21:17:15'),
29+
(null, 'miles', 'miles@davis.com', 1, '2012-02-01 21:17:25'),
30+
(null, 'bird', 'charlie@parker.com', 0, '2012-02-01 21:17:39');
31+
32+
33+
CREATE TABLE [dbo].[permissions] (
34+
[id] INT NOT NULL IDENTITY(1,1),
35+
[user_id] INT NULL,
36+
[group_id] INT NULL,
37+
[role] VARCHAR(30) NULL,
38+
CONSTRAINT PK_permissions PRIMARY KEY CLUSTERED ([id] ASC),
39+
CONSTRAINT FK_permissions FOREIGN KEY ([group_id]) REFERENCES [dbo].[groups] ([id]) ON DELETE CASCADE,
40+
CONSTRAINT FK_users FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([id]) ON DELETE CASCADE
41+
);
42 F438 +
43+
INSERT INTO [dbo].[permissions]([user_id],[group_id],[role])
44+
VALUES
45+
(1,1,'member'),
46+
(2,1,'member'),
47+
(3,2,'member'),
48+
(4,2,'admin');
49+
50+
51+
CREATE TABLE [dbo].[order] (
52+
[id] INT NOT NULL IDENTITY(1,1),
53+
[name] VARCHAR(255) NOT NULL,
54+
[status] VARCHAR(255) NOT NULL,
55+
CONSTRAINT PK_order PRIMARY KEY CLUSTERED ([id] ASC)
56+
);
57+
58+
INSERT INTO [dbo].[order]([name],[status]) VALUES ('main', 'open');
59+
60+
61+
CREATE TABLE [dbo].[composite_pk] (
62+
[group_id] INT NOT NULL,
63+
[id] INT NOT NULL,
64+
[status] VARCHAR(255) NOT NULL,
65+
CONSTRAINT PK_composite_pk PRIMARY KEY CLUSTERED ([group_id] ASC, [id] ASC)
66+
);
67+
68+
CREATE TABLE [dbo].[no_pk] (
69+
[status] varchar(255) NOT NULL
70+
);
71+
72+
CREATE TABLE [dbo].[empty_table] (
73+
[id] int NOT NULL IDENTITY(1,1),
74+
[field] varchar(255),
75+
CONSTRAINT [PK_empty_table] PRIMARY KEY CLUSTERED ([id])
76+
);

tests/data/scripts/mssql.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
/opt/mssql/bin/sqlservr &
4+
/scripts/wait-for-it.sh 127.0.0.1:1433
5+
6+
for i in {1..50};
7+
do
8+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -d master -Q "CREATE DATABASE $MSSQL_DATABASE;"
9+
if [ $? -eq 0 ]
10+
then
11+
echo "database created"
12+
break
13+
else
14+
echo "not ready yet..."
15+
sleep 1
16+
fi
17+
done
18+
19+
sleep infinity # Keep the container running forever

0 commit comments

Comments
 (0)
0