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
34 changes: 3 additions & 31 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
pull_request: ~

jobs:
test-php-74:
name: Code quality PHP 7.4
test-php-8336:
name: Code quality PHP 8.3.36
runs-on: [ubuntu-latest]
steps:
- name: Checkout
Expand All @@ -16,35 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Lint
run: composer lint:check

- name: PHP Static Analysis
run: composer phpstan

- name: Unit Test
run: composer phpunit

test-php-80:
name: Code quality PHP 8.0
runs-on: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.3.36
coverage: xdebug

- name: Validate composer.json and composer.lock
Expand Down
9 changes: 5 additions & 4 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
$config
->setRules([
'@Symfony' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@PHP7x1Migration:risky' => true,
'@PHPUnit6x0Migration:risky' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'concat_space' => ['spacing' => 'one'],
'class_attributes_separation' => ['elements' => ['method'=>'one']],
'declare_strict_types' => true,
'global_namespace_import' => false,
'increment_style' => ['style' => 'post'],
'list_syntax' => ['syntax' => 'short'],
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
Expand Down Expand Up @@ -45,10 +46,10 @@
// special handling of fabbot.io service if it's using too old PHP CS Fixer version
if (false !== getenv('FABBOT_IO')) {
try {
PhpCsFixer\FixerFactory::create()
(new PhpCsFixer\FixerFactory())
->registerBuiltInFixers()
->registerCustomFixers($config->getCustomFixers())
->useRuleSet(new PhpCsFixer\RuleSet($config->getRules()))
->useRuleSet(new PhpCsFixer\RuleSet\RuleSet($config->getRules()))
;
} catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) {
$config->setRules([]);
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM php:8.3.36-cli

RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates libzip-dev unzip \
&& docker-php-ext-install zip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint

WORKDIR /app

ENV COMPOSER_CACHE_DIR=/tmp/composer-cache

ENTRYPOINT ["sh", "/usr/local/bin/docker-entrypoint"]
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,56 @@ $ composer install
$ vendor/bin/phpunit
```

### With Docker

The project includes a PHP 8.3.36 CLI image for running Composer and the test
suite without installing PHP locally.

```bash
$ docker compose build
$ docker compose run --rm php composer install
$ docker compose run --rm php composer test
```

To run an individual Composer script, replace `composer test` with a script
such as `composer phpunit` or `composer phpstan`.

If an existing installation reports that PHP CS Fixer does not support PHP
8.3, update the development tools together:

```bash
$ docker compose run --rm php composer update friendsofphp/php-cs-fixer phpunit/phpunit phpstan/phpstan --with-all-dependencies
$ docker compose run --rm php composer test
```

This refreshes an older local lock file; `composer install` alone keeps the
locked versions. Do not bypass the fixer's PHP version check with
`PHP_CS_FIXER_IGNORE_ENV`.

The development tools use PHP CS Fixer 3.95+, PHPUnit 9.6, and PHPStan 2.2+.
PHPStan stays at level 8, the equivalent of `max` in the previous PHPStan 0.12
configuration.

If your network uses TLS inspection, ask your IT team for its root CA
certificate in PEM format. Do not disable Composer's TLS verification. Set
`CORPORATE_CA_CERT` to the certificate's path on your host, then use the
additional Compose file. It mounts the certificate and configures Composer to
trust it for both dependency installation and tests:

```bash
$ export CORPORATE_CA_CERT=/path/to/corporate-root-ca.crt
$ docker compose -f compose.yaml -f compose.ca.yaml run --rm php composer install
$ docker compose -f compose.yaml -f compose.ca.yaml run --rm php composer test
```

Use the same `-f compose.yaml -f compose.ca.yaml` options for dependency updates
when your network requires the corporate CA.

Run `composer test` only after `composer install` succeeds; otherwise test
tools such as `php-cs-fixer` will not be installed. The CA certificate is
mounted at runtime and appended to the system CA bundle for Composer only. It
is not added to the repository or Docker image.

JSON
----

Expand Down
7 changes: 7 additions & 0 deletions compose.ca.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
php:
volumes:
- type: bind
source: ${CORPORATE_CA_CERT:?Set CORPORATE_CA_CERT to your corporate CA certificate path}
target: /tmp/corporate-root-ca.crt
read_only: true
7 changes: 7 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
php:
build: .
working_dir: /app
user: "${UID:-1000}:${GID:-1000}"
volumes:
- .:/app
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"type": "library",
"license": "BSD-3-Clause",
"require": {
"php": "^7.4 || ^8.0"
"php": "~8.3.36 || ~8.4.27 || ~8.5.12"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.6",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8.5"
"friendsofphp/php-cs-fixer": "^3.95",
"phpstan/phpstan": "^2.2",
"phpunit/phpunit": "^9.6"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 9 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -eu

if [ -f /tmp/corporate-root-ca.crt ]; then
cat /etc/ssl/certs/ca-certificates.crt /tmp/corporate-root-ca.crt > /tmp/ca-bundle.crt
export COMPOSER_CAFILE=/tmp/ca-bundle.crt
fi

exec "$@"
3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
parameters:
level: max
checkMissingIterableValueType: false
level: 8
paths:
- src
10 changes: 5 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
Expand All @@ -14,9 +14,9 @@
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
3 changes: 3 additions & 0 deletions tests/InflectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use PHPUnit\Framework\TestCase;

/**
* @covers \Linio\Component\Util\Inflector
*/
class InflectorTest extends TestCase
{
public function testIsPascalizingSpinalCase(): void
Expand Down
3 changes: 3 additions & 0 deletions tests/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use PHPUnit\Framework\TestCase;

/**
* @covers \Linio\Component\Util\Json
*/
class JsonTest extends TestCase
{
public function testIsEncoding(): void
Expand Down
Loading