Skip to content

Commit ae6679b

Browse files
authored
ci: setup PHPUnit, PHPStan, PHP CS Fixer and GitHub Actions workflow (#2)
1 parent d754dfd commit ae6679b

13 files changed

Lines changed: 379 additions & 5 deletions

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@
1212
/yarn.lock export-ignore
1313
/doc export-ignore
1414
/.editorconfig export-ignore
15+
/tests export-ignore
16+
/phpunit.xml.dist export-ignore
17+
/phpstan.neon.dist export-ignore
18+
/phpstan-baseline.neon export-ignore

.github/workflows/ci.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
tests:
11+
name: PHP ${{ matrix.php }}
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php: ['8.4']
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ matrix.php }}
27+
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite
28+
coverage: none
29+
30+
- name: Get composer cache directory
31+
id: composer-cache
32+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
33+
34+
- name: Cache composer dependencies
35+
uses: actions/cache@v4
36+
with:
37+
path: ${{ steps.composer-cache.outputs.dir }}
38+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
39+
restore-keys: ${{ runner.os }}-composer-
40+
41+
- name: Install dependencies
42+
run: composer update --prefer-dist --no-progress
43+
44+
- name: Initialize PHPUnit Bridge
45+
run: vendor/bin/simple-phpunit -v
46+
47+
- name: Run PHP CS Fixer (Code Style)
48+
if: matrix.php == '8.4'
49+
run: composer cs:check
50+
51+
- name: Run PHPStan (Static Analysis)
52+
run: composer stan
53+
54+
- name: Run PHPUnit (Tests)
55+
run: composer tests

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
composer.lock
22
var
33
vendor/*
4+
.phpunit.result.cache
5+
/phpunit.xml
6+
.php-cs-fixer.cache
47

58
/node_modules/
69
npm-debug.log

.php-cs-fixer.dist.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$finder = PhpCsFixer\Finder::create()
6+
->in(__DIR__ . '/src')
7+
->in(__DIR__ . '/tests')
8+
->append([__FILE__])
9+
->ignoreDotFiles(true)
10+
->ignoreVCS(true)
11+
->files()
12+
->name('*.php');
13+
14+
return new PhpCsFixer\Config()
15+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
16+
->setRules([
17+
'@Symfony' => true,
18+
'@Symfony:risky' => true,
19+
'@PHP84Migration' => true,
20+
'declare_strict_types' => true,
21+
'global_namespace_import' => [
22+
'import_classes' => true,
23+
'import_constants' => true,
24+
'import_functions' => true,
25+
],
26+
'yoda_style' => false, // Disable the Yoda style (e.g., if (null === $var)) if you prefer the classic style (if ($var === null)).
27+
'concat_space' => ['spacing' => 'one'], // Adds a space around the concatenation points
28+
])
29+
->setUsingCache(true)
30+
->setRiskyAllowed(true)
31+
->setFinder($finder)
32+
->setCacheFile(__DIR__ . '/var/cache/.php-cs-fixer.cache'); // Put the cache away neatly.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<a href="https://packagist.org/packages/ezar101/easyadmin-trix-extension-bundle"><img src="https://poser.pugx.org/ezar101/easyadmin-trix-extension-bundle/v" alt="Latest Stable Version"></a>
55
<a href="https://packagist.org/packages/ezar101/easyadmin-trix-extension-bundle"><img src="https://poser.pugx.org/ezar101/easyadmin-trix-extension-bundle/downloads" alt="Total Downloads"></a>
66
<a href="LICENSE"><img src="https://poser.pugx.org/ezar101/easyadmin-trix-extension-bundle/license" alt="License"></a>
7+
<a href="https://github.com/Ezar101/EasyAdminTrixExtensionBundle/actions/workflows/ci.yaml"><img src="https://github.com/Ezar101/EasyAdminTrixExtensionBundle/actions/workflows/ci.yaml/badge.svg" alt="CI"></a>
78
</p>
89

910
This Symfony bundle extends the native capabilities of EasyAdmin's `TextEditorField` (based on Trix). It offers an enhanced writing experience by adding essential features that are missing by default, all without any complex front-end configuration.

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,42 @@
2525
"symfony/framework-bundle": "^6.0|^7.0|^8.0",
2626
"easycorp/easyadmin-bundle": "^4.0|^5.0"
2727
},
28+
"require-dev": {
29+
"friendsofphp/php-cs-fixer": "^3.94",
30+
"phpstan/extension-installer": "^1.4",
31+
"phpstan/phpstan": "^2.0",
32+
"phpstan/phpstan-phpunit": "^2.0",
33+
"phpstan/phpstan-strict-rules": "^2.0",
34+
"symfony/phpunit-bridge": "^6.4.26|^7.0|^8.0"
35+
},
2836
"autoload": {
2937
"psr-4": {
3038
"Ezar101\\EasyAdminTrixExtensionBundle\\": "src/"
3139
}
3240
},
41+
"autoload-dev": {
42+
"psr-4": {
43+
"Ezar101\\EasyAdminTrixExtensionBundle\\Tests\\": "tests/"
44+
}
45+
},
3346
"config": {
3447
"sort-packages": true,
3548
"allow-plugins": {
49+
"phpstan/extension-installer": true,
3650
"symfony/flex": true,
3751
"symfony/runtime": false
3852
}
3953
},
54+
"scripts": {
55+
"tests": "simple-phpunit",
56+
"cs:check": "php-cs-fixer fix --dry-run --diff",
57+
"cs:fix": "php-cs-fixer fix",
58+
"stan": "phpstan analyse",
59+
"qa": [
60+
"@cs:check",
61+
"@stan",
62+
"@tests"
63+
]
64+
},
4065
"minimum-stability": "stable"
4166
}

phpstan.neon.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
parameters:
2+
level: 6
3+
phpVersion: 80400
4+
paths:
5+
- src/
6+
- tests/
7+
8+
excludePaths:
9+
- vendor/
10+
11+
bootstrapFiles:
12+
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
13+
14+
ignoreErrors:
15+
-
16+
identifier: missingType.generics
17+
18+
treatPhpDocTypesAsCertain: false
19+
reportUnmatchedIgnoredErrors: false
20+
21+
tmpDir: var/cache/phpstan

phpunit.xml.dist

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
6+
colors="true"
7+
bootstrap="tests/bootstrap.php">
8+
9+
<php>
10+
<ini name="display_errors" value="1" />
11+
<ini name="error_reporting" value="-1" />
12+
<server name="APP_ENV" value="test" force="true" />
13+
<server name="APP_DEBUG" value="true" force="true" />
14+
<server name="SHELL_VERBOSITY" value="-1" />
15+
</php>
16+
17+
<testsuites>
18+
<testsuite name="EasyAdmin Trix Extension Unit Test Suite">
19+
<directory>tests/</directory>
20+
</testsuite>
21+
</testsuites>
22+
23+
<coverage processUncoveredFiles="true">
24+
<include>
25+
<directory suffix=".php">src</directory>
26+
</include>
27+
</coverage>
28+
</phpunit>

src/Config/Asset.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
namespace Ezar101\EasyAdminTrixExtensionBundle\Config;
66

7+
use JsonException;
8+
9+
use const JSON_THROW_ON_ERROR;
10+
711
final class Asset
812
{
13+
/** @var array<string, string>|null */
914
private static ?array $manifest = null;
1015

