Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
*.md export-ignore
*.yml export-ignore
.php-cs-fixer.dist.php export-ignore
Makefile export-ignore
Taskfile.yml export-ignore
20 changes: 12 additions & 8 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
name: Static analysis
on: [push]
name: static-analysis
on:
pull_request:
push:
branches: ['main']

jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # https://github.com/actions/checkout/releases/tag/v6.0.2
- uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # https://github.com/shivammathur/setup-php/releases/tag/2.37.1
with:
php-version: 8.4
- run: composer update --prefer-stable --prefer-dist --no-interaction --no-suggest
extensions: -pdo_mysql, -mysqli
- run: composer update --prefer-stable --prefer-dist --no-interaction
- run: composer phpstan

php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # https://github.com/actions/checkout/releases/tag/v6.0.2
with:
ref: ${{ github.head_ref }}
- name: Run PHP CS fixer
- name: 'Run PHP CS fixer'
uses: ./.github/actions/php-cs-fixer
with:
workspace: ${{ github.workspace }}
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Commit CS fixes
- name: 'Commit CS fixes'
uses: craftzing/git-auto-commit-action@778341af668090896ca464160c2def5d1d1a3eb0
with:
commit_message: Fix code style violations
16 changes: 10 additions & 6 deletions .github/workflows/tests.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Tests
on: [push, pull_request]
name: test
on:
pull_request:
push:
branches: ['main']

