diff --git a/.editorconfig b/.editorconfig index 82df922..ecf13ec 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,3 +20,6 @@ indent_size = 4 [*.md] indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/.envrc b/.envrc index b999773..92e8ffd 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ PATH_add vendor/bin +PATH_add tools diff --git a/.gitattributes b/.gitattributes index c41471d..1b04a98 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,3 +9,4 @@ /phpstan.neon.dist export-ignore /phpunit.xml.dist export-ignore /test export-ignore +/Makefile diff --git a/.github/workflows/acceptance.yml b/.github/workflows/acceptance.yml index b4941db..7248c98 100644 --- a/.github/workflows/acceptance.yml +++ b/.github/workflows/acceptance.yml @@ -44,16 +44,16 @@ jobs: ${{ runner.os }}-composer- - name: Install Dependencies - run: composer install --no-interaction --prefer-dist --no-progress + run: make install - name: Check Code Style - run: composer style:check + run: make check-style - name: Run Static Analysis - run: composer test:static -- --no-progress + run: make static-check - name: Run Unit & Functional Tests - run: composer test:coverage + run: make coverage - name: Upload Coverage uses: codecov/codecov-action@v3 diff --git a/.gitignore b/.gitignore index e998e45..c42787d 100644 --- a/.gitignore +++ b/.gitignore @@ -194,3 +194,4 @@ Temporary Items /coverage.xml /phpstan.neon /captainhook.config.json +/tools diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ea952bc --- /dev/null +++ b/Makefile @@ -0,0 +1,98 @@ +COMPOSER_VERSION := 2.5.8 +PHPUNIT_VERSION := 10.2.4 +PHPSTAN_VERSION := 1.10.25 +PHP_CS_FIXER_VERSION := 3.21.1 +PHPUNIT_GLOBALS_VERSION := 3.1.2 + +SRC_FILES := $(shell find src test -name '*.php') + + +## Manage Dependencies +.PHONY: install +install: tools/composer + php tools/composer install + +.PHONY: update +update: composer.lock vendor + +composer.lock vendor: tools/composer composer.json + php tools/composer install + + +## PHP CS Fixer +.PHONY: check-style +check-style: tools/php-cs-fixer + php tools/php-cs-fixer fix -v --ansi --dry-run --diff + +.PHONY: fix-style +fix-style: tools/php-cs-Fixer + php tools/php-cs-fixer fix -v --ansi + + +## PHPStan +.PHONY: static-check +static-check: tools/phpstan + php tools/phpstan analyze --ansi + + +## PHPUnit +.PHONY: test +test: tools/phpunit tools/phpunit.d/zalas-phpunit-globals-extension.phar + php tools/phpunit --colors=always + +.PHONY: coverage +coverage: coverage.xml + +coverage.xml: tools/phpunit tools/phpunit.d/zalas-phpunit-globals-extension.phar $(SRC_FILES) + php tools/phpunit --coverage-clover=coverage.xml + + +.PHONY: all-tests +all-tests: check-style static-check test + + +## Tool Aliases +.PHONY: composer +composer: tools/composer + +.PHONY: php-cs-fixer +php-cs-fixer: tools/php-cs-fixer + +.PHONY: phpstan +phpstan: tools/phpstan + +.PHONY: phpunit +phpunit: tools/phpunit + + +## Download Tools +tools: + @mkdir -p tools + +tools/phpunit.d: + @mkdir -p tools/phpunit.d + +tools/composer: tools/composer-installer | tools + @php tools/composer-installer --version=${COMPOSER_VERSION} --filename=tools/composer + +tools/composer-installer: | tools + @curl -s -o tools/composer-installer https://getcomposer.org/installer + @echo "`curl -s https://composer.github.io/installer.sig` tools/composer-installer" | sha384sum -c - + +tools/php-cs-fixer: | tools + @curl -s -L -o tools/php-cs-fixer https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/v$(PHP_CS_FIXER_VERSION)/php-cs-fixer.phar + +tools/phpstan: | tools + @curl -s -L -o tools/phpstan https://github.com/phpstan/phpstan/releases/download/$(PHPSTAN_VERSION)/phpstan.phar + +tools/phpunit: | tools + @curl -s -L -o tools/phpunit https://phar.phpunit.de/phpunit-$(PHPUNIT_VERSION).phar + +tools/phpunit.d/zalas-phpunit-globals-extension.phar: | tools/phpunit.d + @curl -s -L -o tools/phpunit.d/zalas-phpunit-globals-extension.phar https://github.com/jakzal/phpunit-globals/releases/download/v$(PHPUNIT_GLOBALS_VERSION)/zalas-phpunit-globals-extension.phar + + +## Cleanup +.PHONY: clean +clean: + rm -rf tools vendor composer.lock coverage.xml diff --git a/captainhook.json b/captainhook.json index 0c101ef..03dd59a 100644 --- a/captainhook.json +++ b/captainhook.json @@ -8,17 +8,17 @@ "conditions": [] }, { - "action": "composer style:check -- --no-ansi", + "action": "make check-style", "options": [], "conditions": [] }, { - "action": "composer test:static -- --no-ansi", + "action": "make static-check", "options": [], "conditions": [] }, { - "action": "composer test:phpunit -- --colors=never", + "action": "make test", "options": [], "conditions": [] } diff --git a/composer.json b/composer.json index 89d2ed7..c899ec9 100644 --- a/composer.json +++ b/composer.json @@ -29,17 +29,13 @@ "captainhook/captainhook": "~5.16.4", "captainhook/plugin-composer": "~5.3.3", "ergebnis/composer-normalize": "~2.33.0", - "friendsofphp/php-cs-fixer": "^3.21.1", "maglnet/composer-require-checker": "~4.6.0", "mockery/mockery": "~1.6.2", "phpstan/extension-installer": "~1.3.1", - "phpstan/phpstan": "~1.10.25", "phpstan/phpstan-deprecation-rules": "~1.1.3", "phpstan/phpstan-mockery": "~1.1.1", "phpstan/phpstan-phpunit": "~1.3.13", - "phpstan/phpstan-strict-rules": "~1.5.1", - "phpunit/phpunit": "~10.2.4", - "zalas/phpunit-globals": "~3.1.2" + "phpstan/phpstan-strict-rules": "~1.5.1" }, "minimum-stability": "stable", "autoload": { @@ -64,25 +60,5 @@ "branch-alias": { "dev-develop": "1.0.x-dev" } - }, - "scripts": { - "style:check": "php-cs-fixer fix -v --ansi --dry-run --diff", - "style:fix": "php-cs-fixer fix -v --ansi", - "test": [ - "@style:check", - "@test:static", - "@test:phpunit" - ], - "test:coverage": "phpunit --coverage-clover=coverage.xml", - "test:phpunit": "phpunit --colors=always", - "test:static": "phpstan analyze --ansi" - }, - "scripts-descriptions": { - "style:check": "Check all files for code style violations.", - "style:fix": "Automatically fix code style in all files.", - "test": "Check code style, static analysis, and unit tests.", - "test:coverage": "Run unit tests and generate coverage report.", - "test:phpunit": "Run unit & functional tests.", - "test:static": "Run phpstan static analysis." } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fd24ba2..dd4bfc4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,3 +8,4 @@ parameters: - '/Readonly property BeBat\\ConsoleColor\\Style::.+ is assigned outside of the constructor/' - '/Call to an undefined method BeBat\\Verify\\API\\Value::/' - '/Access to an undefined property BeBat\\Verify\\API\\Value::/' + - '/Attribute class Zalas\\PHPUnit\\Globals\\Attribute\\Putenv does not exist/' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6a0bce5..99ed9df 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,8 @@ failOnWarning="true" failOnDeprecation="true" failOnNotice="true" - testdox="true"> + testdox="true" + extensionsDirectory="tools/phpunit.d"> test