From d263e2612bd20fb346b0b864cf893fb47e2d3339 Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Tue, 27 Aug 2024 14:42:48 +0400 Subject: [PATCH 01/10] local docker got refactored --- dev/php.ini | 5 +++++ docker-compose.yml | 24 ++++++++++++++++++------ dockerfile | 21 --------------------- 3 files changed, 23 insertions(+), 27 deletions(-) create mode 100644 dev/php.ini delete mode 100644 dockerfile diff --git a/dev/php.ini b/dev/php.ini new file mode 100644 index 0000000..9976163 --- /dev/null +++ b/dev/php.ini @@ -0,0 +1,5 @@ +zend_extension=xdebug.so +xdebug.mode=debug +xdebug.client_port=9019 +xdebug.idekey=PHPSTORM +xdebug.client_host=host.docker.internal diff --git a/docker-compose.yml b/docker-compose.yml index 0069de9..43c8174 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,14 +2,26 @@ version: '3.8' services: php: - build: - context: . - args: - - PHP_VERSION=${PHP_VERSION} - container_name: php + image: wodby/php:${PHP_VERSION} + working_dir: /srv/web + container_name: templater-php volumes: - .:/srv/web + - ./dev/php.ini:/usr/local/etc/php/conf.d/z-php-sp-overrides.ini environment: - - XDEBUG_MODE=off + XDEBUG_CONFIG: client_host=host.docker.internal + XDEBUG_MODE: $XDEBUG_MODE + PHP_XDEBUG: 1 + PHP_XDEBUG_DEFAULT_ENABLE: 1 + PHP_IDE_CONFIG: $XDEBUG_IDE_CONFIG + PHP_XDEBUG_CLIENT_PORT: $XDEBUG_PORT + PHP_XDEBUG_IDEKEY: $XDEBUG_IDE_KEY + PHP_EXTENSIONS_DISABLE: $EXTENSIONS_DISABLE ports: - "9000:9000" + networks: + - itron-network + +networks: + itron-network: + driver: bridge diff --git a/dockerfile b/dockerfile deleted file mode 100644 index 8421b68..0000000 --- a/dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -ARG PHP_VERSION - -FROM php:${PHP_VERSION}-fpm - -RUN apt-get update && apt-get install -y \ - git \ - unzip \ - zip \ - && docker-php-ext-install pdo pdo_mysql - -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer - -WORKDIR /srv/web - -COPY . . - -RUN chown -R www-data:www-data /srv/web - -EXPOSE 9000 - -CMD ["php-fpm"] From 305ef007027977bf6f9f492190deeddcd7ea2c25 Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Tue, 27 Aug 2024 14:44:29 +0400 Subject: [PATCH 02/10] init.sh got added --- .env.template | 1 - dev/.env.template | 6 ++++++ dev/init.sh | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) delete mode 100644 .env.template create mode 100644 dev/.env.template create mode 100644 dev/init.sh diff --git a/.env.template b/.env.template deleted file mode 100644 index e1b749c..0000000 --- a/.env.template +++ /dev/null @@ -1 +0,0 @@ -PHP_VERSION=8.3 diff --git a/dev/.env.template b/dev/.env.template new file mode 100644 index 0000000..c45cb9b --- /dev/null +++ b/dev/.env.template @@ -0,0 +1,6 @@ +PHP_VERSION=8.3 +XDEBUG_PORT=9019 +XDEBUG_MODE=debug,develop +XDEBUG_IDE_KEY=PHPSTORM +XDEBUG_IDE_CONFIG=serverName=Docker +EXTENSIONS_DISABLE="" diff --git a/dev/init.sh b/dev/init.sh new file mode 100644 index 0000000..ce7f9bf --- /dev/null +++ b/dev/init.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +[ -f ./.env ] || cp ./dev/.env.template ./.env +echo ".env ok" From ab0f8502af1387af62ec1bea2df4e5182b58bf73 Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Tue, 27 Aug 2024 14:45:12 +0400 Subject: [PATCH 03/10] phpunit config docker --- phpunit.xml.dist | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c05e186..ab37037 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,6 +9,10 @@ > + + + + From e8f8f2380f0fbf828bf9e350481abfce3015d736 Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Tue, 27 Aug 2024 14:45:33 +0400 Subject: [PATCH 04/10] makefile --- makefile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 makefile diff --git a/makefile b/makefile new file mode 100644 index 0000000..fdb87f3 --- /dev/null +++ b/makefile @@ -0,0 +1,18 @@ +init: + bash ./dev/init.sh + +docker.up: + docker-compose -p itron-templater up -d + +docker.down: + docker-compose -p itron-templater down + +docker.build.php: + docker-compose -p itron-templater up -d --build php + +connect.php: + docker-compose -p itron-templater exec php bash + +tests.php.run: + docker-compose -p itron-templater exec php vendor/bin/phpunit + From 95fd0a11833d2d7e4e432b4c819ffc7466380233 Mon Sep 17 00:00:00 2001 From: Igor Tron Date: Tue, 27 Aug 2024 15:58:32 +0400 Subject: [PATCH 05/10] remove_spaces() --- tests/TemplaterTest.php | 20 ++++++++++++++------ tests/inc/functions.php | 8 ++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 tests/inc/functions.php diff --git a/tests/TemplaterTest.php b/tests/TemplaterTest.php index 523109f..d04a240 100644 --- a/tests/TemplaterTest.php +++ b/tests/TemplaterTest.php @@ -3,6 +3,8 @@ use iTRON\Templater\Templater; use PHPUnit\Framework\TestCase; +require_once 'inc/functions.php'; + class TemplaterTest extends TestCase { public function testRender() { @@ -75,12 +77,14 @@ public function testRender() { $expected = << -
CONTENT1
CONTENT1.2
CONTENT1.3
+
CONTENT1
+
CONTENT1.2
+
CONTENT1.3
CONTENT2
EXPECTED; - $this->assertEquals( $expected, $result ); + $this->assertEquals( remove_spaces( $expected ), remove_spaces( $result ) ); /** * Template with a preselected value. @@ -107,13 +111,15 @@ public function testRender() { $expected = << -
CONTENT1
CONTENT1.2
CONTENT1.3
+
CONTENT1
+
CONTENT1.2
+
CONTENT1.3
CONTENT2
value2 EXPECTED; - $this->assertEquals( $expected, $result ); + $this->assertEquals( remove_spaces( $expected ), remove_spaces( $result ) ); /** * The same test with a wrong index. @@ -132,13 +138,15 @@ public function testRender() { $expected = << -
CONTENT1
CONTENT1.2
CONTENT1.3
+
CONTENT1
+
CONTENT1.2
+
CONTENT1.3
CONTENT2
value1 EXPECTED; - $this->assertEquals( $expected, $result ); + $this->assertEquals( remove_spaces( $expected ), remove_spaces( $result ) ); /** * Template with nested repeaters. diff --git a/tests/inc/functions.php b/tests/inc/functions.php new file mode 100644 index 0000000..44360bd --- /dev/null +++ b/tests/inc/functions.php @@ -0,0 +1,8 @@ + Date: Tue, 27 Aug 2024 16:14:25 +0400 Subject: [PATCH 06/10] Failure scenario test written --- tests/TemplaterTest.php | 211 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 207 insertions(+), 4 deletions(-) diff --git a/tests/TemplaterTest.php b/tests/TemplaterTest.php index d04a240..94e059b 100644 --- a/tests/TemplaterTest.php +++ b/tests/TemplaterTest.php @@ -144,6 +144,47 @@ public function testRender() {
CONTENT2
value1 +EXPECTED; + + $this->assertEquals( remove_spaces( $expected ), remove_spaces( $result ) ); + } + + public function testNestedRepeaters() { + $templater = new Templater(); + + /** + * Template with several tags. + */ + $tpl = <<