Skip to content

Commit

Permalink
Use self aware normalizers (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Kolb <[email protected]>
  • Loading branch information
christian-kolb and Christian Kolb authored Dec 7, 2024
1 parent e013563 commit 0f1dadd
Show file tree
Hide file tree
Showing 55 changed files with 1,768 additions and 2,424 deletions.
4 changes: 2 additions & 2 deletions .docker/php-8.2/Dockerfile → .docker/php-8.4/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Build with
# docker buildx build --platform linux/arm64,linux/amd64 -t ghcr.io/digital-craftsman-de/date-time-precision-php-8.2:latest ./.docker/php-8.2 --push
# docker buildx build --platform linux/arm64,linux/amd64 -t ghcr.io/digital-craftsman-de/date-time-precision-php-8.4:latest ./.docker/php-8.4 --push

FROM php:8.2-fpm-alpine
FROM php:8.4-fpm-alpine

RUN apk add --update \
autoconf \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 21 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: CI
on: push
jobs:

test-8-2:
name: "Tests on PHP 8.2"
test-8-3:
name: "Tests on PHP 8.3"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -18,25 +18,25 @@ jobs:
- name: Setup env
run: cp .github/workflows/.env .env

- name: Cache PHP 8.2 dependencies
id: cache-php-8-2-dependencies
- name: Cache PHP 8.3 dependencies
id: cache-php-8-3-dependencies
uses: actions/cache@v3
env:
cache-name: cache-php-8-2-dependencies
cache-name: cache-php-8-3-dependencies
with:
path: |
~/.cache
vendor
key: ${{ runner.os }}-php-8-2-cache-${{ hashFiles('composer.lock') }}
key: ${{ runner.os }}-php-8-3-cache-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-php-8-2-cache-${{ hashFiles('composer.lock') }}
${{ runner.os }}-php-8-3-cache-${{ hashFiles('composer.lock') }}
- name: Install
if: steps.cache-php-8-2-dependencies.outputs.cache-hit != 'true'
run: make install-8.2
if: steps.cache-php-8-3-dependencies.outputs.cache-hit != 'true'
run: make install-8.3

- name: Run PHP tests
run: make php-8.2-tests-ci
run: make php-8.3-tests-ci

- name: Upload to Codecov
uses: codecov/codecov-action@v4
Expand All @@ -46,8 +46,8 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true

test-8-3:
name: "Tests on PHP 8.3"
test-8-4:
name: "Tests on PHP 8.4"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -62,25 +62,25 @@ jobs:
- name: Setup env
run: cp .github/workflows/.env .env

- name: Cache PHP 8.3 dependencies
id: cache-php-8-3-dependencies
- name: Cache PHP 8.4 dependencies
id: cache-php-8-4-dependencies
uses: actions/cache@v3
env:
cache-name: cache-php-8-3-dependencies
cache-name: cache-php-8-4-dependencies
with:
path: |
~/.cache
vendor
key: ${{ runner.os }}-php-8-3-cache-${{ hashFiles('composer.lock') }}
key: ${{ runner.os }}-php-8-4-cache-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-php-8-3-cache-${{ hashFiles('composer.lock') }}
${{ runner.os }}-php-8-4-cache-${{ hashFiles('composer.lock') }}
- name: Install
if: steps.cache-php-8-3-dependencies.outputs.cache-hit != 'true'
run: make install-8.3
if: steps.cache-php-8-4-dependencies.outputs.cache-hit != 'true'
run: make install-8.4

- name: Run PHP tests
run: make php-8.3-tests-ci
run: make php-8.4-tests-ci

mutation-testing:
name: "Mutation tests"
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
key: ${{ runner.os }}-php-8-3-cache-${{ hashFiles('composer.lock') }}

- name: Install
if: steps.cache-php-8-3-dependencies.outputs.cache-hit != 'true'
if: steps.cache-php-8-4-dependencies.outputs.cache-hit != 'true'
run: make install-8.3

- name: Run mutation testing
Expand Down
73 changes: 22 additions & 51 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,119 +11,93 @@ default: help
## ----
##

## help Print commands help.
.PHONY: help

help: Makefile
@sed -n 's/^##//p' $<

##
## Docker
## ------
##

## build Build the Docker images.
.PHONY: build
build:
docker compose build

## up Start the Docker stack.
.PHONY: up
up: .up

.up:
docker compose up -d

## down Stop the Docker stack.
.PHONY: down
down: .down

.down:
docker compose down

## update Rebuild Docker images and start stack.
.PHONY: update
update: build up

## reset Teardown stack, install and start.
.PHONY: reset
reset: .reset

.PHONY: .reset
.reset: .down .install .up

## install Install PHP dependencies with PHP 8.3.
.PHONY: .install
install: install-8.3

## install-8.2 Install PHP dependencies with PHP 8.2.
.PHONY: install-8.2
install-8.2:
docker compose run --rm php-8.2 composer install

## install-8.3 Install PHP dependencies with the default PHP version (8.3).
.PHONY: install-8.3
install-8.3:
docker compose run --rm php-8.3 composer install

## php-cli Enter a shell for the default PHP version (8.3).
.PHONY: install-8.4
install-8.4:
docker compose run --rm php-8.4 composer install

.PHONY: .php-cli
php-cli: php-8.3-cli

## php-8.2-cli Enter a shell for PHP 8.2.
.PHONY: php-8.2-cli
php-8.2-cli:
docker compose run --rm php-8.2 sh

## php-8.3-cli Enter a shell for PHP 8.3.
.PHONY: php-8.3-cli
php-8.3-cli:
docker compose run --rm php-8.3 sh

.PHONY: php-8.4-cli
php-8.4-cli:
docker compose run --rm php-8.4 sh

##
## Tests and code quality
## ----------------------
##

## verify Run all validations and tests.
.PHONY: verify
verify: php-code-validation php-tests php-mutation-testing

## php-tests Run the tests for all relevant PHP versions.
.PHONY: php-tests
php-tests: php-8.2-tests php-8.3-tests

## php-8.2-tests Run tests with PHP 8.2.
.PHONY: php-8.2-tests
php-8.2-tests:
docker compose run --rm php-8.2 ./vendor/bin/phpunit
php-tests: php-8.3-tests php-8.4-tests

## php-8.3-tests Run tests with PHP 8.3.
.PHONY: php-8.3-tests
php-8.3-tests:
docker compose run --rm php-8.3 ./vendor/bin/phpunit

## php-tests-coverage Run the tests for default PHP version and create coverage report.
.PHONY: php-8.4-tests
php-8.4-tests:
docker compose run --rm php-8.4 ./vendor/bin/phpunit

.PHONY: php-tests-coverage
php-tests-coverage: php-8.3-tests-html-coverage

## php-8.2-tests-html-coverage Run the tests with PHP 8.2 including coverage report as HTML.
.PHONY: php-8.2-tests-html-coverage
php-8.2-tests-html-coverage:
docker compose run --rm php-8.2 ./vendor/bin/phpunit --coverage-html ./coverage

## php-8.3-tests-html-coverage Run the tests with PHP 8.3 including coverage report as HTML.
.PHONY: php-8.3-tests-html-coverage
php-8.3-tests-html-coverage:
docker compose run --rm php-8.3 ./vendor/bin/phpunit --coverage-html ./coverage

## php-code-validation Run code fixers and linters with default PHP version (8.2).
.PHONY: php-8.4-tests-html-coverage
php-8.4-tests-html-coverage:
docker compose run --rm php-8.4 ./vendor/bin/phpunit --coverage-html ./coverage

.PHONY: php-code-validation
php-code-validation:
docker compose run --rm php-8.3 ./vendor/bin/php-cs-fixer fix
docker compose run --rm php-8.3 ./vendor/bin/psalm --show-info=false --no-diff

## php-mutation-testing Run mutation testing with default PHP version (8.2).
.PHONY: php-mutation-testing
php-mutation-testing:
docker compose run --rm php-8.3 ./vendor/bin/infection --show-mutations --only-covered --threads=8
Expand All @@ -133,17 +107,14 @@ php-mutation-testing:
## --
##

## php-8.2-tests-ci Run the tests with PHP 8.2 for CI.
.PHONY: php-8.2-tests-ci
php-8.2-tests-ci:
docker compose run --rm php-8.2 ./vendor/bin/phpunit --coverage-clover ./coverage.xml

## php-8.3-tests-ci Run the tests with PHP 8.3 for CI.
.PHONY: php-8.3-tests-ci
php-8.3-tests-ci:
docker compose run --rm php-8.3 ./vendor/bin/phpunit
docker compose run --rm php-8.3 ./vendor/bin/phpunit --coverage-clover ./coverage.xml

.PHONY: php-8.4-tests-ci
php-8.4-tests-ci:
docker compose run --rm php-8.4 ./vendor/bin/phpunit

## php-mutation-testing-ci Run mutation testing for CI.
.PHONY: php-mutation-testing-ci
php-mutation-testing-ci:
docker compose run --rm php-8.3 ./vendor/bin/infection --only-covered --threads=max
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ The resulting `$bookingsAllowedFrom` is still a date time with timezone `UTC` bu
## Integration

For the best code readability, it's best to use the `Moment` provided with the package as a full replacement for `\DateTime` or `\DateTimeImmutable` when you're speaking about a moment in time and the others value objects for the rest.
The package provides normalizers and Doctrine types for `Moment` and all parts.
The package integrates with the normalizers of `digital-craftsman/self-aware-normalizers` and provides Doctrine types (that use those interfaces) for `Moment` and all parts.

The Doctrine types are automatically registered with the bundle with the following type names:

- `dtp_moment`
- `dtp_time`
- `dtp_weekday`
- `dtp_weekdays`
- `dtp_date`
- `dtp_month`
- `dtp_year`
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"description": "A Symfony bundle for more precise date and time handling through value objects",
"type": "symfony-bundle",
"require": {
"php": "8.2.*|8.3.*",
"php": "8.3.*|8.4.*",
"digital-craftsman/self-aware-normalizers": "^0.2.0",
"doctrine/dbal": "^3.4.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/serializer": "^6.4|^7.0"
"symfony/framework-bundle": "^7.0",
"symfony/serializer": "^7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.40",
"infection/infection": "^0.26.15",
"infection/infection": "0.27.*",
"phpunit/phpunit": "^10.5",
"vimeo/psalm": "^5.16"
},
Expand Down
Loading

0 comments on commit 0f1dadd

Please sign in to comment.