Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated code formatting and tests. #142

Merged
merged 1 commit into from
Jan 17, 2025
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
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 @@
* @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 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
);

Check warning on line 73 in src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php

View check run for this annotation

Codecov / codecov/patch

src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php#L66-L73

Added lines #L66 - L73 were not covered by tests
}
}

Expand Down
Loading
Loading