From 07bd520b756d2117f939d547edc304ebfff29cb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A9r=C3=B4me=20Canals?= <>
Date: Sun, 17 Jul 2022 19:49:44 +0200
Subject: [PATCH] php/test refactored

---
 php/test/README.md                       | 63 ++++++++----------------
 php/test/docker-compose.test.5.6.yml     | 13 -----
 php/test/docker-compose.test.7.1.yml     | 13 -----
 php/test/docker-compose.test.7.2.yml     | 13 -----
 php/test/docker-compose.test.7.3-cli.yml | 10 ----
 php/test/docker-compose.test.7.3.yml     | 13 -----
 php/test/docker-php-apache.test.sh       | 14 ++++++
 php/test/docker-php-cli.test.sh          | 16 ++++++
 php/test/{web => html}/index.html        |  0
 php/test/{web => html}/index.php         |  2 +-
 php/test/{web => html}/info.php          |  0
 php/test/src/index.php                   |  2 +-
 php/test/src/sample.php                  |  4 +-
 13 files changed, 55 insertions(+), 108 deletions(-)
 delete mode 100644 php/test/docker-compose.test.5.6.yml
 delete mode 100644 php/test/docker-compose.test.7.1.yml
 delete mode 100644 php/test/docker-compose.test.7.2.yml
 delete mode 100644 php/test/docker-compose.test.7.3-cli.yml
 delete mode 100644 php/test/docker-compose.test.7.3.yml
 create mode 100755 php/test/docker-php-apache.test.sh
 create mode 100755 php/test/docker-php-cli.test.sh
 rename php/test/{web => html}/index.html (100%)
 rename php/test/{web => html}/index.php (79%)
 rename php/test/{web => html}/info.php (100%)

diff --git a/php/test/README.md b/php/test/README.md
index d75710f..ddad51e 100644
--- a/php/test/README.md
+++ b/php/test/README.md
@@ -1,65 +1,42 @@
-###Tests for the 7.2, 7.1 and 5.6 php/apache images
+###Tests for the  php/apache images
 
-####php7.2 image :
+####for php-apache images :
 
 ```shell
-$ docker-compose -f docker-compose.test.7.2.yml up
-Creating web.test.canals.php.7.2
-Attaching to web.test.canals.php.7.2
+$ ./docker-php-apache.test.sh tag
 ...
 
 ```
 
-should lead to the creation and enaction of a container named _web.test.canals.php.7.2_ .
+should lead to the creation and enaction of a docker container based on image canals/php:tag.
+Default value for tag is `latest`
 
 To verify that everything goes well, just point your preferred browser to the following urls:
 
-+ http://localhost:27080/
-+ http://localhost:27080/index.html
-+ http://localhost:27080/info.php
-+ https://localhost:27443/
-+ https://localhost:27443/index.html
-+ https://localhost:27443/info.php
++ http://localhost:9080/
++ http://localhost:9080/index.html
++ http://localhost:9080/info.php
++ https://localhost:9443/
++ https://localhost:9443/index.html
++ https://localhost:9443/info.php
 
-####php7.1 image :
+####for php-cli images :
 
 ```shell
-$ docker-compose -f docker-compose.test.7.1.yml up
-Creating web.test.canals.php.7.1
-Attaching to web.test.canals.php.7.1
+$ ./docker-php-cli.test.sh tag
 ...
-
 ```
 
-should lead to the creation and enaction of a container named _web.test.canals.php.7.1_ .
+should lead to the creation and enaction of a docker container based on the image canals/php:tag
+The container runs the following command :
+```shell
+php -S 0.0.0.0:8000
+```
 
 To verify that everything goes well, just point your preferred browser to the following urls:
 
-+ http://localhost:25080/
-+ http://localhost:25080/index.html
-+ http://localhost:25080/info.php
-+ https://localhost:25443/
-+ https://localhost:25443/index.html
-+ https://localhost:25443/info.php
++ http://localhost:8000/
++ http://localhost:8000/fofo
 
 
-####php5.6 image :
-
-```shell
-$ docker-compose -f docker-compose.test.5.6.yml up
-  Creating web.test.canals.php.5.6
-  Attaching to web.test.canals.php.5.6
-...
-
-```
-
-should lead to the creation and enaction of a container named _web.test.canals.php.5.6_ .
-
-To verify that everything goes well, just point your preferred browser to the following urls:
 
