-
-
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.
Converted Behat screenshot to extension.
- Loading branch information
1 parent
73b95ef
commit cd152dc
Showing
9 changed files
with
246 additions
and
108 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 |
---|---|---|
|
@@ -18,4 +18,3 @@ test: | |
override: | ||
- composer cs | ||
- composer test | ||
- BEHAT_SCREENSHOT_DIR=$CIRCLE_ARTIFACTS/behat composer test |
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
90 changes: 90 additions & 0 deletions
90
src/IntegratedExperts/Behat/Screenshot/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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* @file | ||
* This file is part of the IntegratedExperts\BehatScreenshot package. | ||
*/ | ||
|
||
namespace IntegratedExperts\Behat\Screenshot\Context\Initializer; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Behat\Behat\Context\Initializer\ContextInitializer; | ||
use IntegratedExperts\Behat\Screenshot\Context\ScreenshotContextInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
/** | ||
* Class ScreenshotContextInitializer | ||
*/ | ||
class ScreenshotContextInitializer implements ContextInitializer | ||
{ | ||
|
||
/** | ||
* Screenshot directory name. | ||
* | ||
* @var string | ||
*/ | ||
private $dir; | ||
|
||
/** | ||
* Makes screenshot when fail. | ||
* | ||
* @var bool | ||
*/ | ||
private $fail; | ||
|
||
/** | ||
* Purge dir before start test. | ||
* | ||
* @var bool | ||
*/ | ||
private $purge; | ||
|
||
/** | ||
* Does need to clear directory trigger. | ||
* | ||
* @var bool | ||
*/ | ||
private $toPurge; | ||
|
||
/** | ||
* ScreenshotContextInitializer constructor. | ||
* | ||
* @param string $dir Screenshot dir. | ||
* @param bool $fail Screenshot when fail. | ||
* @param bool $purge Purge dir before start script. | ||
*/ | ||
public function __construct($dir, $fail, $purge) | ||
{ | ||
$this->toPurge = true; | ||
$this->dir = $dir; | ||
$this->fail = $fail; | ||
$this->purge = $purge; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function initializeContext(Context $context) | ||
{ | ||
if ($context instanceof ScreenshotContextInterface) { | ||
$context->setParameters($this->dir, $this->fail); | ||
// Calling clearing screenshot directory function. | ||
if ($this->purge && $this->toPurge) { | ||
$this->purgeFilesInDir(); | ||
$this->toPurge = false; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Remove files in directory. | ||
*/ | ||
protected function purgeFilesInDir() | ||
{ | ||
$fs = new Filesystem(); | ||
$finder = new Finder(); | ||
if ($fs->exists($this->dir)) { | ||
$fs->remove($finder->files()->in($this->dir)); | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/IntegratedExperts/Behat/Screenshot/Context/ScreenshotContextInterface.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,27 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Behat context interface to enable Screenshot. | ||
*/ | ||
|
||
namespace IntegratedExperts\Behat\Screenshot\Context; | ||
|
||
use Behat\Behat\Context\Context; | ||
|
||
/** | ||
* Interface ScreenshotContext. | ||
*/ | ||
interface ScreenshotContextInterface extends Context | ||
{ | ||
|
||
/** | ||
* Set context parameters. | ||
* | ||
* @param string $dir | ||
* @param bool $fail | ||
* | ||
* @return $this | ||
*/ | ||
public function setParameters($dir, $fail); | ||
} |
Oops, something went wrong.