forked from crschoen/FlexibleMink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce duplication via UsesFlexibleContext trait
Problem: Each context that wishes to access the FlexibleContext instance needs to implement gathersContexts. This causes duplication in the codebase, and even more so in projects that leverage Flexible Mink. Solution: I added a trait called UsesFlexibleContext that gathers the FlexibleContext instance and makes it available via the $this->flexibleContext property.
- Loading branch information
Showing
8 changed files
with
53 additions
and
166 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
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
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,38 @@ | ||
<?php namespace Medology\Behat\Mink; | ||
|
||
use Behat\Behat\Context\Environment\InitializedContextEnvironment; | ||
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | ||
use RuntimeException; | ||
|
||
/** | ||
* Trait that grants access to the FlexibleContext instance via $this->flexibleContext. | ||
*/ | ||
trait UsesFlexibleContext | ||
{ | ||
/** @var FlexibleContext */ | ||
protected $flexibleContext; | ||
|
||
/** | ||
* Gathers the FlexibleContext instance and stores a reference in $this->flexibleContext. | ||
* | ||
* @param BeforeScenarioScope $scope | ||
* @throws RuntimeException If the current environment is not initialized. | ||
* @return void | ||
* @BeforeScenario | ||
*/ | ||
public function gatherFlexibleContext(BeforeScenarioScope $scope) | ||
{ | ||
$environment = $scope->getEnvironment(); | ||
|
||
if (!($environment instanceof InitializedContextEnvironment)) { | ||
throw new RuntimeException( | ||
'Expected Environment to be ' . InitializedContextEnvironment::class . | ||
', but got ' . get_class($environment) | ||
); | ||
} | ||
|
||
if (!$this->flexibleContext = $environment->getContext(FlexibleContext::class)) { | ||
throw new RuntimeException('Failed to gather FlexibleContext'); | ||
} | ||
} | ||
} |
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