From 18b7bdeb60744d7b5f60dc7b40c1d1e626e86d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chicory=20=20=E2=98=95?= Date: Tue, 29 Oct 2024 09:53:57 +0100 Subject: [PATCH] Initial commit --- .gitea/workflows/run-full-tests.yaml | 30 +++++++++++++++++ .gitignore | 6 ++++ .php-cs-fixer.php | 31 +++++++++++++++++ LICENSE | 18 ++++++++++ Makefile | 32 ++++++++++++++++++ README.md | 40 ++++++++++++++++++++++ composer.json | 50 ++++++++++++++++++++++++++++ docker/Dockerfile | 16 +++++++++ docker/docker-compose.yaml | 11 ++++++ phpstan.neon | 4 +++ phpunit.xml | 23 +++++++++++++ src/ExampleClass.php | 13 ++++++++ tests/ExampleClassTest.php | 27 +++++++++++++++ 13 files changed, 301 insertions(+) create mode 100644 .gitea/workflows/run-full-tests.yaml create mode 100644 .gitignore create mode 100644 .php-cs-fixer.php create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 composer.json create mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.yaml create mode 100644 phpstan.neon create mode 100644 phpunit.xml create mode 100644 src/ExampleClass.php create mode 100644 tests/ExampleClassTest.php diff --git a/.gitea/workflows/run-full-tests.yaml b/.gitea/workflows/run-full-tests.yaml new file mode 100644 index 0000000..9a891fb --- /dev/null +++ b/.gitea/workflows/run-full-tests.yaml @@ -0,0 +1,30 @@ +name: Run code tests +run-name: Run code tests +on: + push: + workflow_dispatch: + +jobs: + Run-code-test: + container: + image: "ch1c0ry/php8-cli-actrunner:latest" + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Install Composer dependencies + uses: "https://github.com/ramsey/composer-install@v3" + with: + composer-options: "--optimize-autoloader" + + - name: Check code style + run: | + composer run code-style-check + + - name: Run analyzer + run: | + composer run analyze-code + + - name: Run unit tests + run: | + composer run run-unit-tests diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b6d51a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea +.vscode +.phpunit.cache +.php-cs-fixer.cache +/vendor +composer.lock \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..2443f84 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,31 @@ +setRiskyAllowed(true) + ->setRules([ + '@PSR12' => true, + '@Symfony' => true, + 'assign_null_coalescing_to_coalesce_equal' => true, + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'declare_strict_types' => true, + 'nullable_type_declaration' => true, + 'phpdoc_var_annotation_correct_order' => true, + 'single_line_empty_body' => true, + 'ternary_to_null_coalescing' => true, + 'phpdoc_align' => ['align' => 'left'], + 'concat_space' => ['spacing' => 'one'], + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => true, + ], + ]) + ->setFinder(PhpCsFixer\Finder::create() + ->in(__DIR__.'/src') + ->in(__DIR__.'/tests') + ); diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ae6316c --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ + Copyright (c) 2024 chicory@fossee.net + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c4fe1a7 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +service_name := composer-package-dev +compose_file := ./docker/docker-compose.yaml +compose_command := PUID=$(shell id -u) PGID=$(shell id -g) docker-compose -f $(compose_file) +compose_run := $(compose_command) run --rm $(service_name) + +build: + @$(compose_command) build + +install: + @make build + @$(compose_run) composer install + +prune: + @$(compose_command) rm -fsv + +exec-shell: + @$(compose_run) sh + +code-style-fix: + @$(compose_run) composer code-style-fix + +code-style-check: + @$(compose_run) composer code-style-check + +analyze-code: + @$(compose_run) composer analyze-code + +run-unit-tests: + @$(compose_run) composer run-unit-tests + +full-test: + @$(compose_run) composer full-test diff --git a/README.md b/README.md new file mode 100644 index 0000000..53b8142 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +Composer package template +========================= + +Template for composer packages with CI and a Docker image for local development. + +Commands +-------- +### Install dependencies +```bash +make install +``` + +### Сode style fixer +```bash +make code-style-fix +``` + +### Сode style check +```bash +make code-style-check +``` + +### Run analyzer +```bash +make analyze-code +``` + +### Run unit tests +```bash +make run-unit-tests +``` + +### Run full test +```bash +make full-test +``` +### Remove all docker data +```bash +make prune +``` \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..44b1a57 --- /dev/null +++ b/composer.json @@ -0,0 +1,50 @@ +{ + "name": "chicory/package-template", + "description": "Composer package template", + "type": "library", + "license": "MIT", + "autoload": { + "psr-4": { + "Chicory\\PackageTemplate\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Chicory\\Tests\\PackageTemplate\\": "tests/" + } + }, + "authors": [ + { + "name": "Chicory", + "email": "chicory@fossee.net" + } + ], + "minimum-stability": "stable", + "require": { + "php": "8.*" + }, + "require-dev": { + "phpunit/phpunit": "11.*", + "phpstan/phpstan": "1.*", + "friendsofphp/php-cs-fixer": "^3.60" + }, + "scripts": { + "code-style-check": [ + "./vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --using-cache=no" + ], + "code-style-fix": [ + "./vendor/bin/php-cs-fixer fix -v --using-cache=no" + ], + "analyze-code": [ + "./vendor/bin/phpstan" + ], + "run-unit-tests": [ + "./vendor/bin/phpunit" + ], + "full-test": [ + "@code-style-check", + "@analyze-code", + "@run-unit-tests" + ] + } +} diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..797a42f --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,16 @@ +FROM php:8.3-fpm-alpine + +RUN apk add --no-cache make + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +ARG PUID=1000 +ARG PGID=1000 + +RUN addgroup -g ${PGID} www && adduser -u ${PUID} -G www -s /bin/sh -D www + +COPY --chown=www:www ./ /var/www + +USER www + +WORKDIR /var/www \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 0000000..33b7386 --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,11 @@ +--- +services: + composer-package-dev: + build: + context: ../ + dockerfile: ./docker/Dockerfile + args: + - PUID=${PUID} + - PGID=${PGID} + volumes: + - ..:/var/www \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..cc317e6 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: max + paths: + - src \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..222528b --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,23 @@ + + + + + tests + + + + + + src + + + diff --git a/src/ExampleClass.php b/src/ExampleClass.php new file mode 100644 index 0000000..d94784d --- /dev/null +++ b/src/ExampleClass.php @@ -0,0 +1,13 @@ +exampleClass = new ExampleClass(); + + parent::setUp(); + } + + public function testExampleClass(): void + { + $this->assertEquals('Hello', $this->exampleClass->sayHello()); + } +}