Skip to content

Commit

Permalink
Code cleanup, refactor for PHP 8 compatibility, and bug fixes discove…
Browse files Browse the repository at this point in the history
…red 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
  • Loading branch information
TheTechsTech committed Feb 8, 2021
1 parent 66e82e6 commit f50139f
Show file tree
Hide file tree
Showing 28 changed files with 495 additions and 480 deletions.
72 changes: 72 additions & 0 deletions .github/install_mssql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash -e

# Use the following variables to control your install:

# Password for the SA user (required)
MSSQL_SA_PASSWORD='!Passw0rd'

# Product ID of the version of SQL server you're installing
# Must be evaluation, developer, express, web, standard, enterprise, or your 25 digit product key
# Defaults to developer
MSSQL_PID='evaluation'

# Install SQL Server Agent (recommended)
SQL_INSTALL_AGENT='y'

# Install SQL Server Full Text Search (optional)
# SQL_INSTALL_FULLTEXT='y'

# Create an additional user with sysadmin privileges (optional)
SQL_INSTALL_USER='ez_test'
SQL_INSTALL_USER_PASSWORD='ezTest'
SQL_INSTALL_DATABASE='ez_test'

if [ -z $MSSQL_SA_PASSWORD ]
then
echo Environment variable MSSQL_SA_PASSWORD must be set for unattended install
exit 1
fi

echo Adding Microsoft repositories...
sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
repoargs="$(curl https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
sudo add-apt-repository "${repoargs}"

echo Running apt-get update -y...
sudo apt-get update -y

echo Installing SQL Server...
sudo apt-get install -y mssql-server

echo Running mssql-conf setup...
sudo MSSQL_SA_PASSWORD=$MSSQL_SA_PASSWORD \
MSSQL_PID=$MSSQL_PID \
/opt/mssql/bin/mssql-conf -n setup accept-eula

# Configure firewall to allow TCP port 1433:
echo Configuring UFW to allow traffic on port 1433...
sudo ufw allow 1433/tcp
sudo ufw reload

# Restart SQL Server after installing:
echo Restarting SQL Server...
sudo systemctl restart mssql-server

# Optional new user creation:
if [ ! -z $SQL_INSTALL_USER ] && [ ! -z $SQL_INSTALL_USER_PASSWORD ]
then
echo Creating user $SQL_INSTALL_USER
sqlcmd \
-S localhost \
-U SA \
-P $MSSQL_SA_PASSWORD \
-Q "CREATE DATABASE ez_test"
sqlcmd \
-S localhost \
-U SA \
-P $MSSQL_SA_PASSWORD \
-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]"
fi

