From 1aa0aaee660f4631f88a1c93bb938fce3333b7a5 Mon Sep 17 00:00:00 2001
From: Raul Barreras <rbarreras@nebraska.edu>
Date: Tue, 17 Sep 2019 19:39:43 +0000
Subject: [PATCH] add php-lint tester

[skip ci]
---
 .gitlab-ci.yml                          | 10 +++++++++-
 php-lint/php-lint                       |  4 ++--
 php-unit-test/7.1/Dockerfile            |  7 ++++---
 php-unit-test/7.2/Dockerfile            |  4 ++--
 static-code-analysis/Dockerfile         |  2 +-
 static-code-analysis/android/Dockerfile |  2 +-
 t/php-lint/tests.sh                     | 14 ++++++++++++++
 7 files changed, 33 insertions(+), 10 deletions(-)
 create mode 100755 t/php-lint/tests.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b0829d5..014eb93 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -27,7 +27,7 @@ Make All Images:
   script:
     - make 
 
-test:
+Test Sonar Scanner:
   stage: test
   tags:
     - dockerd
@@ -35,6 +35,14 @@ test:
     - docker run --rm its-registry.unl.edu/unl-its/docker-ci/static-code-analysis sonar-scanner -v
     - docker run --rm -v "${PWD}:/work" -w /work its-registry.unl.edu/unl-its/docker-ci/detect-secrets -s
 
+Test PHP Lint:
+  stage: test
+  tags:
+    - linux, dockerd
+  script: 
+    - t/php-lint/tests.sh
+
+
 Push to Container Registry:
   after_script:
     - rm -f /var/lib/gitlab-runner/.docker/config.json
diff --git a/php-lint/php-lint b/php-lint/php-lint
index afb52f2..c14a4f3 100644
--- a/php-lint/php-lint
+++ b/php-lint/php-lint
@@ -51,8 +51,8 @@ for dir in "${LINT_DIRS[@]}"; do
     echo "Scanning directory ${dir} for extension ${ext}"
 
     # Scan current dir and ext and lint them
-    for f in $(find "${dir}" -type f -name "*${ext}"); do
-      OUTPUT=$(php -l $f 2>&1)
+    find "${dir}" -type f -name "*${ext}" -print0 | while IFS= read -r -d '' f; do
+      OUTPUT=$(php -l "$f" 2>&1)
       rc=$?
 
       if [[ $rc != 0 ]]; then # Non-zero exit code, print error and exit
diff --git a/php-unit-test/7.1/Dockerfile b/php-unit-test/7.1/Dockerfile
index 63ce09c..43734ca 100644
--- a/php-unit-test/7.1/Dockerfile
+++ b/php-unit-test/7.1/Dockerfile
@@ -12,9 +12,10 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
       org.label-schema.schema-version="1.0" \
       maintainer="Alan Nelson <alan.nelson@nebraska.edu>"
 
-RUN apk add --no-cache bash nodejs nodejs-npm $PHPIZE_DEPS \
-    && pecl install xdebug \
-    && docker-php-ext-enable xdebug \
+RUN apk add --no-cache bash nodejs nodejs-npm libmcrypt-dev $PHPIZE_DEPS \
+    && pecl install xdebug redis \
+    && docker-php-ext-enable xdebug redis \
+    && docker-php-ext-install mcrypt \
     && apk del --no-cache $PHPIZE_DEPS
 RUN curl -o /usr/local/bin/composer https://getcomposer.org/composer.phar \
   && chmod 755 /usr/local/bin/composer
diff --git a/php-unit-test/7.2/Dockerfile b/php-unit-test/7.2/Dockerfile
index 97bdcd1..7edf64a 100644
--- a/php-unit-test/7.2/Dockerfile
+++ b/php-unit-test/7.2/Dockerfile
@@ -13,8 +13,8 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
       maintainer="Alan Nelson <alan.nelson@nebraska.edu>"
 
 RUN apk add --no-cache bash nodejs nodejs-npm $PHPIZE_DEPS \
-    && pecl install xdebug \
-    && docker-php-ext-enable xdebug \
+    && pecl install xdebug redis \
+    && docker-php-ext-enable xdebug redis \
     && apk del --no-cache $PHPIZE_DEPS
 RUN curl -o /usr/local/bin/composer https://getcomposer.org/composer.phar \
   && chmod 755 /usr/local/bin/composer
diff --git a/static-code-analysis/Dockerfile b/static-code-analysis/Dockerfile
index a6524d4..6424a9a 100644
--- a/static-code-analysis/Dockerfile
+++ b/static-code-analysis/Dockerfile
@@ -12,7 +12,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
       org.label-schema.schema-version="1.0" \
       maintainer="J.R. Barreras <barreras@unl.edu>"
 
-ENV SONAR_SCANNER_VERSION 3.3.0.1492
+ENV SONAR_SCANNER_VERSION 4.0.0.1744
 
 WORKDIR /opt
 
diff --git a/static-code-analysis/android/Dockerfile b/static-code-analysis/android/Dockerfile
index 7ec3ab9..3857f63 100644
--- a/static-code-analysis/android/Dockerfile
+++ b/static-code-analysis/android/Dockerfile
@@ -12,7 +12,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
       org.label-schema.schema-version="1.0" \
       maintainer="Alan Nelson <alan.nelson@nebraska.edu>"
 
-ENV SONAR_SCANNER_VERSION 3.2.0.1227
+ENV SONAR_SCANNER_VERSION 4.0.0.1744
 ENV SONAR_HOME /opt/sonar-scanner
 
 ENV PATH ${PATH}:${SONAR_HOME}
diff --git a/t/php-lint/tests.sh b/t/php-lint/tests.sh
new file mode 100755
index 0000000..0828342
--- /dev/null
+++ b/t/php-lint/tests.sh
@@ -0,0 +1,14 @@
+TMP_DIR=`mktemp -d`
+chmod 777 ${TMP_DIR}
+touch "${TMP_DIR}/dumb php file with spaces.php"
+touch "${TMP_DIR}/ddumb_php_file_without_spaces.php"
+touch "${TMP_DIR}/$(printf '\u03c0').php"
+docker run --rm -v "${TMP_DIR}:/work"  its-registry.unl.edu/unl-its/docker-ci/php-lint:latest php-lint -d /work 
+RET=$?
+rm -rf ${TMP_DIR}
+if [ $RET -eq 0 ]; then
+  echo "PASS";
+else
+  echo "FAIL";
+fi
+exit $RES
-- 
GitLab