Chapters
23 Chapters
|
1:59:49
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: >=5.4.0, <7.3.0
Subscribe to download the code!Compatible PHP versions: >=5.4.0, <7.3.0
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
05.
Behat Hooks Background
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial uses a very old version of Symfony. The fundamentals of Behat are still valid, but integration with Symfony will be different.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=5.4.0, <7.3.0",
"symfony/symfony": "^2.7", // v2.7.4
"twig/twig": "^1.22", // v1.22.1
"sensio/framework-extra-bundle": "^3.0", // v3.0.16
"doctrine/doctrine-bundle": "^1.5", // v1.5.1
"doctrine/orm": "^2.5", // v2.5.1
"doctrine/doctrine-fixtures-bundle": "^2.2", // v2.2.1
"behat/symfony2-extension": "^2.0" // v2.0.0
},
"require-dev": {
"behat/mink-extension": "^2.0", // v2.0.1
"behat/mink-goutte-driver": "^1.1", // v1.1.0
"behat/mink-selenium2-driver": "^1.2", // v1.2.0
"phpunit/phpunit": "^4.8" // 4.8.18
}
}
13 Comments
You should really put some quotes around that
realpathcall, I got far too close to accidentally wiping something important because I have spaces in my pathThanks for your input on that. I agree with you, it's safer to do that, and as a reminder, do not run scripts as sudo :)
Cheers!
Hey,
do you know why
//Works
if (is_dir('test')){
system('rm -r '.realpath('test'));
}
works but
//Don't work
if (is_dir('test')){
system('rm -r'.realpath('test'));
}
not? The difference is, there is a space between -r and '. Works -> 'rm -r ' | Don't work 'rm -r' This is strange.
Hi Florian!
Ah, it's because system() ultimately runs a command-line script. If you think about it, the two commands would be:
If there's no space, the -r flag "runs into" the path :).
Cheers!
Not sure where is the best place to ask this - maybe here?
I am using @insulated tag for scenarios that run mink-selenium tests on SauceLabs, and SauceLabs creates a separate set of screenshots/video for each scenario. I have code that gets the URL of the SauceLabs job output and can write that to the log in the @AfterScenario - all good, I can look in the log for the inidividual link to the SauceLabs output for each scenario.
I can also send the pass-fail status of the scenario to SauceLabs (they have an API for that).
Is there some way, inside an AfterScenario method, to get the pass/fail status of the scenario?
I just needed to look - scenario scopes have getTestResult which has isPassed()
/**
* After Scenario. Report the pass/fail status.
*
* @return void
* @AfterScenario
*/
public function reportResult(\Behat\Behat\Hook\Scope\AfterScenarioScope $afterScenarioScope) {
if ($afterScenarioScope->getTestResult()->isPassed()) {
$passOrFail = "pass";
$passed = "true";
} else {
$passOrFail = "fail";
$passed = "false";
}
$jobId = $this->getSessionId();
$sauceUsername = getenv('SAUCE_USERNAME');
$sauceAccessKey = getenv('SAUCE_ACCESS_KEY');
if ($sauceUsername && $sauceAccessKey) {
error_log("SAUCELABS RESULT: ($passOrFail) https://saucelabs.com/jobs/...");
exec('curl -X PUT -s -d "{\"passed\": ' . $passed . '}" -u ' . $sauceUsername . ':' . $sauceAccessKey . ' https://saucelabs.com/rest/... . $jobId);
}
}
Haha, awesome - thanks for sharing the solution Phil! :)
is there a way to use the "use" sentence and avoid the "include_once"? it just feels ugly. what I should add to the featureContext class if I want to test an API using Guzzle?
Hey Daniel!
Inside FeatureContext, you *do* have access to any of your normal classes (e.g. anything in the vendor directory, etc). So, you should be able to use Guzzle without needing any require statements - and actually, we do this in the REST tutorial (http://knpuniversity.com/sc... or https://github.com/knpunive... to see usage - though this is an older version of Guzzle now).
We added the require_once in this case to get the PHPUnit *functions* - as function autoloading is a bit different. However, this may not be needed anymore even for functions - I believe PHPUnit takes care of autoloading these automatically now as well.
I hope that helps!
P.S. Sorry for the slow reply!
Cool! this is getting more amazing!
P.S. it's okay as long you were working on this https://events.drupal.org/n... or this https://events.drupal.org/n...
Haha, let's say I was ;). Will you be there?
Yes! First DrupalCon ever :)
Awesome! DrupalCon is one of my absolute favorite conferences - incredibly well-run and great people. See you there!
"Houston: no signs of life"
Start the conversation!