echo Done!
56 changes: 56 additions & 0 deletions .github/workflows/ezsql-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# GitHub Action for PHP with extensions
name: Linux

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
linux:
name: Linux (PHP ${{ matrix.php-versions }} CI)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.0']

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug
coverage: xdebug
- name: Start MySQL
run: sudo systemctl start mysql.service
- name: Setup MySQL Database
run: |
mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE IF NOT EXISTS ez_test;"
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;"
- name: Start PostgreSql
run: |
sudo systemctl start postgresql.service
pg_isready
- name: Create additional user
run: |
sudo -u postgres psql --command="CREATE USER ez_test PASSWORD 'ezTest'" --command="\du"
- name: Setup PostgreSql Database
run: |
sudo -u postgres createdb --owner=ez_test ez_test
- name: Setup SQLServer Database
run: |
chmod +x "${GITHUB_WORKSPACE}/.github/install_mssql.sh"
"${GITHUB_WORKSPACE}/.github/install_mssql.sh"
- name: Install dependencies
run: composer update
- name: Test with phpunit
run: vendor/bin/phpunit --coverage-clover=coverage.xml
- name: Submit code coverage
run: bash <(curl -s https://codecov.io/bash)
65 changes: 65 additions & 0 deletions .github/workflows/ezsql-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# GitHub Action for PHP with extensions
name: Windows

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
windows:
name: Windows (PHP ${{ matrix.php-versions }} CI)
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
operating-system: [windows-latest]
php-versions: ['7.1', '7.2']

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, fileinfo, mysqli, pdo_mysql, pgsql, pdo_pgsql, sqlite3, pdo_sqlite, sqlsrv, pdo_sqlsrv, xdebug
coverage: xdebug
- name: Chocolatey Install MySQL
run: choco install mysql --version=5.7.18 -y -f
- name: Setup MySQL Database
run: |
mysql -u root -e "CREATE DATABASE IF NOT EXISTS ez_test;"
mysql -u root -e "CREATE USER ez_test@localhost IDENTIFIED BY 'ezTest'; GRANT ALL ON ez_test.* TO ez_test@localhost; FLUSH PRIVILEGES;"
- name: Chocolatey Uninstall PostgreSql 13
run: choco uninstall postgresql13 -y -f
- name: Chocolatey Install PostgreSql 9
run: choco install postgresql9 --params '/Password:root' -y -f
- name: Setup PostgreSql Database
run: |
$env:Path += ";C:\Program Files\PostgreSQL\9.6\bin"
$env:PGPASSWORD = "root"
psql -U postgres --command="\conninfo"
psql -U postgres -c "CREATE USER ez_test WITH PASSWORD 'ezTest';" --command="\du"
createdb --owner=ez_test ez_test
[Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine)
- name: Chocolatey Install SQLServer
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
- name: Setup SQLServer Database
run: |
sqlcmd -L
New-NetFirewallRule -DisplayName "SQLServer default instance" -Direction Inbound -LocalPort 1433 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "SQLServer Browser service" -Direction Inbound -LocalPort 1434 -Protocol UDP -Action Allow
sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE ez_test"
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"
- name: Install dependencies
run: composer update
- name: Test with phpunit
run: vendor\bin\phpunit --coverage-clover=coverage.xml
- name: Submit code coverage
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml # optional
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# **ezsql**

[![Build Status](https://travis-ci.org/ezSQL/ezsql.svg?branch=master)](https://travis-ci.org/ezSQL/ezsql)
[![Build status](https://ci.appveyor.com/api/projects/status/6s8oqnoxa2i5k04f?svg=true)](https://ci.appveyor.com/project/jv2222/ezsql)
[![Windows](https://github.com/ezSQL/ezsql/workflows/Windows/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3AWindows)
[![Linux](https://github.com/ezSQL/ezsql/workflows/Linux/badge.svg)](https://github.com/ezSQL/ezsql/actions?query=workflow%3ALinux)
[![codecov](https://codecov.io/gh/ezSQL/ezSQL/branch/master/graph/badge.svg)](https://codecov.io/gh/ezSQL/ezSQL)
[![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)
[![Maintainability](https://api.codeclimate.com/v1/badges/6f6107f25e9de7bf4272/maintainability)](https://codeclimate.com/github/ezSQL/ezsql/maintainability)
[![Total Downloads](https://poser.pugx.org/jv2222/ezsql/downloads)](https://packagist.org/packages/jv2222/ezsql)
[![Total Downloads](https://poser.pugx.org/ezSQL/ezsql/downloads)](https://packagist.org/packages/ezSQL/ezsql)

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

Expand Down
114 changes: 0 additions & 114 deletions appveyor.yml

This file was deleted.

12 changes: 8 additions & 4 deletions lib/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ class Database
private static $instances = [];

private function __construct()
{ }
{
}
private function __clone()
{ }
private function __wakeup()
{ }
{
}
public function __wakeup()
{
}

/**
* Initialize and connect a vendor database.
*
* @param mixed $vendor - SQL driver
* @param mixed $setting - SQL connection parameters
* @param mixed $tag - Store the instance for later use
* @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli
*/
public static function initialize(?string $vendor = null, ?array $setting = null, ?string $tag = null)
{
Expand Down
Loading

0 comments on commit f50139f

Please sign in to comment.