PHP code example of gorghoa / scenariostate-behat-extension
1. Go to this page and download the library: Download gorghoa/scenariostate-behat-extension library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gorghoa / scenariostate-behat-extension example snippets
use Gorghoa\ScenarioStateBehatExtension\Context\ScenarioStateAwareContext;
use Gorghoa\ScenarioStateBehatExtension\Context\ScenarioStateAwareTrait;
use Gorghoa\ScenarioStateBehatExtension\ScenarioStateInterface;
class FeatureContext implements ScenarioStateAwareContext
{
use ScenarioStateAwareTrait;
}
/**
* @When bonobo takes a banana
*/
public function takeBanana()
{
$banana = 'Yammy Banana';
$bonobo = new Bonobo('Gerard');
// Here, the banana `Yammy Banana` is shared amongst steps through the key "scenarioBanana"
$this->scenarioState->provideStateFragment('scenarioBanana', $banana);
// Here, the bonobo Gerard is shared amongst steps through the key "scenarioBonobo"
$this->scenarioState->provideStateFragment('scenarioBonobo', $bonobo);
}
use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument;
/**
* @When bonobo gives this banana to :monkey
*
* @ScenarioStateArgument("scenarioBanana")
* @ScenarioStateArgument(name="scenarioBonobo", argument="bonobo")
*
* @param string $monkey
* @param string $scenarioBanana
* @param Bonobo $bonobo
*/
public function giveBananaToGorilla($monkey, $scenarioBanana, Bonobo $bonobo)
{
// (note that PHPUnit is here only given as an example, feel free to use any asserter you want)
\PHPUnit_Framework_Assert::assertEquals($monkey, 'gorilla');
\PHPUnit_Framework_Assert::assertEquals($scenarioBanana, 'Yammy Banana');
\PHPUnit_Framework_Assert::assertEquals($bonobo->getName(), 'Gerard');
}
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument;
/**
* @BeforeScenario
*
* @ScenarioStateArgument("scenarioBanana")
*
* @param string $scenarioBanana
* @param BeforeScenarioScope $scope
*/
public function checkBananaBeforeScenario($scenarioBanana, BeforeScenarioScope $scope)
{
// (note that PHPUnit is here only given as an example, feel free to use any asserter you want)
\PHPUnit_Framework_Assert::assertEquals($scenarioBanana, 'Yammy Banana');
\PHPUnit_Framework_Assert::assertNotNull($scope);
}
/**
* @AfterScenario
*
* @ScenarioStateArgument("scenarioBanana")
*
* @param string $scenarioBanana
* @param AfterScenarioScope $scope
*/
public function checkBananaAfterScenario($scenarioBanana, AfterScenarioScope $scope)
{
// (note that PHPUnit is here only given as an example, feel free to use any asserter you want)
\PHPUnit_Framework_Assert::assertEquals($scenarioBanana, 'Yammy Banana');
\PHPUnit_Framework_Assert::assertNotNull($scope);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.