From 16bca425d79e34ab4ef09657568ef1e4829b3719 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Mon, 4 Nov 2024 23:11:55 +1100 Subject: [PATCH] Increased code test coverage. --- .../Initializer/ScreenshotContextInitializer.php | 2 ++ .../Context/ScreenshotContext.php | 6 ++++++ .../ServiceContainer/BehatScreenshotExtension.php | 4 ++++ tests/phpunit/Unit/Tokenizer/TokenizerTest.php | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php b/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php index 09bb27b..ba47b1f 100644 --- a/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php +++ b/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php @@ -32,6 +32,8 @@ class ScreenshotContextInitializer implements ContextInitializer { * File name pattern failed. * @param bool $needsPurging * Check if need to actually purge. + * + * @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 $needsPurging = TRUE) { } diff --git a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php index 575ff8e..9313fdc 100644 --- a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php +++ b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php @@ -173,10 +173,12 @@ public function iSaveScreenshot(bool $fail = FALSE, ?string $filename = NULL): v $fileName = $this->makeFileName('png', $filename, $fail); $this->saveScreenshotData($fileName, $data); } + // @codeCoverageIgnoreStart catch (UnsupportedDriverActionException) { // Nothing to do here - drivers without support for screenshots // simply do not have them created. } + // @codeCoverageIgnoreEnd } /** @@ -233,6 +235,8 @@ public function getBeforeStepScope(): BeforeStepScope { * * @return int * Current timestamp. + * + * @codeCoverageIgnore */ public function getCurrentTime(): int { return time(); @@ -303,10 +307,12 @@ protected function makeFileName(string $ext, ?string $filename = NULL, bool $fai } if (!empty($url) && !empty(getenv('BEHAT_SCREENSHOT_TOKEN_HOST'))) { + // @codeCoverageIgnoreStart $host = parse_url($url, PHP_URL_HOST); if ($host) { $url = str_replace($host, getenv('BEHAT_SCREENSHOT_TOKEN_HOST'), $url); } + // @codeCoverageIgnoreEnd } $data = [ diff --git a/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php b/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php index cec09bf..9cc8230 100644 --- a/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php +++ b/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php @@ -24,6 +24,8 @@ class BehatScreenshotExtension implements ExtensionInterface { /** * {@inheritdoc} + * + * @codeCoverageIgnore */ public function process(ContainerBuilder $container): void { } @@ -37,6 +39,8 @@ public function getConfigKey(): string { /** * {@inheritdoc} + * + * @codeCoverageIgnore */ public function initialize(ExtensionManager $extensionManager): void { } diff --git a/tests/phpunit/Unit/Tokenizer/TokenizerTest.php b/tests/phpunit/Unit/Tokenizer/TokenizerTest.php index 35a6793..72275ae 100644 --- a/tests/phpunit/Unit/Tokenizer/TokenizerTest.php +++ b/tests/phpunit/Unit/Tokenizer/TokenizerTest.php @@ -300,6 +300,16 @@ public static function dataProviderReplaceTokens(): array { $data, '20240312_045703.foo-fail_foo-file.feature_6_Foo_step_name.png', ], + [ + '{url}.{ext}', + $data, + 'http%3A%2F%2Fexample.com%2Ffoo%3Ffoo%3Dfoo-value%23hello-fragment.png', + ], + [ + '{nontoken}.{ext}', + $data, + '{nontoken}.png', + ], ]; }