diff --git a/.docker/Dockerfile-php7.0 b/.docker/Dockerfile-php7.0 new file mode 100644 index 0000000..4a2171d --- /dev/null +++ b/.docker/Dockerfile-php7.0 @@ -0,0 +1,8 @@ +FROM php:7.0-cli-alpine + +COPY ./../.. /usr/src/myapp +WORKDIR /usr/src/myapp + +RUN apk --no-cache add curl zip +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer install diff --git a/.docker/Dockerfile-php7.1 b/.docker/Dockerfile-php7.1 new file mode 100644 index 0000000..cefcb4b --- /dev/null +++ b/.docker/Dockerfile-php7.1 @@ -0,0 +1,8 @@ +FROM php:7.1-cli-alpine + +COPY ./../.. /usr/src/myapp +WORKDIR /usr/src/myapp + +RUN apk --no-cache add curl zip +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer install diff --git a/.docker/Dockerfile-php7.2 b/.docker/Dockerfile-php7.2 new file mode 100644 index 0000000..b7c0189 --- /dev/null +++ b/.docker/Dockerfile-php7.2 @@ -0,0 +1,8 @@ +FROM php:7.2-cli-alpine + +COPY ./../.. /usr/src/myapp +WORKDIR /usr/src/myapp + +RUN apk --no-cache add curl zip +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer install diff --git a/.docker/Dockerfile-php7.3 b/.docker/Dockerfile-php7.3 new file mode 100644 index 0000000..9131723 --- /dev/null +++ b/.docker/Dockerfile-php7.3 @@ -0,0 +1,8 @@ +FROM php:7.3-cli-alpine + +COPY ./../.. /usr/src/myapp +WORKDIR /usr/src/myapp + +RUN apk --no-cache add curl zip +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer install diff --git a/.docker/Dockerfile-php7.4 b/.docker/Dockerfile-php7.4 new file mode 100644 index 0000000..3af4eb1 --- /dev/null +++ b/.docker/Dockerfile-php7.4 @@ -0,0 +1,8 @@ +FROM php:7.4-cli-alpine + +COPY ./../.. /usr/src/myapp +WORKDIR /usr/src/myapp + +RUN apk --no-cache add curl zip +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer install diff --git a/.docker/Dockerfile-php8.0 b/.docker/Dockerfile-php8.0 new file mode 100644 index 0000000..51d344b --- /dev/null +++ b/.docker/Dockerfile-php8.0 @@ -0,0 +1,8 @@ +FROM php:8.0-cli-alpine + +COPY ./../.. /usr/src/myapp +WORKDIR /usr/src/myapp + +RUN apk --no-cache add curl zip +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer install diff --git a/.docker/Dockerfile-php8.1 b/.docker/Dockerfile-php8.1 new file mode 100644 index 0000000..2ddd597 --- /dev/null +++ b/.docker/Dockerfile-php8.1 @@ -0,0 +1,8 @@ +FROM php:8.1-cli-alpine + +COPY ./../.. /usr/src/myapp +WORKDIR /usr/src/myapp + +RUN apk --no-cache add curl zip +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer install diff --git a/.docker/Dockerfile-php8.2 b/.docker/Dockerfile-php8.2 new file mode 100644 index 0000000..c650522 --- /dev/null +++ b/.docker/Dockerfile-php8.2 @@ -0,0 +1,8 @@ +FROM php:8.2-cli-alpine + +COPY ./../.. /usr/src/myapp +WORKDIR /usr/src/myapp + +RUN apk --no-cache add curl zip +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer install diff --git a/.docker/Dockerfile-php8.3 b/.docker/Dockerfile-php8.3 new file mode 100644 index 0000000..671a1d9 --- /dev/null +++ b/.docker/Dockerfile-php8.3 @@ -0,0 +1,8 @@ +FROM php:8.3-cli-alpine + +COPY ./../.. /usr/src/myapp +WORKDIR /usr/src/myapp + +RUN apk --no-cache add curl zip +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer install diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..186c691 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.docker +.dockerignore +.git +.github +composer.lock +docker-compose.yml +vendor/ diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ca6222b..e38e579 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,8 +5,8 @@ on: pull_request: workflow_dispatch: schedule: - # “At 17:45 on Friday.” - - cron: '45 17 * * 5' + # “At 12:00 on Wednesdays.” + - cron: '0 12 * * 3' jobs: build: @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php-version: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] steps: - uses: actions/checkout@v3 @@ -34,7 +34,7 @@ jobs: run: | mkdir ./coverage php -v > ./coverage/php${{ matrix.php-version }}_output.txt && echo '' >> ./coverage/php${{ matrix.php-version }}_output.txt - ./vendor/bin/phpunit --configuration ./tests/phpunit-${{ matrix.php-version }}.xml --coverage-clover ./coverage/php${{ matrix.php-version }}_coverage.clover >> ./coverage/php${{ matrix.php-version }}_output.txt + ./vendor/bin/phpunit -c ./tests/phpunit-${{ matrix.php-version }}.xml --coverage-clover ./coverage/php${{ matrix.php-version }}_coverage.clover >> ./coverage/php${{ matrix.php-version }}_output.txt cat ./coverage/php${{ matrix.php-version }}_output.txt - name: Save coverage results diff --git a/.gitignore b/.gitignore index bbd3373..1debf85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea composer.lock vendor -/coverage/ +/coverage/ \ No newline at end of file diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..af4f7fe --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,25 @@ +# Development + +When a change is made, each php version should be tested in isolation, because depending on the PHP version, composer is downloading different files. + +The Github-ci will automatically performs the phpunit tests as a final check. + +For local testing, this can be done with the prepared docker images, using docker compose. + +### Running local PHPUnit tests + +``` +./docker-run-tests.sh +``` + +### Rebuild docker images + +``` +docker compose build +``` + +### Remove orphans + +``` +docker compose down --remove-orphans +``` diff --git a/README.md b/README.md index efb3dd5..5bc9890 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,22 @@