jobs:
tests:
Expand All @@ -8,14 +11,15 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-24.04]
php: [8.4]
php: [8.4, 8.5]
dependency-version: [prefer-lowest, prefer-stable]
name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }}
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # https://github.com/actions/checkout/releases/tag/v6.0.2
- uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # https://github.com/shivammathur/setup-php/releases/tag/2.37.1
with:
php-version: ${{ matrix.php }}
coverage: pcov
- run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
extensions: -pdo_mysql, -mysqli
- run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- run: composer coverage:summary
16 changes: 12 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ Make sure to follow these rules when creating a pull request:
- We follow [Semantic Versioning](http://semver.org/), so please send pull requests to the correct branch
- Update the [CHANGELOG.md](CHANGELOG.md) file with any changes/additions/... and follow the [changelog standards](http://keepachangelog.com/)

## 🧪 Running tests
# 🏃‍➡️ Running locally

You can run the test suite with the following command:
```bash
vendor/bin/phpunit
This project is fully Dockerized, meaning [Docker](https://docs.docker.com) (or [Orbstack](https://orbstack.dev) for macOS users) is the only requirement
to run this project locally. Using Docker Compose, we set up a container for each supported PHP version.

> [!TIP]
> While you can run Docker Compose commands directly, we highly recommend to use our predefined tasks using
> [Task](https://taskfile.dev). All docs will always refer to these tasks, but if you prefer not to install
> Task, you can inspect [Taskfile.yml](./Taskfile.yml) to see which Docker Compose commands are used under the hood.

To explore all available tasks, run:
```shell
task
```
13 changes: 0 additions & 13 deletions Makefile

This file was deleted.

61 changes: 61 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# https://taskfile.dev
version: '3.50'

vars:
PHP_VERSIONS: ['8.4', '8.5']
DEFAULT_PHP_VERSION: '8.5'

tasks:
default:
desc: 'List all available tasks'
silent: true
cmd: task --list

up:
desc: 'Up the PHP container(s) and install all Composer dependencies'
cmds:
- docker compose up --detach
- docker compose exec php-{{ .DEFAULT_PHP_VERSION }} composer install

down:
desc: 'Shutdown the PHP container(s)'
cmds:
- docker compose down

php:
desc: 'Open an interactive shell into one of the `php` services (see docker-compose.yml)'
summary: |
Open an interactive shell into one of the `php` services (see docker-compose.yml).

usage:
task php version=<version>
requires:
vars:
- name: version
enum:
ref: .PHP_VERSIONS
cmds:
- docker compose up --detach
- docker compose exec php-{{ .version }} sh

test:
desc: 'Run the testsuite on all or one of the supported PHP versions'
summary: |
Run the testsuite on all or one of the supported PHP versions.

usage:
task test
task test version=<version>
vars:
versions: |-
{{- if .version -}}
{{ .version }}
{{- else -}}
{{ join "," .PHP_VERSIONS }}
{{- end -}}
cmds:
- docker compose up --detach
- for:
var: versions
split: ','
cmd: docker compose exec php-{{ .ITEM }} composer phpunit
12 changes: 11 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
php84:
php-8.4:
build:
context: .
dockerfile: docker/php84/Dockerfile
Expand All @@ -9,3 +9,13 @@ services:
working_dir: /code
volumes:
- ./:/code:delegated
php-8.5:
build:
context: .
dockerfile: docker/php85/Dockerfile
container_name: php-testbench.craftzing.php85
restart: unless-stopped
tty: true
working_dir: /code
volumes:
- ./:/code:delegated
4 changes: 2 additions & 2 deletions docker/php84/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM php:8.4-cli-alpine3.21
FROM php:8.4-cli-alpine3.23

WORKDIR /code

USER root
COPY docker/setup.sh .
RUN chmod u+x /code/setup.sh && /code/setup.sh && rm /code/setup.sh
COPY --from=composer:2.8 /usr/bin/composer /usr/local/bin/composer
COPY --from=composer:2.10 /usr/bin/composer /usr/local/bin/composer

USER app
10 changes: 10 additions & 0 deletions docker/php85/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM php:8.5-cli-alpine3.23

WORKDIR /code

USER root
COPY docker/setup.sh .
RUN chmod u+x /code/setup.sh && /code/setup.sh && rm /code/setup.sh
COPY --from=composer:2.10 /usr/bin/composer /usr/local/bin/composer

USER app
6 changes: 4 additions & 2 deletions src/Factories/ImmutableFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use function iterator_to_array;

/**
* @template TClass
* @template TClass of object
*/
abstract class ImmutableFactory
{
Expand All @@ -34,6 +34,7 @@ final public function __construct(
*/
public function state(array $state): static
{
// @phpstan-ignore-next-line return.type
return new static($this->faker, [...$this->state, ...$state], $this->count);
}

Expand All @@ -42,6 +43,7 @@ public function state(array $state): static
*/
public function times(int $count): static
{
// @phpstan-ignore-next-line return.type
return new static($this->faker, $this->state, $count);
}

Expand Down Expand Up @@ -87,7 +89,7 @@ public function raw(array $attributes = []): array

/**
* @param array<string, mixed> $attributes
* @return array<int, TClass>
* @return array<int, array<string, mixed>>
*/
public function rawMany(array $attributes = []): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/InstanceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use ReflectionProperty;

/**
* @template TClass
* @template TClass of object
*/
final readonly class InstanceFactory
{
Expand Down
12 changes: 7 additions & 5 deletions src/PHPUnit/DataProviders/EnumCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
*/
private array $options;

/**
* @param TValue $instance
* @param TValue ...$options
*/
public function __construct(
/* @var TValue */
public UnitEnum $instance,
/* @param array<int, TValue> ...$options */
UnitEnum ...$options,
) {
in_array($instance, $options, true) or throw new ValueError('Options should contain the given instance.');
Expand Down Expand Up @@ -58,7 +60,7 @@ public function differentInstance(): UnitEnum

/**
* @param class-string<TValue> $enumFQCN
* @return iterable<array<self<TValue>>>
* @return iterable<array{self<TValue>}>
*/
public static function cases(string $enumFQCN): iterable
{
Expand All @@ -72,7 +74,7 @@ public static function cases(string $enumFQCN): iterable

/**
* @param TValue ...$options
* @return iterable<array<self<TValue>>>
* @return iterable<array{self<TValue>}>
*/
public static function options(UnitEnum ...$options): iterable
{
Expand All @@ -83,7 +85,7 @@ public static function options(UnitEnum ...$options): iterable

/**
* @param class-string<TValue> $enumFQCN
* @return iterable<array<self<TValue>>>
* @return iterable<array{self<TValue>}>
*/
public static function except(string $enumFQCN, UnitEnum ...$except): iterable
{
Expand Down
Loading