Skip to content

Commit

Permalink
Feature/patch travis composer (#34)
Browse files Browse the repository at this point in the history
* composer/composer#7797

* Delete composer.phar

* fix syntax error, unexpected '$index'

* fix 'SQL‘ not found
coveralls

* Plugin bootstrap Scripts saved args (set -- $saved)

* php composer.phar

* sql info

* bootstrap test

* Test Workflow

wip : Cannot declare class Tableau, because the name is already in use

* HOW to fix issues Error handling upon first tests

* ./test_cake.sh -p <sql-password> -t

* ERROR 1064 (42000) at line 4 in file: 'app/Config/identities.sql': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if not exists 'test'@'localhost'' at line 1

* Readme

* Remote CI : mysql socket
ERROR 1064 (42000) at line 4 in file: 'app/Config/identities.sql': You 
have an error in your SQL syntax; check the manual that corresponds to 
your MySQL server version for the right syntax to use near 'if not 
exists 'test'@'127.0.0.1'' at line 1

* COLLECT_COVERAGE coveralls
php unit bootstrap

* environment variable

* Documentation

* ./Scripts/bootstrap.sh: line 35: ./app/vendor/bin/phpunit: No such file or directory

* style

* errno : 1054 sqlstate : 42S22 error : Unknown column 'image' in 'field list'
Fatal error: CakePHP core could not be found.  Check the value of 
CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php.  It should point to the 
directory containing your /cake core directory and your /vendors root 
directory. in 
/home/travis/build/b23prodtm/myphpcms/app/bootstrap_phpunit.php on line 
86

* Update php_cms

Fatal error: require(): Failed opening required '' (include_path='.:/home/travis/.phpenv/versions/5.6.32/share/pear') in /home/travis/build/b23prodtm/myphpcms/app/webroot/php_cms/e13/include/SQL.php on line 11
  • Loading branch information
b23prodtm authored Nov 25, 2018
1 parent 65082ea commit bbdc9f2
Show file tree
Hide file tree
Showing 32 changed files with 403 additions and 295 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# User specific & automatically generated files #
#################################################
/app/Config/database.php
/app/Config/database.php*
/app/tmp
/lib/Cake/Console/Templates/skel/tmp/
/plugins
Expand All @@ -10,6 +10,7 @@
/tags
*.mo
/bin/composer.phar
/app/Config/identities.sql*

# IDE and editor specific files #
#################################
Expand Down
20 changes: 14 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ cache:
- $HOME/.composer/cache/files
env:
matrix:
- DB=mysql
- DB=Mysql
global:
- TEST_MYSQL_SERVICE_HOST=127.0.0.1
- TEST_MYSQL_SERVICE_PORT=3306
- TEST_DATABASE_NAME=cakephp_test
- TEST_DATABASE_USER=root
- TEST_DATABASE_PASSWORD=
- PHPUNIT=4
- PHPCS=3
- COLLECT_COVERAGE=true
Expand All @@ -22,7 +27,7 @@ addons:
project:
name: "b23prodtm/myphpcms"
notification_email: b23prodtm@users.sourceforge.net
build_command_prepend: .travis/configure
build_command_prepend: .travis/configure.sh
build_command: if [ '${PHPCS}' != '1' ]; then ./lib/Cake/Console/cake test core AllTests --stderr; else ./app/vendor/bin/phpcs -p --extensions=php --standard=CakePHP ./lib/Cake; fi;
branch_pattern: development
services:
Expand All @@ -36,11 +41,11 @@ matrix:
include:
- os: linux
php: 5.6
env: DB=pgsql
env: DB=Pgsql

- os: linux
php: 5.6
env: DB=sqlite
env: DB=Sqlite

- os: linux
php: 5.6
Expand Down Expand Up @@ -81,13 +86,16 @@ install:
# Local Test (osx configuration and mysql engine) :
# $ ./test-cake.sh --travis
before_script:
- .travis/configure
# remote servers CI doesn't need a root password import (-i) but the socket => -y
- ./configure.sh "-c" "-h" "-p" "pass" "-s" "word" "--mig-database" "-y"
- .travis/configure.sh

script:
# tests with phpunit
- ./test-cake.sh

after_script:
- if [[ "$COLLECT_COVERAGE" == "true" ]]; then travis_retry php app/vendor/bin/coveralls -v ; fi
- if [[ "$COLLECT_COVERAGE" == "true" ]]; then travis_retry php app/vendor/bin/php-coveralls -v -r ./app/; fi

# Openshift webhook notifies that a new build version is available
# $OC_SECRET is obtained from an Openshift Console and set secret environment variable
Expand Down
2 changes: 1 addition & 1 deletion .travis/TravisCI-OSX-PHP
43 changes: 24 additions & 19 deletions .travis/configure → .travis/configure.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
source configure.sh "-c" "-d" "-y" "-h" "-p" "pass" "-s" "word"
echo -e "
Set of default environment
==========================
Expand All @@ -9,25 +8,29 @@ echo -e "
Documented VARIABLES
TRAVIS_OS_NAME: os: ['osx','linux'] in .travis.yml
TRAVIS_PHP_VERSION : php: <version> in .travis.yml
DB=['mysql', 'pgsql', 'sqlite']
DB=['Mysql', 'Pgsql', 'Sqlite']
optional environment VARIABLES
ADDITIONAL_PHP_INI='path to a php.ini settings file'
==========================
";
php bin/composer.phar install --dev --no-interaction
php bin/composer.phar install --no-interaction
if [ ! -z "${ADDITIONAL_PHP_INI}" ]; then /usr/bin/env bash .travis/TravisCI-OSX-PHP/build/custom_php_ini.sh; fi
mkdir -p build/logs
echo "Database Unit Tests... DB=${DB}"
if [[ ("${TRAVIS_OS_NAME}" == "linux") && (${TRAVIS_PHP_VERSION:0:3} == "7.2") ]] ; then pear config-set preferred_state snapshot && yes "" | pecl install mcrypt ; fi
sudo locale-gen de_DE
sudo locale-gen es_ES
if [[ ${DB} == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
if [[ ${DB} == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test2;'; fi
if [[ ${DB} == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test3;'; fi
if [[ ${DB} == 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
if [[ ${DB} == 'pgsql' ]]; then psql -c 'CREATE SCHEMA test2;' -U postgres -d cakephp_test; fi
if [[ ${DB} == 'pgsql' ]]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi
echo -e "Database Unit Tests... DB=${DB}"
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then
pear config-set preferred_state snapshot && yes "" | pecl install mcrypt ;
fi
sudo locale-gen de_DE
sudo locale-gen es_ES
fi
if [[ ${DB} == 'Mysql' ]]; then mysql -e 'CREATE DATABASE IF NOT EXISTS cakephp_test;' -u $TEST_DATABASE_USER --password=$TEST_DATABASE_PASSWORD; fi
if [[ ${DB} == 'Mysql' ]]; then mysql -e 'CREATE DATABASE IF NOT EXISTS cakephp_test2;' -u $TEST_DATABASE_USER --password=$TEST_DATABASE_PASSWORD; fi
if [[ ${DB} == 'Mysql' ]]; then mysql -e 'CREATE DATABASE IF NOT EXISTS cakephp_test3;' -u $TEST_DATABASE_USER --password=$TEST_DATABASE_PASSWORD; fi
if [[ ${DB} == 'Pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
if [[ ${DB} == 'Pgsql' ]]; then psql -c 'CREATE SCHEMA test2;' -U postgres -d cakephp_test; fi
if [[ ${DB} == 'Pgsql' ]]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi
chmod -R 777 ./app/tmp
if [[ ("${TRAVIS_OS_NAME}" == "linux") && (${TRAVIS_PHP_VERSION:0:3} == "5.3") ]] ; then pecl install timezonedb ; fi
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
Expand All @@ -39,14 +42,16 @@ if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
fi
set +H
echo "<?php
/** This is a source file generated by .travis/configure.sh . Modify it from there. */
class DATABASE_CONFIG {
private \$identities = array(
'mysql' => array(
'Mysql' => array(
'datasource' => 'Database/Mysql',
'host' => '127.0.0.1',
'login' => 'root'
'login' => 'root',
'password' => '${SQL_PASSWORD}'
),
'pgsql' => array(
'Pgsql' => array(
'datasource' => 'Database/Postgres',
'host' => '127.0.0.1',
'login' => 'postgres',
Expand All @@ -58,7 +63,7 @@ echo "<?php
'test_database_three' => 'test3'
)
),
'sqlite' => array(
'Sqlite' => array(
'datasource' => 'Database/Sqlite',
'database' => array(
'default' => ':memory:',
Expand Down Expand Up @@ -101,7 +106,7 @@ echo "<?php
'prefix' => ''
);
public function __construct() {
\$db = 'mysql';
\$db = 'Mysql';
if (!empty(\$_SERVER['DB'])) {
\$db = \$_SERVER['DB'];
}
Expand All @@ -117,4 +122,4 @@ echo "<?php
}
}
}" > app/Config/database.php
echo "Unit Test was set up in app/Config/database.php"
echo -e "{green}Unit Test was set up in app/Config/database.php{nc}"
123 changes: 123 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- [CakePHP Sample App on OpenShift](#cakephp-sample-app-on-openshift)
+ [Source repository layout](#source-repository-layout)
+ [Compatibility](#compatibility)
+ [Local Built-in Server](#local-built-in-server)
+ [PHP Unit Test](#php-unit-test)
+ [Common Issues](#common-issues)
+ [License](#license)

<!-- tocstop -->
Expand Down Expand Up @@ -41,6 +44,126 @@ However, if these files exist they will affect the behavior of the build process

This repository is compatible with PHP 5.6 and higher, excluding any alpha or beta versions.

### Local built-in server
>for local test only
Open a Terminal window:

./start_cake.sh

>Ctrl-click the URLs to open them in the browser.
### PHP Unit Test

Open a Terminal window:

./test_cake.sh -p <sql-password>

See [below](#common-issues) to allow access on the built-in local server.

### Common Issues

1. How to fix the following error?

Index page displays:

errno : 1146
sqlstate : 42S02
error : Table 'phpcms.info' doesn't exist

Try the following to migrate (update) all database tables, answer 'y' when prompted:

./migrate-database.sh -u

2. ACCESS DENIED to user appears with other information complaining about database connection, what does that mean ?

You probably have modified user privileges on your server:

mysql -u root
use mysql;
grant all on $TEST_DATABASE_NAME.* to '$TEST_DATABASE_USER'@'$TEST_MYSQL_SERVICE_HOST';
exit
./configure.sh -c

This will reset the connection profile in ..etc/ properties file with the template.
More about environment variables are located in the remote pod (OpenShift) settings and locally in ./Scripts/bootargs.sh.

3. ACCESS DENIED for root@'127.0.0.1' appears with other information complaining about database connection, what does that mean ?

This looks like a first installation of mysql. You have to secure or reset your mysql root access:

sudo rm -rf /usr/local/var/mysql
mysqld --initialize

[Note] A temporary password is generated for root@localhost. Now import identities.

brew services restart mysql@5.7
./migrate-database.sh -Y -i
<temporary password>

4. My mysql server's upgraded to another version, what should I do ?

Upgrade your phpcms database within a (secure)shell:

mysql_upgrade -u root --password=<password>

4. I've made changes to mysql database tables, I've made changes to Config/Schema/myschema.php, as Config/database.php defines it, what should I do ?

Migrate all your tables:

./migrate-database.sh -u

Answer 'y' when prompted.

5. How to fix up 'Database connection "Mysql" is missing, or could not be created' ?

Check your environment variable (./Scripts/bootargs.sh or Docker/Pod settings)

TEST_DATABASE_NAME=cakephp_test

Log in with authorized privileges from a shell prompt:

mysql -u root --password=<password> cakephp_test

6. How to fix up ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) ?

Run the socket fixup script with arguments:

./migrate-database.sh -y
brew services restart mysql@5.7

7. I'm testing with ./start_cake.sh and I cannot add any new post on Updates section, what should I do ?

With the CLI, you may ctrl-X ctrl-C to exit server and migrate your database:

./migrate-database.sh -U
./start_cake.sh

Answer 'y' when prompted.

8. I cannot upload any picture, why ?

The Mysql.php Datasource must define binary and mediumbinary storage types. Please check the file __lib/Cake/Model/Datasource/Mysql.php__, if you experienced the following error:

errno : 1054
sqlstate : 42S22
error : Unknown column 'image' in 'field list'

Add the *__mediumbinary__* storage:

>public $columns = array(...)
'mediumbinary' => array('name' => 'mediumblob'),

>public function column($real){...}, at line 814:
if (strpos($col, 'mediumblob') !== false || $col === 'mediumbinary') {
return 'mediumbinary';
}

Update database schema:

./migrate-database.sh -U

### License
Copyright 2016 b23production GNU

Expand Down
15 changes: 11 additions & 4 deletions Scripts/bootargs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ orange="\033[0;33m"
cyan="\033[0;36m"
#; Host name (unix) 'localhost' generally replaces '127.0.0.1' (macOS).
export DATABASE_ENGINE="Mysql"
export DATABASE_SERVICE_NAME="mysql"
export DATABASE_SERVICE_NAME="MYSQL"
export MYSQL_SERVICE_HOST="127.0.0.1"
#;export MYSQL_SERVICE_HOST="localhost"
export MYSQL_SERVICE_PORT="3306"
export DATABASE_NAME="phpcms"
export DATABASE_USER="test"
export DATABASE_PASSWORD="mypassword"
#. Test configuration ?test=1
export TEST_MYSQL_SERVICE_HOST="127.0.0.1"
#;export TEST_MYSQL_SERVICE_HOST="localhost"
export TEST_MYSQL_SERVICE_PORT="3306"
export TEST_DATABASE_NAME="phpcms"
export TEST_DATABASE_USER="test"
export TEST_DATABASE_PASSWORD="mypassword"
export TEST_DATABASE_NAME="cakephp_test"
export TEST_DATABASE_USER="root"
export TEST_DATABASE_PASSWORD=${SQL_PASSWORD}
export FTP_SERVICE_HOST="localhost"
export FTP_SERVICE_USER="test"
export FTP_SERVICE_PASSWORD="mypassword"
Expand Down
3 changes: 2 additions & 1 deletion Scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ source $hash
echo -e "${nc}Password ${green}$GET_HASH_PASSWORD${nc}"
#; Install PHPUnit, performs unit tests
#; The website must pass health checks in order to be deployed
phpunit="app/vendor/bin/phpunit"
phpunit="./app/Vendor/bin/phpunit"
if [ ! -f $phpunit ]; then
if [ ! -f bin/composer.phar ]; then
source ./Scripts/composer.sh
Expand All @@ -33,3 +33,4 @@ else
echo -e "PHPUnit ${green}[OK]${nc}"
fi
echo `$phpunit --version`
source ./Scripts/config_app_database.sh
28 changes: 11 additions & 17 deletions Scripts/composer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,19 @@ cyan="\033[0;36m"
composer="bin/composer.phar"
if [ ! -f $composer ]; then
echo -e "Composer setup...\n"
EXPECTED_SIGNATURE="$(curl -f https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")"

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi

php composer-setup.php --quiet --install-dir=bin
rm composer-setup.php
mkdir -p bin
cd bin
curl -sS https://getcomposer.org/installer | php
cd ..
else
echo -e "Composer ${green}[OK]${nc}"
fi
echo `bin/composer.phar --version`
php bin/composer.phar --version
echo -e "\n
If you see the message ${red}SHA1 signature could not be verified: broken signature${nc}\r
Do ${cyan}rm bin/composer.phar${nc} please, and again ${cyan}./Scripts/composer.sh${nc}.\r\n"
//// FAQ:
1. When ${orange}SHA1 signature could not be verified: broken signature${nc} appears on terminal :\r
The composer binary wasn't downloaded on this machine or it must be updated :
Please copy and run :
${cyan}rm bin/composer.phar && ./Scripts/composer.sh${nc}\n"
#; update plugins and dependencies
echo `bin/composer.phar update --with-dependencies`
php bin/composer.phar update --with-dependencies --apcu-autoloader
Loading

0 comments on commit bbdc9f2

Please sign in to comment.