-* http://localhost:26080/
-* http://localhost:26080/index.html
-* http://localhost:26080/info.php
-* https://localhost:26443/
-* https://localhost:26443/index.html
-* https://localhost:26443/info.php
\ No newline at end of file
diff --git a/php/test/docker-compose.test.5.6.yml b/php/test/docker-compose.test.5.6.yml
deleted file mode 100644
index 9185882..0000000
--- a/php/test/docker-compose.test.5.6.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-version: "3"
-services:
-  web:
-    image: canals/php:5.6
-    container_name: web.test.canals.php.5.6
-    ports:
-      - "26080:80"
-      - "26443:443"
-    volumes :
-      - ./web:/var/www/html
-      - ./src:/var/www/src
-
-
diff --git a/php/test/docker-compose.test.7.1.yml b/php/test/docker-compose.test.7.1.yml
deleted file mode 100644
index 0dc9ecb..0000000
--- a/php/test/docker-compose.test.7.1.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-version: "3"
-services:
-  web:
-    image: canals/php:7.1
-    container_name: web.test.canals.php.7.1
-    ports:
-      - "25080:80"
-      - "25443:443"
-    volumes :
-      - ./web:/var/www/html
-      - ./src:/var/www/src
-
-
diff --git a/php/test/docker-compose.test.7.2.yml b/php/test/docker-compose.test.7.2.yml
deleted file mode 100644
index 06ec032..0000000
--- a/php/test/docker-compose.test.7.2.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-version: "3"
-services:
-  web:
-    image: canals/php:7.2
-    container_name: web.test.canals.php.7.2
-    ports:
-      - "27080:80"
-      - "27443:443"
-    volumes :
-      - ./web:/var/www/html
-      - ./src:/var/www/src
-
-
diff --git a/php/test/docker-compose.test.7.3-cli.yml b/php/test/docker-compose.test.7.3-cli.yml
deleted file mode 100644
index eba5d85..0000000
--- a/php/test/docker-compose.test.7.3-cli.yml
+++ /dev/null
@@ -1,10 +0,0 @@
-version: "3"
-services:
-  php:
-    image: canals/php:7.3-cli
-    ports:
-    - "8800:8000"
-    volumes:
-    - ./src:/var/php
-    working_dir: /var/php
-    command: php -S 0.0.0.0:8000 index.php
diff --git a/php/test/docker-compose.test.7.3.yml b/php/test/docker-compose.test.7.3.yml
deleted file mode 100644
index ab98963..0000000
--- a/php/test/docker-compose.test.7.3.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-version: "3"
-services:
-  web:
-    image: canals/php:7.3
-    container_name: web.test.canals.php.7.3
-    ports:
-      - "27080:80"
-      - "27443:443"
-    volumes :
-      - ./web:/var/www/html
-      - ./src:/var/www/src
-
-
diff --git a/php/test/docker-php-apache.test.sh b/php/test/docker-php-apache.test.sh
new file mode 100755
index 0000000..721b1be
--- /dev/null
+++ b/php/test/docker-php-apache.test.sh
@@ -0,0 +1,14 @@
+#!/usr/local/bin/bash
+
+tag="latest"
+if [ $# -ge 1 ]; then
+    tag=$1
+fi
+
+echo "running a canals/php based container with tag : $tag"
+
+docker run --rm\
+       -p 9080:80 -p 9443:443 \
+       -v "$PWD"/html:/var/www/html \
+       -v "$PWD"/src:/var/www/src \
+       canals/php:$tag
diff --git a/php/test/docker-php-cli.test.sh b/php/test/docker-php-cli.test.sh
new file mode 100755
index 0000000..b9607ed
--- /dev/null
+++ b/php/test/docker-php-cli.test.sh
@@ -0,0 +1,16 @@
+#!/usr/local/bin/bash
+
+
+if [ $# -lt 1 ]; then
+    echo "no tag present, stopping"
+    exit 1
+fi
+
+
+
+docker run --rm -it \
+             -p 8000:8000 \
+             -v "$PWD"/src:/var/php \
+             -w /var/php \
+             canals/php:"$1" \
+             php -S 0.0.0.0:8000
diff --git a/php/test/web/index.html b/php/test/html/index.html
similarity index 100%
rename from php/test/web/index.html
rename to php/test/html/index.html
diff --git a/php/test/web/index.php b/php/test/html/index.php
similarity index 79%
rename from php/test/web/index.php
rename to php/test/html/index.php
index 3653270..6dc7b55 100644
--- a/php/test/web/index.php
+++ b/php/test/html/index.php
@@ -7,7 +7,7 @@
  * @author: canals
  */
 
-require_once __DIR__ . '/../src/sample.php';
+$sample = require_once __DIR__ . '/../src/sample.php';
 
 echo <<<EOT
 <!-- DOCTYPE html-->
diff --git a/php/test/web/info.php b/php/test/html/info.php
similarity index 100%
rename from php/test/web/info.php
rename to php/test/html/info.php
diff --git a/php/test/src/index.php b/php/test/src/index.php
index d43d8c5..da498af 100644
--- a/php/test/src/index.php
+++ b/php/test/src/index.php
@@ -8,4 +8,4 @@
 
 echo "php is running !". '<br>';
 
-echo "uri : ". $_SERVER['PATH_INFO'] ;
+echo "uri : ". ( isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : "/") ;
diff --git a/php/test/src/sample.php b/php/test/src/sample.php
index 9eec48d..e344314 100644
--- a/php/test/src/sample.php
+++ b/php/test/src/sample.php
@@ -7,4 +7,6 @@
  * @author: canals
  */
 
-$sample ='hungry heart';
\ No newline at end of file
+$sample ='hungry heart';
+
+return $sample;
\ No newline at end of file
-- 
GitLab