diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 522ce58..0000000 --- a/.gitattributes +++ /dev/null @@ -1,5 +0,0 @@ -/tests export-ignore -.gitattributes export-ignore -.gitignore export-ignore -.travis.yml export-ignore -phpunit.xml export-ignore diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..62f3254 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,56 @@ +name: Build +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + testing: + name: PHP ${{ matrix.php }} + runs-on: ubuntu-latest + strategy: + matrix: + php: + - 5.6 + - 7.0 + - 7.1 + - 7.2 + - 7.3 + - 7.4 + - 8.0 + - 8.1 + steps: + - uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + ini-values: date.timezone='UTC' + extensions: xmlwriter + tools: composer:v2 + + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache Composer packages + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: php${{ matrix.php }}-composer- + + - name: Install dependencies + run: composer install --no-plugins + + - name: Run test suite + run: XDEBUG_MODE=coverage ./vendor/bin/phpunit + + - name: Upload coverage results to Coveralls + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + composer global require php-coveralls/php-coveralls + php-coveralls --coverage_clover=build/logs/clover.xml -v diff --git a/.gitignore b/.gitignore index da3767d..45a160c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ /logs /phpunit.xml.dist /.idea -/.php_cs.cache +/.php-cs-fixer.cache +/docker-compose.yml +/.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0505928..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: php - -dist: trusty - -php: - - '5.6' - - '7.0' - - '7.1' - - '7.2' - - '7.3' - - '7.4' - -before_script: - - composer install --no-interaction - -after_script: - - vendor/bin/php-coveralls -v diff --git a/CHANGELOG.md b/CHANGELOG.md index 5022d0a..5efdef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ php-html-form - *Dep*: Deprecated. - *Fix*: Fixed. +2.0.1 [2022-01-30] +------------------ + +- Add: Support PHP 8.0, 8.1. + 2.0.0 [2020-02-11] ------------------ diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index a3dcdc7..0000000 --- a/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -FROM alpine:3.11 - -RUN apk update - -RUN apk add --no-cache php7 \ - php7-curl \ - php7-json \ - php7-mbstring \ - php7-xml \ - php7-xdebug \ - php7-ctype \ - php7-session \ - php7-phar \ - php7-tokenizer \ - php7-zlib \ - php7-dom \ - php7-posix \ - php7-openssl \ - php7-simplexml - -RUN sed -ie 's/^;zend/zend/' /etc/php7/conf.d/xdebug.ini - -RUN apk add curl -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer -RUN export COMPOSER_DISABLE_XDEBUG_WARN=1 - -CMD ["php", "-a"] diff --git a/LICENSE.md b/LICENSE.md index 0de9818..ec7000b 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -2,7 +2,7 @@ The MIT License (MIT) Copyright (c) 2016 Adam Wathan -Copyright (c) 2017 Vasily Belosloodcev +Copyright (c) 2022 Vasily Belosloodcev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 235ac2d..fa61937 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ -Form -==== +php-html-form +=== -This is fork of [adamwathan/form](https://github.com/adamwathan/form). There is only HTML-elements builder -without any support frameworks. Extension are supporting PHP from 5.6 to 7.x! +This is fork of [adamwathan/form](https://github.com/adamwathan/form). There is just HTML-elements builder +without any framework support. Extension are supporting PHP from 5.6 to 8.x! -[![Latest Stable Version](https://poser.pugx.org/bupy7/php-html-form/v/stable)](https://packagist.org/packages/bupy7/php-html-form) +[![Stable Version](https://poser.pugx.org/bupy7/php-html-form/v/stable)](https://packagist.org/packages/bupy7/php-html-form) +[![Build status](https://github.com/bupy7/php-html-form/actions/workflows/build.yml/badge.svg)](https://github.com/bupy7/php-html-form/actions/workflows/build.yml) +[![Coverage Status](https://coveralls.io/repos/github/bupy7/php-html-form/badge.svg?branch=master)](https://coveralls.io/github/bupy7/php-html-form?branch=master) [![Total Downloads](https://poser.pugx.org/bupy7/php-html-form/downloads)](https://packagist.org/packages/bupy7/php-html-form) -[![Latest Unstable Version](https://poser.pugx.org/bupy7/php-html-form/v/unstable)](https://packagist.org/packages/bupy7/php-html-form) [![License](https://poser.pugx.org/bupy7/php-html-form/license)](https://packagist.org/packages/bupy7/php-html-form) -[![Build Status](https://travis-ci.org/bupy7/php-html-form.svg?branch=master)](https://travis-ci.org/bupy7/php-html-form) -[![Coverage Status](https://coveralls.io/repos/bupy7/php-html-form/badge.svg?branch=master&service=github)](https://coveralls.io/github/bupy7/php-html-form?branch=master) Boring name for a boring package. Builds form HTML with a fluent-ish, hopefully intuitive syntax. @@ -21,7 +20,7 @@ Boring name for a boring package. Builds form HTML with a fluent-ish, hopefully - [Data Binding](#data-binding) Installation ------------- +--- You can install this package via Composer by running this command in your terminal in the root of your project: @@ -31,7 +30,7 @@ $ composer require bupy7/php-html-form ``` Basic Usage ------------ +--- - [Getting Started](#getting-started) - [Opening a Form](#opening-a-form) @@ -45,7 +44,7 @@ Basic Usage - [Setting Attributes](#setting-attributes) Getting Started ---------------- +--- First, instantiate a FormBuilder... @@ -64,7 +63,7 @@ Next, use the FormBuilder to build an element. For example: Opening a Form --------------- +--- ```php //
@@ -92,7 +91,7 @@ Opening a Form ``` Text and Password Fields ------------------------- +--- Text and password fields share the same interface. @@ -119,7 +118,7 @@ Other available methods: - `enable()` Textareas ---------- +--- Textareas share the same interface as regular text fields, with a couple of extra useful methods. @@ -135,7 +134,7 @@ Textareas share the same interface as regular text fields, with a couple of extr ``` Checkboxes and Radio Buttons ----------------------------- +--- ```php // @@ -158,7 +157,7 @@ Checkboxes and Radio Buttons ``` Selects -------- +--- ```php // @@ -215,7 +214,7 @@ $options = [ ``` Buttons -------- +--- ```php // @@ -232,7 +231,7 @@ Buttons ``` Hidden Inputs -------------- +--- ```php // @@ -240,7 +239,7 @@ Hidden Inputs ``` Labels ------- +--- **Basic Label** ```php @@ -261,7 +260,7 @@ Labels ``` Setting Attributes ------------------- +--- ```php // Attributes can be set with attribute(...) @@ -282,7 +281,7 @@ Setting Attributes ``` Error Messages --------------- +--- FormBuilder also allows you to easily retrieve error messages for your form elements. To do so, just implement the `ErrorStoreInterface` and pass it to the FormBuilder: @@ -321,7 +320,7 @@ token to your form easily like so: ``` Data Binding ------------- +--- Sometimes you might have a form where all of the fields match properties on some sort of object or array in your system, and you want the user to be able to edit that data. Data binding makes this really easy by @@ -343,24 +342,24 @@ $model->email = "john@example.com"; > Note: Be sure to `bind` before creating any other form elements. -Run tests ---------- +Testing +--- -**Using Docker:** +Run tests: -```bash -$ docker-compose up -d -$ docker-compose exec php sh -$ composer test:run +``` +$ ./vendor/bin/phpunit --no-coverage ``` -**Any another way:** +Run tests with coverage: -```bash -$ composer test:run ``` +$ XDEBUG_MODE=coverage ./vendor/bin/phpunit +``` + +HTML coverage path: `build/coverage/index.html` License -------- +--- php-html-form is released under the [MIT License](LICENSE.md). diff --git a/composer.json b/composer.json index 7c88d0d..ddaf72e 100644 --- a/composer.json +++ b/composer.json @@ -11,16 +11,13 @@ "email": "vasily.belosloodcev@gmail.com" } ], - "version": "2.0.0", "license": "MIT", "require": { "php": ">=5.6" }, "require-dev": { - "mockery/mockery": "^1.3.1", - "php-coveralls/php-coveralls": "^2.2.0", - "phpunit/phpunit": ">=5.5 <6.0.0", - "friendsofphp/php-cs-fixer": "^2.16.1" + "mockery/mockery": ">=1.3.5", + "phpunit/phpunit": ">=5.7.27" }, "autoload": { "psr-0": { @@ -31,8 +28,6 @@ "classmap": ["tests/"] }, "scripts": { - "test:run": "./vendor/bin/phpunit --no-coverage", - "test:run-with-cov": "./vendor/bin/phpunit", - "cs:fix": "./vendor/bin/php-cs-fixer fix --config=./phpcs.php" + "cs:fix": "php-cs-fixer fix --config=./phpcs.php --verbose" } } diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index f19ed61..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: '2' - -volumes: - logs: - driver: local - -services: - php: - build: . - working_dir: /var/www - tty: true - volumes: - - .:/var/www - - logs:/var/www/logs diff --git a/phpcs.php b/phpcs.php index 0c8229b..c259b59 100644 --- a/phpcs.php +++ b/phpcs.php @@ -1,5 +1,7 @@ exclude(__DIR__ . '/vendor') ->exclude(__DIR__ . '/logs') ->exclude(__DIR__ . '/build'); -return Config::create() - ->setRules([ - '@PSR2' => true, - 'array_syntax' => [ - 'syntax' => 'short', - ], - ]) - ->setFinder($finder); + +$config = new Config(); +$config->setRules([ + '@PSR2' => true, + 'array_syntax' => [ + 'syntax' => 'short', + ], +]); +$config->setFinder($finder); + +return $config; diff --git a/phpunit.xml b/phpunit.xml index 0a190ac..abddbe5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,21 +1,23 @@ - ./tests - ./tests/TestCase.php - ./tests/bootstrap.php - ./tests/InputContractTest.php - ./tests/TextSubclassContractTest.php + tests + tests/TestCase.php + tests/bootstrap.php + tests/InputContractTest.php + tests/TextSubclassContractTest.php - ./src + src diff --git a/src/AdamWathan/Form/Elements/Element.php b/src/AdamWathan/Form/Elements/Element.php index 4a6a893..722e725 100644 --- a/src/AdamWathan/Form/Elements/Element.php +++ b/src/AdamWathan/Form/Elements/Element.php @@ -137,7 +137,7 @@ protected function setBooleanAttribute($attribute, $value) protected function escape($value) { - return htmlentities($value, ENT_QUOTES, 'UTF-8'); + return htmlentities((string)$value, ENT_QUOTES, 'UTF-8'); } public function __call($method, $params) diff --git a/tests/BindingTest.php b/tests/BindingTest.php index 6c0c6f9..4e7b723 100644 --- a/tests/BindingTest.php +++ b/tests/BindingTest.php @@ -9,12 +9,12 @@ class BindingTest extends TestCase */ protected $form; - public function setUp() + protected function _setUp() { $this->form = new FormBuilder; } - public function tearDown() + protected function _tearDown() { Mockery::close(); } diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 36b6a4b..164af98 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -9,12 +9,12 @@ class FormBuilderTest extends TestCase */ protected $form; - public function setUp() + protected function _setUp() { $this->form = new FormBuilder; } - public function tearDown() + protected function _tearDown() { Mockery::close(); } diff --git a/tests/LabelTest.php b/tests/LabelTest.php index b7bd84b..56331b6 100644 --- a/tests/LabelTest.php +++ b/tests/LabelTest.php @@ -4,7 +4,7 @@ class LabelTest extends TestCase { - public function tearDown() + protected function _tearDown() { Mockery::close(); } diff --git a/tests/TestCase.php b/tests/TestCase.php index a20a3a4..20ca130 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,48 @@ use PHPUnit\Framework\TestCase as BaseTestCase; -class TestCase extends BaseTestCase -{ +if (version_compare(PHP_VERSION, '7.1.0', '>=')) { + class TestCase extends BaseTestCase + { + protected function setUp(): void + { + if (method_exists($this, '_setUp')) { + $this->_setUp(); + } + } + + protected function tearDown(): void + { + if (method_exists($this, '_tearDown')) { + $this->_tearDown(); + } + } + + public static function assertRegExp(string $pattern, string $string, string $message = ''): void + { + self::assertMatchesRegularExpression($pattern, $string, $message); + } + + public static function assertNotRegExp(string $pattern, string $string, string $message = ''): void + { + self::assertDoesNotMatchRegularExpression($pattern, $string, $message); + } + } +} else { + class TestCase extends BaseTestCase + { + protected function setUp() + { + if (method_exists($this, '_setUp')) { + $this->_setUp(); + } + } + + protected function tearDown() + { + if (method_exists($this, '_tearDown')) { + $this->_tearDown(); + } + } + } } diff --git a/workenv/50_xdebug.ini b/workenv/50_xdebug.ini new file mode 100644 index 0000000..40449cd --- /dev/null +++ b/workenv/50_xdebug.ini @@ -0,0 +1,2 @@ +zend_extension=xdebug +xdebug.mode=debug,develop diff --git a/workenv/Dockerfile b/workenv/Dockerfile new file mode 100644 index 0000000..9f107c4 --- /dev/null +++ b/workenv/Dockerfile @@ -0,0 +1,18 @@ +FROM php:8.1-cli-alpine + +RUN apk add --no-cache $PHPIZE_DEPS + +RUN pecl install xdebug && docker-php-ext-enable xdebug +RUN rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +COPY 50_xdebug.ini /usr/local/etc/php/conf.d/ + +RUN curl -sS https://getcomposer.org/installer | php -- --2 --install-dir=/usr/bin --filename=composer +ARG GITHUB_OAUTH_TOKEN=false +RUN if [ ${GITHUB_OAUTH_TOKEN} != false ]; then \ + composer config -g github-oauth.github.com ${GITHUB_OAUTH_TOKEN} \ +;fi +RUN export COMPOSER_DISABLE_XDEBUG_WARN=1 + +RUN composer global require friendsofphp/php-cs-fixer "^3.5.0" + +CMD ["php", "-a"] diff --git a/workenv/docker-compose.yml b/workenv/docker-compose.yml new file mode 100644 index 0000000..6531708 --- /dev/null +++ b/workenv/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3' + +services: + php-cli: + build: + context: workenv + args: + - GITHUB_OAUTH_TOKEN= + working_dir: /app + tty: true + volumes: + - type: bind + source: ./ + target: /app