Skip to content

Commit f50139f

Browse files
committed
Code cleanup, refactor for PHP 8 compatibility, and bug fixes discovered in doing so
- bug fixes, prior to PHP 8, `**@**` silenced errors which this library used to return `**false**` instead, that is not no longer possible with PHP 8 - Linux and Windows CI tests move to GitHub Actions - General code style fixes - merged bug fix #199 - fixed tests in issue #200, and corrections for PR #201
1 parent 66e82e6 commit f50139f

28 files changed

+495
-480
lines changed

.github/install_mssql.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash -e
2+
3+
# Use the following variables to control your install:
4+
5+
# Password for the SA user (required)
6+
MSSQL_SA_PASSWORD='!Passw0rd'
7+
8+
# Product ID of the version of SQL server you're installing
9+
# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key
10+
# Defaults to developer
11+
MSSQL_PID='evaluation'
12+
13+
# Install SQL Server Agent (recommended)
14+
SQL_INSTALL_AGENT='y'
15+
16+
# Install SQL Server Full Text Search (optional)
17+
# SQL_INSTALL_FULLTEXT='y'
18+
19+
# Create an additional user with sysadmin privileges (optional)
20+
SQL_INSTALL_USER='ez_test'
21+
SQL_INSTALL_USER_PASSWORD='ezTest'
22+
SQL_INSTALL_DATABASE='ez_test'
23+
24+
if [ -z $MSSQL_SA_PASSWORD ]
25+
then
26+
echo Environment variable MSSQL_SA_PASSWORD must be set for unattended install
27+
exit 1
28+
fi
29+
30+
echo Adding Microsoft repositories...
31+
sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
32+
sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
33+
repoargs="$(curl https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
34+
sudo add-apt-repository "${repoargs}"
35+
36+
echo Running apt-get update -y...
37+
sudo apt-get update -y
38+
39+
echo Installing SQL Server...
40+
sudo apt-get install -y mssql-server
41+
42+
echo Running mssql-conf setup...
43+
sudo MSSQL_SA_PASSWORD=$MSSQL_SA_PASSWORD \
44+
MSSQL_PID=$MSSQL_PID \
45+
/opt/mssql/bin/mssql-conf -n setup accept-eula
46+
47+
# Configure firewall to allow TCP port 1433:
48+
echo Configuring UFW to allow traffic on port 1433...
49+
sudo ufw allow 1433/tcp
50+
sudo ufw reload
51+
52+
# Restart SQL Server after installing:
53+
echo Restarting SQL Server...
54+
sudo systemctl restart mssql-server
55+
56+
# Optional new user creation:
57+
if [ ! -z $SQL_INSTALL_USER ] && [ ! -z $SQL_INSTALL_USER_PASSWORD ]
58+
then
59+
echo Creating user $SQL_INSTALL_USER
60+
sqlcmd \
61+
-S localhost \
62+
-U SA \
63+
-P $MSSQL_SA_PASSWORD \
64+
-Q "CREATE DATABASE ez_test"
65+
sqlcmd \
66+
-S localhost \
67+
-U SA \
68+
-P $MSSQL_SA_PASSWORD \
69+
-Q "CREATE LOGIN [$SQL_INSTALL_USER] WITH PASSWORD=N'$SQL_INSTALL_USER_PASSWORD', DEFAULT_DATABASE=[$SQL_INSTALL_DATABASE], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER [$SQL_INSTALL_USER]"
70+
fi
71+
72+
echo Done!

