Skip to content

Commit

Permalink
Updated code formatting and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Jan 17, 2025
1 parent b9a77c8 commit 64d929a
Show file tree
Hide file tree
Showing 13 changed files with 409 additions and 521 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
continue-on-error: ${{ vars.CI_LINT_IGNORE_FAILURE == '1' }}

- name: Run unit tests
run: composer test-unit
run: composer test-coverage
continue-on-error: ${{ vars.CI_TEST_UNIT_IGNORE_FAILURE == '1' }}

- name: Run BDD tests
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ You may optionally specify size of browser window in the screenshot step:
| Name | Default value | Description |
|-------------------------|----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| `dir` | `%paths.base%/screenshots` | Path to directory to save screenshots. Directory structure will be created if the directory does not exist. |
| `fail` | `true` | Capture screenshots for failed tests. |
| `fail` | `true` | Capture screenshot on test failure. |
| `fail_prefix` | `failed_` | Prefix failed screenshots with `fail_` string. Useful to distinguish failed and intended screenshots. |
| `purge` | `false` | Remove all files from the screenshots directory on each test run. Useful during debugging of tests. |
| `filenamePattern` | `{datetime:u}.{feature_file}.feature_{step_line}.{ext}` | File name pattern for successful assertions. |
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"phpcbf"
],
"reset": "rm -Rf vendor vendor-bin composer.lock",
"test": "phpunit --no-coverage",
"test-bdd": "behat --colors",
"test-unit": "phpunit"
"test-coverage": "phpunit"
}
}
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ parameters:
# it is not possible to specify the type of the parameter, so we ignore
# this error.
message: '#.*no value type specified in iterable type array.#'
path: tests/phpunit/*
paths:
- tests/phpunit/*
- src/DrevOps/BehatScreenshotExtension/Tokenizer.php
reportUnmatched: false
-
message: '#.*#'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
*/
class ScreenshotContextInitializer implements ContextInitializer {

/**
* Flag to purge files in the directory.
*/
protected bool $needsPurging = TRUE;

/**
* ScreenshotContextInitializer constructor.
*
* @param string $dir
* Screenshot dir.
* @param bool $fail
* Screenshot when fail.
* Create screenshot on test failure.
* @param string $failPrefix
* File name prefix for a failed test.
* @param bool $purge
Expand All @@ -31,13 +36,19 @@ class ScreenshotContextInitializer implements ContextInitializer {
* @param string $filenamePatternFailed
* File name pattern failed.
* @param bool $showPath
* Show current path in screenshots.
* @param bool $needsPurging
* Check if need to actually purge.
* Show current URL in screenshots.
*
* @codeCoverageIgnore
*/
public function __construct(protected string $dir, protected bool $fail, private readonly string $failPrefix, protected bool $purge, protected string $filenamePattern, protected string $filenamePatternFailed, protected bool $showPath = FALSE, protected bool $needsPurging = TRUE) {
public function __construct(
protected string $dir,
protected bool $fail,
private readonly string $failPrefix,
protected bool $purge,
protected string $filenamePattern,
protected string $filenamePatternFailed,
protected bool $showPath = FALSE,
) {
}

/**
Expand All @@ -46,11 +57,20 @@ public function __construct(protected string $dir, protected bool $fail, private
public function initializeContext(Context $context): void {
if ($context instanceof ScreenshotAwareContextInterface) {
$dir = $this->resolveScreenshotDir();
$context->setScreenshotParameters($dir, $this->fail, $this->failPrefix, $this->filenamePattern, $this->filenamePatternFailed, $this->showPath);

if ($this->shouldPurge() && $this->needsPurging) {
$this->purgeFilesInDir($dir);
$this->needsPurging = FALSE;
}

$context->setScreenshotParameters(
$dir,
$this->fail,
$this->failPrefix,
$this->filenamePattern,
$this->filenamePatternFailed,
$this->showPath
);
}
}

Expand Down
Loading

0 comments on commit 64d929a

Please sign in to comment.