Overview
Testing is crucial to ensure the Docker images work correctly with Microsoft SQL Server. The project includes automated tests that verify both thesqlsrv and pdo_sqlsrv extensions can successfully connect to a SQL Server database.
Test Infrastructure
The test suite consists of:- Test Script:
.ci/tests/test_connection.php- PHP script that tests SQL Server connectivity - CI Workflow:
.github/workflows/create-and-test-docker-image.yml- Automated testing pipeline - SQL Server Service: Uses
mcr.microsoft.com/mssql/server:2022-latestfor testing
Running Tests Locally
Start a SQL Server container
First, start a SQL Server instance for testing:
The SA password must meet SQL Server’s complexity requirements: at least 8 characters including uppercase, lowercase, numbers, and symbols.
Wait for SQL Server to be ready
SQL Server takes a few seconds to start. Wait until it’s ready:Or use a health check loop:
Run the test script
Execute the test script against your built image:On macOS or Windows, replace
--network host with a link to the SQL Server container:Understanding the Test Script
The test script (.ci/tests/test_connection.php) performs the following checks:
Extension Version Check
sqlsrv Extension Test
sqlsrv extension by establishing a connection and executing a simple query.
pdo_sqlsrv Extension Test
Manual Testing
For quick manual verification without the test script:Automated CI Testing
The GitHub Actions workflow automatically tests each image build:- Builds the image using Docker Buildx
- Starts a SQL Server 2022 container as a service
- Waits for SQL Server to be ready using health checks
- Runs the test script inside the built image
- Fails the build if tests don’t pass
Troubleshooting
Connection Timeouts
If tests fail with connection timeouts:- Ensure SQL Server is fully started (check logs)
- Verify network connectivity between containers
- Check firewall rules if testing on remote hosts
Authentication Errors
If you see authentication errors:- Verify the SA password meets complexity requirements
- Check that the password is correctly passed to the test script
- Ensure SQL Server is configured to accept SQL authentication
Extension Not Found
If PHP reports extensions are missing:- Verify the image built successfully
- Check the Dockerfile includes extension installation
- Rebuild the image without cache:
docker build --no-cache ...
SSL/TLS Certificate Errors
The tests disable encryption (Encrypt=false or Encrypt=no) to avoid certificate issues. For production, use proper SSL certificates:
Checking Detailed Error Messages
If a test fails, the script outputs detailed error information:Testing Different PHP Versions
Test all PHP versions to ensure consistency:Next Steps
After testing your images:- Contribute your changes to the project
- Review the PHP Configuration guide for production usage
- Explore the Available PHP Extensions for more information
