Skip to content

Commit 6f42335

Browse files
committed
Improve code quality and fix PHPUnit configuration
Signed-off-by: Alex Skrypnyk <alex@drevops.com>
1 parent 6656680 commit 6f42335

6 files changed

Lines changed: 61 additions & 19 deletions

File tree

CLAUDE.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Claude Code Configuration
2+
3+
## Standard Operations
4+
5+
These are the standard operations that should be performed when working with this codebase:
6+
7+
### Code Quality Checks
8+
```
9+
composer lint # Run all linting tools
10+
composer lint-fix # Automatically fix linting issues
11+
composer test # Run PHPUnit tests without coverage
12+
```
13+
14+
### Coding Standards
15+
- Follow Drupal coding standards
16+
- Use snake_case for variable names (e.g., `$file_path` not `$filePath`)
17+
- Use TRUE/FALSE constants (uppercase) rather than true/false
18+
- Use NULL constant (uppercase) rather than null
19+
- Maintain proper docblock annotations
20+
21+
### PHPUnit Configuration
22+
- Uses PHPUnit 11.5 with configuration in phpunit.xml
23+
- Coverage reports are generated in .logs/coverage directory
24+
25+
## Recent Improvements
26+
- Updated autoloader from PSR-0 to PSR-4
27+
- Made constants public as per PHP 8.2+ standards
28+
- Improved error messages for file operations
29+
- Optimized token replacement logic
30+
- Updated PHPUnit configuration to remove deprecated attributes
31+
- Ensured all variables follow Drupal's snake_case naming convention
32+
33+
## Code Structure
34+
The Behat Screenshot extension provides functionality to capture screenshots during Behat test runs. Its main components are:
35+
36+
1. **BehatScreenshotExtension**: Handles configuration and service container integration
37+
2. **ScreenshotContext**: Provides Behat steps and screenshot capabilities
38+
3. **Tokenizer**: Processes dynamic filename generation with tokens
39+
40+
## Best Practices for Contributing
41+
1. Always run tests before and after changes
42+
2. Maintain existing code style and standards
43+
3. Fix PHPUnit deprecations as they arise
44+
4. Use verbose error messages to aid debugging

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"symfony/process": "^6.4 || ^7.0"
4040
},
4141
"autoload": {
42-
"psr-0": {
43-
"DrevOps\\BehatScreenshot": "src/"
42+
"psr-4": {
43+
"DrevOps\\BehatScreenshotExtension\\": "src/DrevOps/BehatScreenshotExtension"
4444
}
4545
},
4646
"autoload-dev": {

phpunit.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
21
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
2+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
43
bootstrap="vendor/autoload.php"
54
cacheDirectory=".phpunit.cache"
65
executionOrder="depends,defects"
@@ -12,21 +11,20 @@
1211
displayDetailsOnTestsThatTriggerWarnings="true"
1312
displayDetailsOnTestsThatTriggerErrors="true"
1413
displayDetailsOnTestsThatTriggerNotices="true"
15-
>
14+
displayDetailsOnTestsThatTriggerDeprecations="true">
1615
<testsuites>
1716
<testsuite name="default">
1817
<directory>tests/phpunit</directory>
1918
</testsuite>
2019
</testsuites>
21-
22-
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
20+
<source restrictNotices="true"
21+
restrictWarnings="true"
22+
ignoreIndirectDeprecations="true">
2323
<include>
2424
<directory>src</directory>
2525
</include>
2626
</source>
27-
2827
<coverage includeUncoveredFiles="true"
29-
pathCoverage="false"
3028
ignoreDeprecatedCodeUnits="true"
3129
disableCodeCoverageIgnore="false">
3230
<report>

src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,12 @@ public function iSaveSizedScreenshot(string|int $width = 1440, string|int $heigh
236236
*/
237237
public function saveScreenshotContent(string $filename, string $content): void {
238238
(new Filesystem())->mkdir($this->dir, 0755);
239-
$success = file_put_contents($this->dir . DIRECTORY_SEPARATOR . $filename, $content);
239+
$file_path = $this->dir . DIRECTORY_SEPARATOR . $filename;
240+
$success = file_put_contents($file_path, $content);
240241
if ($success === FALSE) {
241-
throw new \RuntimeException(sprintf('Failed to save screenshot to %s', $filename));
242+
// @codeCoverageIgnoreStart
243+
throw new \RuntimeException(sprintf('Failed to save screenshot to %s. Check permissions and disk space.', $file_path));
244+
// @codeCoverageIgnoreEnd
242245
}
243246
}
244247

src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BehatScreenshotExtension implements ExtensionInterface {
2020
/**
2121
* Extension configuration ID.
2222
*/
23-
const MOD_ID = 'drevops_behat_screenshot';
23+
public const MOD_ID = 'drevops_behat_screenshot';
2424

2525
/**
2626
* {@inheritdoc}

src/DrevOps/BehatScreenshotExtension/Tokenizer.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@ public static function replaceTokens(string $text, array $data = []): string {
3333

3434
// Move {step_name} token to the last position as it may contain other
3535
// tokens.
36-
foreach ($replacements as $name => $value) {
37-
if ($name === '{step_name}') {
38-
$replaced = [$name => $value];
39-
unset($replacements[$name]);
40-
$replacements = array_merge($replacements, $replaced);
41-
break;
42-
}
36+
if (isset($replacements['{step_name}'])) {
37+
$step_name_value = $replacements['{step_name}'];
38+
unset($replacements['{step_name}']);
39+
$replacements['{step_name}'] = $step_name_value;
4340
}
4441

4542
return strtr($text, $replacements);

0 commit comments

Comments
 (0)