-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated code to use Drupal coding standards.
- Loading branch information
1 parent
a5d84aa
commit 28c7f3f
Showing
15 changed files
with
1,786 additions
and
1,854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="custom"> | ||
<description>Custom PHPCS standard.</description> | ||
|
||
<!-- Coding standard. --> | ||
<rule ref="Drupal"> | ||
<exclude name="Drupal.Commenting.ClassComment.Short"/> | ||
</rule> | ||
|
||
<!-- Show sniff codes in all reports --> | ||
<arg value="s"/> | ||
<!-- Show progress of the run. --> | ||
<arg value="p"/> | ||
<arg name="colors"/> | ||
|
||
<rule ref="Symfony"/> | ||
|
||
<file>src</file> | ||
<file>tests</file> | ||
<file>tests/phpunit</file> | ||
<file>tests/behat/bootstrap</file> | ||
|
||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"> | ||
<exclude-pattern>./tests/*</exclude-pattern> | ||
</rule> | ||
<rule ref="Symfony.NamingConventions.ValidClassName.InvalidInterfaceName"> | ||
<exclude-pattern>.*context.*</exclude-pattern> | ||
<!-- Allow long array lines in tests. --> | ||
<rule ref="Drupal.Arrays.Array.LongLineDeclaration"> | ||
<exclude-pattern>*.Test\.php</exclude-pattern> | ||
<exclude-pattern>*.TestCase\.php</exclude-pattern> | ||
<exclude-pattern>*.test</exclude-pattern> | ||
</rule> | ||
<rule ref="Symfony.Commenting.FunctionComment.MissingParamTag"> | ||
<exclude-pattern>*</exclude-pattern> | ||
</rule> | ||
<rule ref="Symfony.Commenting.Annotations.Invalid"> | ||
<exclude-pattern>.*context.*</exclude-pattern> | ||
|
||
<!-- Allow missing function names in tests. --> | ||
<rule ref="Drupal.Commenting.FunctionComment.Missing"> | ||
<exclude-pattern>*.Test\.php</exclude-pattern> | ||
<exclude-pattern>*.TestCase\.php</exclude-pattern> | ||
<exclude-pattern>*.test</exclude-pattern> | ||
</rule> <!-- Allow missing function names in tests. --> | ||
|
||
<rule ref="Drupal.Commenting.DocComment.MissingShort"> | ||
<exclude-pattern>tests/behat/bootstrap/BehatCliTrait.php</exclude-pattern> | ||
</rule> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 68 additions & 70 deletions
138
src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,90 @@ | ||
<?php | ||
/** | ||
* @file | ||
* This file is part of the DrevOps\BehatScreenshot package. | ||
*/ | ||
|
||
namespace DrevOps\BehatScreenshotExtension\Context\Initializer; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Behat\Behat\Context\Initializer\ContextInitializer; | ||
use DrevOps\BehatScreenshotExtension\Context\ScreenshotAwareContext; | ||
use DrevOps\BehatScreenshotExtension\Context\ScreenshotAwareContextInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
/** | ||
* Class ScreenshotContextInitializer. | ||
*/ | ||
class ScreenshotContextInitializer implements ContextInitializer | ||
{ | ||
class ScreenshotContextInitializer implements ContextInitializer { | ||
|
||
/** | ||
* ScreenshotContextInitializer constructor. | ||
* | ||
* @param string $dir | ||
* Screenshot dir. | ||
* @param bool $fail | ||
* Screenshot when fail. | ||
* @param string $failPrefix | ||
* File name prefix for a failed test. | ||
* @param bool $purge | ||
* Purge dir before start script. | ||
* @param string $filenamePattern | ||
* File name pattern. | ||
* @param string $filenamePatternFailed | ||
* File name pattern failed. | ||
* @param bool $needsPurging | ||
* Check if need to actually purge. | ||
*/ | ||
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) { | ||
} | ||
|
||
/** | ||
* ScreenshotContextInitializer constructor. | ||
* | ||
* @param string $dir Screenshot dir. | ||
* @param bool $fail Screenshot when fail. | ||
* @param string $failPrefix File name prefix for a failed test. | ||
* @param bool $purge Purge dir before start script. | ||
* @param string $filenamePattern File name pattern. | ||
* @param string $filenamePatternFailed File name pattern failed. | ||
* @param bool $needsPurging Check if need to actually purge. | ||
*/ | ||
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) | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function initializeContext(Context $context): void { | ||
if ($context instanceof ScreenshotAwareContextInterface) { | ||
$dir = $this->resolveScreenshotDir(); | ||
$context->setScreenshotParameters($dir, $this->fail, $this->failPrefix, $this->filenamePattern, $this->filenamePatternFailed); | ||
if ($this->shouldPurge() && $this->needsPurging) { | ||
$this->purgeFilesInDir($dir); | ||
$this->needsPurging = FALSE; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function initializeContext(Context $context): void | ||
{ | ||
if ($context instanceof ScreenshotAwareContext) { | ||
$dir = $this->resolveScreenshotDir(); | ||
$context->setScreenshotParameters($dir, $this->fail, $this->failPrefix, $this->filenamePattern, $this->filenamePatternFailed); | ||
if ($this->shouldPurge() && $this->needsPurging) { | ||
$this->purgeFilesInDir($dir); | ||
$this->needsPurging = false; | ||
} | ||
} | ||
/** | ||
* Remove files in directory. | ||
* | ||
* @param string $dir | ||
* Directory to purge files in. | ||
*/ | ||
protected function purgeFilesInDir(string $dir): void { | ||
$fs = new Filesystem(); | ||
$finder = new Finder(); | ||
if ($fs->exists($dir)) { | ||
$fs->remove($finder->files()->in($dir)); | ||
} | ||
} | ||
|
||
/** | ||
* Remove files in directory. | ||
* | ||
* @param string $dir | ||
* Directory to purge files in. | ||
*/ | ||
protected function purgeFilesInDir(string $dir): void | ||
{ | ||
$fs = new Filesystem(); | ||
$finder = new Finder(); | ||
if ($fs->exists($dir)) { | ||
$fs->remove($finder->files()->in($dir)); | ||
} | ||
/** | ||
* Resolve directory using one of supported paths. | ||
* | ||
* @return string | ||
* Path to the screenshots directory. | ||
*/ | ||
protected function resolveScreenshotDir(): string { | ||
$dir = getenv('BEHAT_SCREENSHOT_DIR'); | ||
if (!empty($dir)) { | ||
return $dir; | ||
} | ||
|
||
/** | ||
* Resolve directory using one of supported paths. | ||
* | ||
* @return string | ||
* Path to the screenshots directory. | ||
*/ | ||
protected function resolveScreenshotDir(): string | ||
{ | ||
$dir = getenv('BEHAT_SCREENSHOT_DIR'); | ||
if (!empty($dir)) { | ||
return $dir; | ||
} | ||
return $this->dir; | ||
} | ||
|
||
return $this->dir; | ||
} | ||
/** | ||
* Decide if 'purge' flag was set. | ||
* | ||
* @return bool | ||
* TRUE if should purge, FALSE otherwise. | ||
*/ | ||
protected function shouldPurge(): bool { | ||
return getenv('BEHAT_SCREENSHOT_PURGE') || $this->purge; | ||
} | ||
|
||
/** | ||
* Decide if 'purge' flag was set. | ||
* | ||
* @return bool | ||
* TRUE if should purge, FALSE otherwise. | ||
*/ | ||
protected function shouldPurge(): bool | ||
{ | ||
return getenv('BEHAT_SCREENSHOT_PURGE') || $this->purge; | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
src/DrevOps/BehatScreenshotExtension/Context/ScreenshotAwareContext.php
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
src/DrevOps/BehatScreenshotExtension/Context/ScreenshotAwareContextInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace DrevOps\BehatScreenshotExtension\Context; | ||
|
||
use Behat\Behat\Context\Context; | ||
|
||
/** | ||
* Interface ScreenshotContext. | ||
*/ | ||
interface ScreenshotAwareContextInterface extends Context { | ||
|
||
/** | ||
* Set context parameters. | ||
* | ||
* @param string $dir | ||
* Directory to store screenshots. | ||
* @param bool $fail | ||
* Create screenshots on fail. | ||
* @param string $failPrefix | ||
* File name prefix for a failed test. | ||
* @param string $filenamePattern | ||
* File name pattern. | ||
* @param string $filenamePatternFailed | ||
* File name pattern failed. | ||
* | ||
* @return $this | ||
*/ | ||
public function setScreenshotParameters(string $dir, bool $fail, string $failPrefix, string $filenamePattern, string $filenamePatternFailed): static; | ||
|
||
} |
Oops, something went wrong.