1116
private function __construct()
@@ -20,8 +25,8 @@ public static function from(string $filename): string
2025
if (file_exists($path)) {
2126
try {
2227
$content = file_get_contents($path);
23-
self::$manifest = json_decode($content, true, 512, JSON_THROW_ON_ERROR) ?: [];
24-
} catch (\JsonException $e) {
28+
self::$manifest = json_decode($content, true, 512, JSON_THROW_ON_ERROR) ?? [];
29+
} catch (JsonException $e) {
2530
self::$manifest = [];
2631
}
2732
} else {

src/Field/ExtendedTextEditorField.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44

55
namespace Ezar101\EasyAdminTrixExtensionBundle\Field;
66

7+
use EasyCorp\Bundle\EasyAdminBundle\Config\Asset as EasyAdminAsset;
78
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
89
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
910
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
1011
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\TextEditorType;
1112
use Ezar101\EasyAdminTrixExtensionBundle\Config\Asset;
13+
use InvalidArgumentException;
1214
use Symfony\Contracts\Translation\TranslatableInterface;
13-
use EasyCorp\Bundle\EasyAdminBundle\Config\Asset as EasyAdminAsset;
15+
16+
use function sprintf;
1417

1518
final class ExtendedTextEditorField implements FieldInterface
1619
{
1720
use FieldTrait;
1821

1922
public static function new(string $propertyName, TranslatableInterface|bool|string|null $label = null): self
2023
{
21-
return (new self)
24+
return new self()
2225
->setProperty($propertyName)
2326
->setLabel($label)
2427
->setTemplateName('crud/field/text_editor')
@@ -41,7 +44,7 @@ public static function new(string $propertyName, TranslatableInterface|bool|stri
4144
public function setNumOfRows(int $rows): self
4245
{
4346
if ($rows < 1) {
44-
throw new \InvalidArgumentException(sprintf('The argument of the "%s()" method must be 1 or higher (%d given).', __METHOD__, $rows));
47+
throw new InvalidArgumentException(sprintf('The argument of the "%s()" method must be 1 or higher (%d given).', __METHOD__, $rows));
4548
}
4649

4750
$this->setCustomOption(TextEditorField::OPTION_NUM_OF_ROWS, $rows);
@@ -51,6 +54,7 @@ public function setNumOfRows(int $rows): self
5154

5255
/**
5356
* @param array<string, mixed> $config
57+
*
5458
* @see TextEditorField::setTrixEditorConfig()
5559
*/
5660
public function setTrixEditorConfig(array $config): self

0 commit comments

Comments
 (0)