.github/workflows/ezsql-linux.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# GitHub Action for PHP with extensions
2+
name: Linux
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
branches:
10+
- master
11+
12+
jobs:
13+
linux:
14+
name: Linux (PHP ${{ matrix.php-versions }} CI)
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
operating-system: [ubuntu-latest]
20+
php-versions: ['7.4', '8.0']
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
- name: Setup PHP, with composer and extensions
26+
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
27+
with:
28+
php-version: ${{ matrix.php-versions }}
29+
extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug
30+
coverage: xdebug
31+
- name: Start MySQL
32+
run: sudo systemctl start mysql.service
33+
- name: Setup MySQL Database
34+
run: |
35+
mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;"
36+
mysql -uroot -h127.0.0.1 -proot -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;"
37+
- name: Start PostgreSql
38+
run: |
39+
sudo systemctl start postgresql.service
40+
pg_isready
41+
- name: Create additional user
42+
run: |
43+
sudo -u postgres psql --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du"
44+
- name: Setup PostgreSql Database
45+
run: |
46+
sudo -u postgres createdb --owner=ez_test ez_test
47+
- name: Setup SQLServer Database
48+
run: |
49+
chmod +x "${GITHUB_WORKSPACE}/.github/install_mssql.sh"
50+
"${GITHUB_WORKSPACE}/.github/install_mssql.sh"
51+
- name: Install dependencies
52+
run: composer update
53+
- name: Test with phpunit
54+
run: vendor/bin/phpunit --coverage-clover=coverage.xml
55+
- name: Submit code coverage
56+
run: bash <(curl -s https://codecov.io/bash)

.github/workflows/ezsql-windows.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# GitHub Action for PHP with extensions
2+
name: Windows
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
branches:
10+
- master
11+
12+
jobs:
13+
windows:
14+
name: Windows (PHP ${{ matrix.php-versions }} CI)
15+
runs-on: windows-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
operating-system: [windows-latest]
20+
php-versions: ['7.1', '7.2']
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
- name: Setup PHP, with composer and extensions
26+
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
27+
with:
28+
php-version: ${{ matrix.php-versions }}
29+
extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug
30+
coverage: xdebug
31+
- name: Chocolatey Install MySQL
32+
run: choco install mysql --version=5.7.18 -y -f
33+
- name: Setup MySQL Database
34+
run: |
35+
mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;"
36+
mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;"
37+
- name: Chocolatey Uninstall PostgreSql 13
38+
run: choco uninstall postgresql13 -y -f
39+
- name: Chocolatey Install PostgreSql 9
40+
run: choco install postgresql9 --params '/Password:root' -y -f
41+
- name: Setup PostgreSql Database
42+
run: |
43+
$env:Path += ";C:\Program Files\PostgreSQL\9.6\bin"
44+
$env:PGPASSWORD = "root"
45+
psql -U postgres --command="\conninfo"
46+
psql -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du"
47+
createdb --owner=ez_test ez_test
48+
[Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine)
49+
- name: Chocolatey Install SQLServer
50+
run: choco install sql-server-express -ia "/IACCEPTSQLSERVERLICENSETERMS /Q /ACTION=install /INSTANCEID=MSSQLSERVER /INSTANCENAME=MSSQLSERVER /UPDATEENABLED=FALSE /TCPENABLED=1 /SECURITYMODE=SQL /SAPWD=Password12!" -o -y -f
51+
- name: Setup SQLServer Database
52+
run: |
53+
sqlcmd -L
54+
New-NetFirewallRule -DisplayName "SQLServer default instance" -Direction Inbound -LocalPort 1433 -Protocol TCP -Action Allow
55+
New-NetFirewallRule -DisplayName "SQLServer Browser service" -Direction Inbound -LocalPort 1434 -Protocol UDP -Action Allow
56+
sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test"
57+
sqlcmd -S localhost,1433 -U sa -P Password12! -d ez_test -Q "CREATE LOGIN ez_test WITH PASSWORD=N'ezTest', DEFAULT_DATABASE=ez_test, CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF; ALTER SERVER ROLE [sysadmin] ADD MEMBER ez_test"
58+
- name: Install dependencies
59+
run: composer update
60+
- name: Test with phpunit
61+
run: vendor\bin\phpunit --coverage-clover=coverage.xml
62+
- name: Submit code coverage
63+
uses: codecov/codecov-action@v1
64+
with:
65+
file: ./coverage.xml # optional

.travis.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# **ezsql**
22

3-
[![Build Status](https://travis-ci.org/ezSQL/ezsql.svg?branch=master)](https://travis-ci.org/ezSQL/ezsql)
4-
[![Build status](https://ci.appveyor.com/api/projects/status/6s8oqnoxa2i5k04f?svg=true)](https://ci.appveyor.com/project/jv2222/ezsql)
3+
[![Windows](https://github.com/ezSQL/ezsql/workflows/Windows/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AWindows)
4+
[![Linux](https://github.com/ezSQL/ezsql/workflows/Linux/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3ALinux)
55
[![codecov](https://codecov.io/gh/ezSQL/ezSQL/branch/master/graph/badge.svg)](https://codecov.io/gh/ezSQL/ezSQL)
66
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/aad1f6aaaaa14f60933e75615da900b8)](https://www.codacy.com/app/techno-express/ezsql?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ezSQL/ezsql&amp;utm_campaign=Badge_Grade)
77
[![Maintainability](https://api.codeclimate.com/v1/badges/6f6107f25e9de7bf4272/maintainability)](https://codeclimate.com/github/ezSQL/ezsql/maintainability)
8-
[![Total Downloads](https://poser.pugx.org/jv2222/ezsql/downloads)](https://packagist.org/packages/jv2222/ezsql)
8+
[![Total Downloads](https://poser.pugx.org/ezSQL/ezsql/downloads)](https://packagist.org/packages/ezSQL/ezsql)
99

1010
***A class to make it very easy to deal with database connections.***
1111

appveyor.yml

Lines changed: 0 additions & 114 deletions
This file was deleted.

lib/Database.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@ class Database
1818
private static $instances = [];
1919

2020
private function __construct()
21-
{ }
21+
{
22+
}
2223
private function __clone()
23-
{ }
24-
private function __wakeup()
25-
{ }
24+
{
25+
}
26+
public function __wakeup()
27+
{
28+
}
2629

2730
/**
2831
* Initialize and connect a vendor database.
2932
*
3033
* @param mixed $vendor - SQL driver
3134
* @param mixed $setting - SQL connection parameters
3235
* @param mixed $tag - Store the instance for later use
36+
* @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli
3337
*/
3438
public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null)
3539
{

0 commit comments

Comments
 (0)