generated from chicory/package-template
This commit is contained in:
commit
18b7bdeb60
30
.gitea/workflows/run-full-tests.yaml
Normal file
30
.gitea/workflows/run-full-tests.yaml
Normal file
|
@ -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
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
.phpunit.cache
|
||||||
|
.php-cs-fixer.cache
|
||||||
|
/vendor
|
||||||
|
composer.lock
|
31
.php-cs-fixer.php
Normal file
31
.php-cs-fixer.php
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
$config = new PhpCsFixer\Config();
|
||||||
|
|
||||||
|
return $config
|
||||||
|
->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')
|
||||||
|
);
|
18
LICENSE
Normal file
18
LICENSE
Normal file
|
@ -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.
|
32
Makefile
Normal file
32
Makefile
Normal file
|
@ -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
|
40
README.md
Normal file
40
README.md
Normal file
|
@ -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
|
||||||
|
```
|
50
composer.json
Normal file
50
composer.json
Normal file
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
16
docker/Dockerfile
Normal file
16
docker/Dockerfile
Normal file
|
@ -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
|
11
docker/docker-compose.yaml
Normal file
11
docker/docker-compose.yaml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
services:
|
||||||
|
composer-package-dev:
|
||||||
|
build:
|
||||||
|
context: ../
|
||||||
|
dockerfile: ./docker/Dockerfile
|
||||||
|
args:
|
||||||
|
- PUID=${PUID}
|
||||||
|
- PGID=${PGID}
|
||||||
|
volumes:
|
||||||
|
- ..:/var/www
|
4
phpstan.neon
Normal file
4
phpstan.neon
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
parameters:
|
||||||
|
level: max
|
||||||
|
paths:
|
||||||
|
- src
|
23
phpunit.xml
Normal file
23
phpunit.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
cacheDirectory=".phpunit.cache"
|
||||||
|
executionOrder="depends,defects"
|
||||||
|
requireCoverageMetadata="true"
|
||||||
|
beStrictAboutCoverageMetadata="true"
|
||||||
|
beStrictAboutOutputDuringTests="true"
|
||||||
|
failOnRisky="true"
|
||||||
|
failOnWarning="true">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="default">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
|
||||||
|
<include>
|
||||||
|
<directory>src</directory>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
|
</phpunit>
|
13
src/ExampleClass.php
Normal file
13
src/ExampleClass.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chicory\PackageTemplate;
|
||||||
|
|
||||||
|
class ExampleClass
|
||||||
|
{
|
||||||
|
public function sayHello(): string
|
||||||
|
{
|
||||||
|
return 'Hello';
|
||||||
|
}
|
||||||
|
}
|
27
tests/ExampleClassTest.php
Normal file
27
tests/ExampleClassTest.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chicory\Tests\PackageTemplate;
|
||||||
|
|
||||||
|
use Chicory\PackageTemplate\ExampleClass;
|
||||||
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
#[CoversClass(ExampleClass::class)]
|
||||||
|
class ExampleClassTest extends TestCase
|
||||||
|
{
|
||||||
|
public ExampleClass $exampleClass;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->exampleClass = new ExampleClass();
|
||||||
|
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExampleClass(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals('Hello', $this->exampleClass->sayHello());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user