Convert an array to XML with PHP

+

- + License - +
+
+ + + + + + + + + +

@@ -15,7 +27,7 @@ composer require rboonzaijer/php-array-to-xml ^2.0 ``` -Load the vendor files (these already loaded if you are using something like Symfony or Laravel) +Require the vendor files (these already loaded if you are using something like Symfony or Laravel) ```php require __DIR__ . '/vendor/autoload.php'; ``` @@ -457,14 +469,6 @@ Result (prettified): ``` -# PHPUnit Tests -Use a specific configuration file, depending on your php version: -``` -./vendor/bin/phpunit --configuration ./tests/phpunit-7.0.xml -./vendor/bin/phpunit --configuration ./tests/phpunit-7.1.xml -./vendor/bin/phpunit --configuration ./tests/phpunit-7.2.xml -./vendor/bin/phpunit --configuration ./tests/phpunit-7.3.xml -./vendor/bin/phpunit --configuration ./tests/phpunit-7.4.xml -./vendor/bin/phpunit --configuration ./tests/phpunit-8.0.xml -./vendor/bin/phpunit --configuration ./tests/phpunit-8.1.xml -``` +## Development + +- [DEVELOPMENT.md](DEVELOPMENT.md) diff --git a/composer.json b/composer.json index 40d9157..8f2ffc5 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,10 @@ } ], "require": { - "php" : "^8.0|^7.0" + "php": "^8.0|^7.0" }, "require-dev": { - "phpunit/phpunit" : "^9.5|^8.5|^7.5|^6.5", + "phpunit/phpunit": "^10.5|^9.5|^8.5|^7.5|^6.5", "mockery/mockery": "^1.0" }, "autoload": { diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ad28a60 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,48 @@ +version: "3" + +services: + + php8.3: + build: + context: . + dockerfile: .docker/Dockerfile-php8.3 + + php8.2: + build: + context: . + dockerfile: .docker/Dockerfile-php8.2 + + php8.1: + build: + context: . + dockerfile: .docker/Dockerfile-php8.1 + + php8.0: + build: + context: . + dockerfile: .docker/Dockerfile-php8.0 + + php7.4: + build: + context: . + dockerfile: .docker/Dockerfile-php7.4 + + php7.3: + build: + context: . + dockerfile: .docker/Dockerfile-php7.3 + + php7.2: + build: + context: . + dockerfile: .docker/Dockerfile-php7.2 + + php7.1: + build: + context: . + dockerfile: .docker/Dockerfile-php7.1 + + php7.0: + build: + context: . + dockerfile: .docker/Dockerfile-php7.0 diff --git a/docker-run-tests.sh b/docker-run-tests.sh new file mode 100755 index 0000000..ea0e3d7 --- /dev/null +++ b/docker-run-tests.sh @@ -0,0 +1,10 @@ +docker compose run --rm php7.0 php ./vendor/bin/phpunit -c tests/phpunit-7.0.xml -v && \ +docker compose run --rm php7.1 php ./vendor/bin/phpunit -c tests/phpunit-7.1.xml -v && \ +docker compose run --rm php7.2 php ./vendor/bin/phpunit -c tests/phpunit-7.2.xml -v && \ +docker compose run --rm php7.3 php ./vendor/bin/phpunit -c tests/phpunit-7.3.xml -v && \ +docker compose run --rm php7.4 php ./vendor/bin/phpunit -c tests/phpunit-7.4.xml -v && \ +docker compose run --rm php8.0 php ./vendor/bin/phpunit -c tests/phpunit-8.0.xml -v && \ +docker compose run --rm php8.1 php ./vendor/bin/phpunit -c tests/phpunit-8.1.xml && \ +docker compose run --rm php8.2 php ./vendor/bin/phpunit -c tests/phpunit-8.2.xml && \ +docker compose run --rm php8.3 php ./vendor/bin/phpunit -c tests/phpunit-8.3.xml && \ +echo -e "\n\ndone.\n" diff --git a/src/Traits/DomDocumentBuilder.php b/src/Traits/DomDocumentBuilder.php index 30dc102..5b7de4d 100644 --- a/src/Traits/DomDocumentBuilder.php +++ b/src/Traits/DomDocumentBuilder.php @@ -184,11 +184,12 @@ protected function createXmlElement($name, $value = null, $cdata = false, $attri return $element; } - - $element = $this->_doc->createElement($name, $this->normalizeValue($value)); + $normalizedValue = $this->normalizeValue($value); + $element = $this->_doc->createElement($name, $normalizedValue === null ? '' : $normalizedValue); foreach ($attributes as $attribute_name => $attribute_value) { - $element->setAttribute($attribute_name, $this->normalizeAttributeValue($attribute_value)); + $normalizedValue = $this->normalizeAttributeValue($attribute_value); + $element->setAttribute($attribute_name, $normalizedValue === null ? '' : $normalizedValue); } return $element; diff --git a/tests/phpunit-8.1.xml b/tests/phpunit-8.1.xml index 299ec13..ff30d35 100644 --- a/tests/phpunit-8.1.xml +++ b/tests/phpunit-8.1.xml @@ -1,19 +1,22 @@ - + - + cacheResult="false" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" + cacheDirectory=".phpunit.cache" + backupStaticProperties="false"> + + + ./../tests/ + + + ./../src @@ -21,10 +24,5 @@ ./../vendor ./../tests - - - - ./../tests/ - - + diff --git a/tests/phpunit-8.2.xml b/tests/phpunit-8.2.xml new file mode 100644 index 0000000..206f4e4 --- /dev/null +++ b/tests/phpunit-8.2.xml @@ -0,0 +1,28 @@ + + + + + + ./../tests/ + + + + + ./../src + + + ./../vendor + ./../tests + + + diff --git a/tests/phpunit-8.3.xml b/tests/phpunit-8.3.xml new file mode 100644 index 0000000..206f4e4 --- /dev/null +++ b/tests/phpunit-8.3.xml @@ -0,0 +1,28 @@ + + + + + + ./../tests/ + + + + + ./../src + + + ./../vendor + ./../tests + + +