Skip to content
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

test(mssql): add support for running tests against ms sql server (#91) #94

Merged
merged 9 commits into from
Jul 8, 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
55 changes: 55 additions & 0 deletions .github/phpunit.mssql2019.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/LongitudeOne/Spatial/Tests/TestInit.php" executionOrder="depends,defects" stopOnFailure="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
stopOnError="true" stopOnWarning="true" stopOnDefect="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="default">
<directory>tests/LongitudeOne/Spatial/Tests</directory>
</testsuite>
</testsuites>
<groups>
<include>
<group>php</group>
<group>dql</group>
<group>geometry</group>
<group>geography</group>
<group>srid</group>
<group>pgsql-only</group>
<group>issue</group>
<group>mssql-only</group>
</include>
<exclude>
<group>mysql-only</group>
<group>pgsql-only</group>
</exclude>
</groups>
<php>
<var name="db_type" value="pdo_sqlsrv"/>
<var name="db_host" value="localhost"/>
<var name="db_username" value="sa"/>
<var name="db_password" value="mainExtendedToMoreThan8Chars"/>
<var name="db_name" value="main"/>
<var name="db_port" value="2019"/>
<var name="db_driver_options" value="TrustServerCertificate=1"/>
<!-- mssql cannot drop current database, -->
<!-- Also, we connect on the alternate database, then we drop the main database -->
<var name="db_alternate" value="master"/>
<!-- Select timezone for log -->
<var name="opt_log_timezone" value="Europe/Paris"/>
<!-- Select the log level: debug to get each request, info to get each starting test and disconnection -->
<var name="opt_log_level" value="debug"/>
<!-- Select the directory to store the log files -->
<var name="opt_log_dir" value=".phpunit.cache/logs"/>
<!-- Select the log file name -->
<var name="opt_log_file" value="mssql2019.log"/>
</php>
<source>
<include>
<directory suffix=".php">lib/</directory>
</include>
</source>
</phpunit>
55 changes: 55 additions & 0 deletions .github/phpunit.mssql2022.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/LongitudeOne/Spatial/Tests/TestInit.php" executionOrder="depends,defects" stopOnFailure="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
stopOnError="true" stopOnWarning="true" stopOnDefect="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="default">
<directory>tests/LongitudeOne/Spatial/Tests</directory>
</testsuite>
</testsuites>
<groups>
<include>
<group>php</group>
<group>dql</group>
<group>geometry</group>
<group>geography</group>
<group>srid</group>
<group>pgsql-only</group>
<group>issue</group>
<group>mssql-only</group>
</include>
<exclude>
<group>mysql-only</group>
<group>pgsql-only</group>
</exclude>
</groups>
<php>
<var name="db_type" value="pdo_sqlsrv"/>
<var name="db_host" value="localhost"/>
<var name="db_username" value="sa"/>
<var name="db_password" value="mainExtendedToMoreThan8Chars"/>
<var name="db_name" value="main"/>
<var name="db_port" value="2022"/>
<var name="db_driver_options" value="TrustServerCertificate=1"/>
<!-- mssql cannot drop current database, -->
<!-- Also, we connect on the alternate database, then we drop the main database -->
<var name="db_alternate" value="master"/>
<!-- Select timezone for log -->
<var name="opt_log_timezone" value="Europe/Paris"/>
<!-- Select the log level: debug to get each request, info to get each starting test and disconnection -->
<var name="opt_log_level" value="debug"/>
<!-- Select the directory to store the log files -->
<var name="opt_log_dir" value=".phpunit.cache/logs"/>
<!-- Select the log file name -->
<var name="opt_log_file" value="mssql2022.log"/>
</php>
<source>
<include>
<directory suffix=".php">lib/</directory>
</include>
</source>
</phpunit>
73 changes: 67 additions & 6 deletions .github/workflows/full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,22 @@ jobs:
SA_PASSWORD: mainExtendedToMoreThan8Chars
ports:
- 2017:1433
# Set health checks to wait until mssql-server has started
# options: >-
# --health-cmd="/opt/mssql-tools/bin/sqlcmd -S http://localhost:2017 -U sa -P mainExtendedToMoreThan8Chars -Q 'SELECT 1'"
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
mssql-2019:
# Docker Hub image
image: mcr.microsoft.com/mssql/server:2019-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: mainExtendedToMoreThan8Chars
ports:
- 2019:1433
mssql-2022:
# Docker Hub image
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: mainExtendedToMoreThan8Chars
ports:
- 2022:1433
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -121,6 +131,22 @@ jobs:
- name: Show libraries
run: composer show

- name: Install sqlclient for mssql
uses: potatoqualitee/[email protected]
with:
install: sqlclient

# Create the main databases
- name: Create the main database for mssql-2017
run: sqlcmd -S localhost,2017 -U sa -P mainExtendedToMoreThan8Chars -Q "CREATE DATABASE main;"

- name: Create the main database for mssql-2019
run: sqlcmd -S localhost,2019 -U sa -P mainExtendedToMoreThan8Chars -Q "CREATE DATABASE main;"

- name: Create the main database for mssql-2022
run: sqlcmd -S localhost,2022 -U sa -P mainExtendedToMoreThan8Chars -Q "CREATE DATABASE main;"

# Run the tests
- name: Run test suite and with coverage for codeclimate for PHP 8.3 and doctrine/orm ^3.1 only
if: ${{ env.HAS_CC_SECRET == 'true' }}
uses: paambaati/[email protected]
Expand Down Expand Up @@ -266,6 +292,30 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
mssql-2017:
# Docker Hub image
image: mcr.microsoft.com/mssql/server:2017-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: mainExtendedToMoreThan8Chars
ports:
- 2017:1433
mssql-2019:
# Docker Hub image
image: mcr.microsoft.com/mssql/server:2019-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: mainExtendedToMoreThan8Chars
ports:
- 2019:1433
mssql-2022:
# Docker Hub image
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: mainExtendedToMoreThan8Chars
ports:
- 2022:1433
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -299,6 +349,17 @@ jobs:
- name: Force doctrine/orm library to ${{ matrix.orm }}
run: composer --prefer-stable require doctrine/orm:${{ matrix.orm }} --with-all-dependencies

# Create the main databases
- name: Create the main database for mssql-2017
run: sqlcmd -S localhost,2017 -U sa -P mainExtendedToMoreThan8Chars -Q "CREATE DATABASE main;"

- name: Create the main database for mssql-2019
run: sqlcmd -S localhost,2019 -U sa -P mainExtendedToMoreThan8Chars -Q "CREATE DATABASE main;"

- name: Create the main database for mssql-2022
run: sqlcmd -S localhost,2022 -U sa -P mainExtendedToMoreThan8Chars -Q "CREATE DATABASE main;"

# Run the tests
- name: Run test suite for forks or version without code coverage
run: composer run-script test

Expand Down
13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,26 @@
"test": [
"phpunit --configuration phpunit.mysql5.7.xml",
"phpunit --configuration phpunit.mysql8.0.xml",
"phpunit --configuration phpunit.pgsql.xml"
"phpunit --configuration phpunit.pgsql.xml",
"phpunit --configuration phpunit.mssql2017.xml",
"phpunit --configuration phpunit.mssql2019.xml",
"phpunit --configuration phpunit.mssql2022.xml"
],
"test-coverage": [
"phpunit --configuration phpunit.mysql5.7.xml --coverage-php .phpunit.cache/code-coverage/mysql5.7.cov",
"phpunit --configuration phpunit.mysql8.0.xml --coverage-php .phpunit.cache/code-coverage/mysql8.0.cov",
"phpunit --configuration phpunit.pgsql.xml --coverage-php .phpunit.cache/code-coverage/pgsql.cov",
"phpunit --configuration phpunit.mssql2017.xml --coverage-php .phpunit.cache/code-coverage/mssql2017.cov",
"phpunit --configuration phpunit.mssql2019.xml --coverage-php .phpunit.cache/code-coverage/mssql2019.cov",
"phpunit --configuration phpunit.mssql2022.xml --coverage-php .phpunit.cache/code-coverage/mssql2022.cov",
"phpcov merge --clover .phpunit.cache/code-coverage/clover.xml .phpunit.cache/code-coverage/"
],
"test-mysql5.7": "phpunit --configuration phpunit.mysql5.7.xml",
"test-mysql8.0": "phpunit --configuration phpunit.mysql8.0.xml",
"test-pgsql": "phpunit --configuration phpunit.pgsql.xml"
"test-pgsql": "phpunit --configuration phpunit.pgsql.xml",
"test-mssql2017": "phpunit --configuration phpunit.mssql2017.xml",
"test-mssql2019": "phpunit --configuration phpunit.mssql2019.xml",
"test-mssql2022": "phpunit --configuration phpunit.mssql2022.xml"
},
"autoload": {
"psr-0": {
Expand Down
3 changes: 3 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ docker exec spatial-php8 cp docker/phpunit*.xml .
docker exec spatial-php8 composer test-mysql5
docker exec spatial-php8 composer test-mysql8
docker exec spatial-php8 composer test-pgsql
docker exec spatial-php8 composer test-mssql2017
docker exec spatial-php8 composer test-mssql2019
docker exec spatial-php8 composer test-mssql2022
37 changes: 37 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,43 @@ services:
MYSQL_PORT: 3306
ports:
- "3380:3306"
database-mssql2017:
build:
context: ./mssql
args:
IMAGE_TAG: "2017-latest"
USER_NAME: "root"
container_name: "spatial-mssql2017"
restart: always
environment:
ACCEPT_EULA: Y
MSSQL_SA_PASSWORD: mainExtendedToMoreThan8Chars
ports:
- "1433:1433"
database-mssql2019:
build:
context: ./mssql
args:
IMAGE_TAG: "2019-latest"
container_name: "spatial-mssql2019"
restart: always
environment:
ACCEPT_EULA: Y
MSSQL_SA_PASSWORD: mainExtendedToMoreThan8Chars
ports:
- "1434:1433"
database-mssql2022:
build:
context: ./mssql
args:
IMAGE_TAG: "2022-latest"
container_name: "spatial-mssql2022"
restart: always
environment:
ACCEPT_EULA: Y
MSSQL_SA_PASSWORD: mainExtendedToMoreThan8Chars
ports:
- "1435:1433"
service_doc:
container_name: "spatial-doc"
build:
Expand Down
12 changes: 12 additions & 0 deletions docker/mssql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG IMAGE_TAG
ARG USER_NAME=mssql
FROM mcr.microsoft.com/mssql/server:${IMAGE_TAG}
USER root
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY usr/src/app .
RUN chmod +x run-initialization.sh entrypoint.sh
USER ${USER_NAME}
EXPOSE 1433

CMD /bin/bash ./entrypoint.sh
2 changes: 2 additions & 0 deletions docker/mssql/usr/src/app/create-database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE DATABASE main;
GO
1 change: 1 addition & 0 deletions docker/mssql/usr/src/app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/src/app/run-initialization.sh & /opt/mssql/bin/sqlservr
5 changes: 5 additions & 0 deletions docker/mssql/usr/src/app/run-initialization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Wait to be sure that SQL Server came up
sleep 90s

# Run the setup script to create the DB
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "${MSSQL_SA_PASSWORD:-notProvided}" -d master -i create-database.sql
15 changes: 11 additions & 4 deletions docker/php8/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
FROM php:8.1-fpm-alpine

RUN apk --update --no-cache add bash git postgresql-dev mysql-dev autoconf gcc make g++ \
&& docker-php-ext-install pdo_pgsql pdo_mysql \
&& pecl install pcov \
&& docker-php-ext-enable pcov pdo_pgsql pdo_mysql
#Install the package(s)
#for Microsoft ODBC driver for SQL Server see https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-linux-ver15#alpine-linux
RUN apk --update --no-cache add bash git postgresql-dev mysql-dev unixodbc-dev autoconf gcc make g++ &&\
cd /tmp && \
curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/msodbcsql18_18.3.2.1-1_amd64.apk && \
curl -O https://download.microsoft.com/download/3/5/5/355d7943-a338-41a7-858d-53b259ea33f5/mssql-tools18_18.3.1.1-1_amd64.apk && \
apk add --allow-untrusted msodbcsql18_18.3.2.1-1_amd64.apk && \
apk add --allow-untrusted mssql-tools18_18.3.1.1-1_amd64.apk && \
docker-php-ext-install pdo_pgsql pdo_mysql && \
pecl install pcov pdo_sqlsrv-5.11.1 sqlsrv-5.11.1 && \
docker-php-ext-enable pcov pdo_pgsql pdo_mysql pdo_sqlsrv sqlsrv

#Install composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
Expand Down
55 changes: 55 additions & 0 deletions docker/phpunit.mssql2017.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/LongitudeOne/Spatial/Tests/TestInit.php" executionOrder="depends,defects" stopOnFailure="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
stopOnError="true" stopOnWarning="true" stopOnDefect="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="default">
<directory>tests/LongitudeOne/Spatial/Tests</directory>
</testsuite>
</testsuites>
<groups>
<include>
<group>php</group>
<group>dql</group>
<group>geometry</group>
<group>geography</group>
<group>srid</group>
<group>pgsql-only</group>
<group>issue</group>
<group>mssql-only</group>
</include>
<exclude>
<group>mysql-only</group>
<group>pgsql-only</group>
</exclude>
</groups>
<php>
<var name="db_type" value="pdo_sqlsrv"/>
<var name="db_host" value="spatial-mssql2017"/>
<var name="db_username" value="sa"/>
<var name="db_password" value="mainExtendedToMoreThan8Chars"/>
<var name="db_name" value="main"/>
<var name="db_port" value="1433"/>
<var name="db_driver_options" value="TrustServerCertificate=1"/>
<!-- mssql cannot drop current database, -->
<!-- Also, we connect on the alternate database, then we drop the main database -->
<var name="db_alternate" value="master"/>
<!-- Select timezone for log -->
<var name="opt_log_timezone" value="Europe/Paris"/>
<!-- Select the log level : debug to get each request, info to get each starting test and disconnection -->
<var name="opt_log_level" value="debug"/>
<!-- Select the directory to store the log files -->
<var name="opt_log_dir" value=".phpunit.cache/logs"/>
<!-- Select the log file name -->
<var name="opt_log_file" value="mssql2017.log"/>
</php>
<source>
<include>
<directory suffix=".php">lib/</directory>
</include>
</source>
</phpunit>
Loading