Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer committed Jul 21, 2024
0 parents commit db07011
Show file tree
Hide file tree
Showing 21 changed files with 5,259 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

[*.php]
indent_style = space
indent_size = 4
charset = utf-8
112 changes: 112 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: CI

on: [push, pull_request]

jobs:
testsuite:
name: Unittests
runs-on: ubuntu-20.04

env:
DB_HOST: 127.0.0.1
DB_DATABASE: test
DB_USER: test
DB_ROOT_PASSWORD: changeme
DB_PASSWORD: changeme
REDIS_SCHEME: tcp
REDIS_HOST: 127.0.0.1
REDIS_PORT: 6379

services:
mariadb:
image: mariadb:latest
ports:
- 3306:3306
env:
DATABASE_HOST: 127.0.0.1
MARIADB_DATABASE: test
MARIADB_USER: test
MARIADB_ROOT_PASSWORD: changeme
MARIADB_PASSWORD: changeme
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

strategy:
fail-fast: false
matrix:
php-version: ['8.2', '8.3']

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: json, fileinfo
tools: pecl
coverage: pcov

- name: Composer install
run: |
if [[ ${{ matrix.prefer-lowest == 'prefer-lowest' }} ]]; then
composer update --prefer-lowest --prefer-stable
else
composer install
fi
- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '8.2' ]]; then
bin/phpunit --coverage-clover=coverage.xml
else
bin/phpunit
fi
- name: Code Coverage Report
if: success() && matrix.php-version == '8.2'
uses: codecov/codecov-action@v4

- name: Run Infection
run: |
if [[ ${{ matrix.php-version }} == '8.2' ]]; then
bin/infection
fi
cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: json, fileinfo
coverage: pcov
tools: pecl

- name: Composer install
run: composer update --prefer-lowest --prefer-stable

- name: Run phpcs
run: bin/phpcs --version && bin/phpcs --report=source --standard=phpcs.xml

- name: Run phpstan
run: bin/phpstan -V && bin/phpstan --error-format=github

- name: Run Infection
run: bin/infection
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/bin
/vendor
/tools
/tmp
.idea
.phpunit.cache
.phpunit.result.cache
infection.log
*.drawio.bkp
*.drawio.dtmp
.env
phpunit.xml
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM php:8.3-cli

RUN pecl install redis-5.3.7 \
&& pecl install xdebug-3.2.1 \
&& docker-php-ext-enable pdo_mysql

# Install Composer globally
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Florian Krämer

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.
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.DEFAULT_GOAL := help

help:
@echo "Available commands:"
@echo " - run-tests: Run tests"
@echo " - run-infection: Runs Infection mutation testing"
@echo " - coverage-text: Runs coverage text"
@echo " - coverage-html: Runs coverage html"
@echo " - all: Runs CS-Fixer, CS-Checker, Static Analyser and Tests"
@echo " - shell: Run shell"

run-tests:
@echo "Running tests"
docker compose run php composer test

run-infection:
@echo "Running infection mutation testing"
docker compose run php composer infection

coverage-text:
@echo "Running coverage text"
docker compose run php composer test-coverage

coverage-html:
@echo "Running coverage text"
docker compose run php composer test-coverage-html

all:
@echo "Running CS-Fixer, CS-Checker, Static Analyser and Tests"
docker compose run php composer all

benchmark:
@echo "Running phpbench"
docker compose run php composer benchmark

shell:
@echo "Running shell"
docker compose run --service-ports --entrypoint /bin/bash php
75 changes: 75 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"name": "phauthentic/optional",
"description": "PHP version of Javas Optional class, used to represent a container object which may or may not contain a non-null value.",
"keywords": [
"optional", "php", "oop", "library", "utility"
],
"type": "library",
"require-dev": {
"squizlabs/php_codesniffer": "^3.10",
"phpmd/phpmd": "^2.15",
"infection/infection": "^0.29.6",
"phpunit/phpunit": "^11.2",
"phpstan/phpstan": "^1.11"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Phauthentic\\Optional\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Phauthentic\\Optional\\Test\\": "tests/"
}
},
"authors": [
{
"name": "Florian Krämer"
}
],
"require": {
"php": "^8.2"
},
"config": {
"bin-dir": "bin",
"allow-plugins": {
"infection/extension-installer": true
}
},
"scripts": {
"test": [
"phpunit"
],
"infection": [
"infection"
],
"test-coverage": [
"phpunit --coverage-text"
],
"test-coverage-html": [
"phpunit --coverage-html tmp/coverage/"
],
"cscheck": [
"phpcs src/ tests/ --standard=PSR12 -s"
],
"csfix": [
"phpcbf src/ tests/ --standard=PSR12"
],
"analyze": [
"phpstan analyse src/"
],
"phpmd": [
"bin/phpmd ./src text cleancode,codesize,controversial,design"
],
"benchmark": [
"bin/phpbench run tests/Benchmark/ --report=aggregate"
],
"all": [
"@csfix",
"@cscheck",
"@analyze",
"@test"
]
}
}
Loading

0 comments on commit db07011

Please sign in to comment.