Skip to content

Commit 7463431

Browse files
committed
Added testing of PHP code samples (PHPStan, CS-Fixer, Deptrac)
1 parent 19ca290 commit 7463431

16 files changed

Lines changed: 1553 additions & 39 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ yarn.lock
1313
docs/css/*.map
1414
.deptrac.cache
1515
.phpunit.result.cache
16+
code_samples/_inline_php/

.php-cs-fixer-factory.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
use Ibexa\CodeStyle\PhpCsFixer\InternalConfigFactory;
10+
11+
$configFactory = new InternalConfigFactory();
12+
$configFactory->withRules([
13+
'header_comment' => false,
14+
]);
15+
16+
return $configFactory;

.php-cs-fixer-inline.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
/**
10+
* PHP-CS-Fixer configuration for auto-generated inline snippets in code_samples/_inline_php/.
11+
*
12+
* Builds on top of the main .php-cs-fixer.php configuration with additional
13+
* rule overrides:
14+
* - psr_autoloading is disabled: snippet files are named line_N.php and do not
15+
* correspond to any class, so the filename≠class-name rule does not apply.
16+
*/
17+
$configFactory = require __DIR__ . '/.php-cs-fixer-factory.php';
18+
19+
$configFactory->withRules([
20+
'psr_autoloading' => false,
21+
'AdamWojs/phpdoc_force_fqcn_fixer' => false,
22+
]);
23+
24+
return $configFactory
25+
->buildConfig()
26+
->setFinder(
27+
PhpCsFixer\Finder::create()
28+
->in(__DIR__ . '/code_samples/_inline_php')
29+
->files()->name('*.php')
30+
);

.php-cs-fixer.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
*/
77
declare(strict_types=1);
88

9-
use Ibexa\CodeStyle\PhpCsFixer\InternalConfigFactory;
10-
11-
$configFactory = new InternalConfigFactory();
12-
$configFactory->withRules([
13-
'header_comment' => false,
14-
]);
9+
$configFactory = require __DIR__ . '/.php-cs-fixer-factory.php';
1510

1611
return $configFactory
1712
->buildConfig()
@@ -23,5 +18,6 @@
2318
__DIR__ . '/tests',
2419
], 'is_dir')
2520
)
21+
->exclude('_inline_php') // handled separately by .php-cs-fixer-inline.php
2622
->files()->name('*.php')
2723
);

composer.json

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,25 @@
101101
"ibexa/fastly": "~5.0.x-dev"
102102
},
103103
"scripts": {
104-
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
105-
"check-cs": "@fix-cs --dry-run",
106-
"phpstan": "phpstan analyse",
107-
"deptrac": "deptrac analyse",
108-
"check-rector": "rector process --dry-run --ansi",
104+
"fix-cs": [
105+
"php tools/extract-inline-php.php",
106+
"php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
107+
"php-cs-fixer fix --config=.php-cs-fixer-inline.php -v --show-progress=dots",
108+
"php tools/sync-inline-php-to-markdown.php"
109+
],
110+
"check-cs": [
111+
"php tools/extract-inline-php.php",
112+
"php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots --dry-run",
113+
"php-cs-fixer fix --config=.php-cs-fixer-inline.php -v --show-progress=dots --dry-run"
114+
],
115+
"phpstan": "php tools/extract-inline-php.php && phpstan analyse",
116+
"deptrac": "php tools/extract-inline-php.php && deptrac analyse",
117+
"fix-rector": [
118+
"php tools/extract-inline-php.php",
119+
"rector process --ansi",
120+
"php tools/sync-inline-php-to-markdown.php"
121+
],
122+
"check-rector": "php tools/extract-inline-php.php && rector process --dry-run --ansi",
109123
"check-yaml": "phpunit --group yaml",
110124
"phpunit": "phpunit --exclude-group=yaml",
111125
"yaml-update-baseline": "php tests/generate-yaml-baseline.php"
@@ -115,6 +129,7 @@
115129
"check-cs": "Run code style checker for all files",
116130
"phpstan": "Run static code analysis",
117131
"deptrac": "Run Deptrac architecture testing",
132+
"fix-rector": "Automatically applies Rector refactoring to code samples and syncs back to Markdown",
118133
"check-rector": "Check for code refactoring opportunities",
119134
"check-yaml": "Run PHPUnit tests (YAML validation)",
120135
"yaml-update-baseline": "Regenerate tests/yaml-validation-baseline.yaml from current failures"

phpstan-baseline.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -678,18 +678,6 @@ parameters:
678678
count: 1
679679
path: code_samples/tutorials/page_tutorial_starting_point/src/QueryType/MenuQueryType.php
680680

681-
-
682-
message: '#^Instantiated class App\\Notifications\\MyNotification not found\.$#'
683-
identifier: class.notFound
684-
count: 1
685-
path: code_samples/user_management/notifications/notification_send.php
686-
687-
-
688-
message: '#^Parameter \#1 \$notification of class Ibexa\\Contracts\\Notifications\\Value\\Notification\\SymfonyNotificationAdapter constructor expects Symfony\\Component\\Notifier\\Notification\\Notification, App\\Notifications\\MyNotification given\.$#'
689-
identifier: argument.type
690-
count: 1
691-
path: code_samples/user_management/notifications/notification_send.php
692-
693681
-
694682
message: '#^Parameter \#2 \$email of method Ibexa\\Contracts\\OAuth2Client\\Repository\\OAuth2UserService\:\:newOAuth2UserCreateStruct\(\) expects string, string\|null given\.$#'
695683
identifier: argument.type

0 commit comments

Comments
 (0)