Skip to content

Commit e2019fb

Browse files
[auto-generated] Update plugin files
Check out the commits that caused these changes: moodlehq/moodleapp@6553d20...6ac81d1
1 parent 0da0421 commit e2019fb

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

tests/behat/behat_app.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require_once(__DIR__ . '/behat_app_helper.php');
2121

2222
use Behat\Behat\Hook\Scope\ScenarioScope;
23+
use Behat\Behat\Hook\Scope\AfterStepScope;
2324
use Behat\Gherkin\Node\TableNode;
2425
use Behat\Mink\Exception\DriverException;
2526
use Behat\Mink\Exception\ExpectationException;
@@ -44,7 +45,10 @@ class behat_app extends behat_app_helper {
4445
],
4546
];
4647

47-
protected $featurepath = '';
48+
protected $featurepath;
49+
protected $coveragepath;
50+
protected $scenarioslug;
51+
protected $scenariolaststep;
4852

4953
/**
5054
* @BeforeScenario
@@ -56,7 +60,35 @@ public function before_scenario(ScenarioScope $scope) {
5660
return;
5761
}
5862

63+
$steps = $scope->getScenario()->getSteps();
64+
65+
$this->scenarioslug = $this->get_scenario_slug($scope);
66+
$this->scenariolaststep = $steps[count($steps) - 1];
5967
$this->featurepath = dirname($feature->getFile());
68+
$this->coveragepath = get_config('local_moodleappbehat', 'coverage_path') ?: ($this->featurepath . DIRECTORY_SEPARATOR . 'coverage' . DIRECTORY_SEPARATOR);
69+
}
70+
71+
/**
72+
* @AfterStep
73+
*/
74+
public function after_step(AfterStepScope $scope) {
75+
$step = $scope->getStep();
76+
77+
if ($step !== $this->scenariolaststep || empty($this->coveragepath)) {
78+
return;
79+
}
80+
81+
if (!is_dir($this->coveragepath)) {
82+
if (!@mkdir($this->coveragepath, 0777, true)) {
83+
throw new Exception("Cannot create {$this->coveragepath} directory.");
84+
}
85+
}
86+
87+
$coverage = $this->runtime_js('getCoverage()');
88+
89+
if (!is_null($coverage)) {
90+
file_put_contents($this->coveragepath . $this->scenarioslug . '.json', $coverage);
91+
}
6092
}
6193

6294
/**

tests/behat/behat_app_helper.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
2020

21+
use Behat\Behat\Hook\Scope\ScenarioScope;
2122
use Behat\Mink\Exception\DriverException;
2223
use Behat\Mink\Exception\ExpectationException;
2324
use Moodle\BehatExtension\Exception\SkippedException;
@@ -357,7 +358,7 @@ protected function notify_unload(): void {
357358
* @return mixed Result.
358359
*/
359360
protected function runtime_js(string $script) {
360-
return $this->evaluate_script("window.behat.$script");
361+
return $this->evaluate_script("window.behat?.$script");
361362
}
362363

363364
/**
@@ -472,6 +473,22 @@ function($context) use ($successXPath) {
472473
$this->i_wait_the_app_to_restart();
473474
}
474475

476+
/**
477+
* Get scenario slug.
478+
*
479+
* @param ScenarioScope $scope Scenario scope.
480+
* @return string Slug.
481+
*/
482+
protected function get_scenario_slug(ScenarioScope $scope): string {
483+
$text = $scope->getFeature()->getTitle() . ' ' . $scope->getScenario()->getTitle();
484+
$text = trim($text);
485+
$text = strtolower($text);
486+
$text = preg_replace('/\s+/', '-', $text);
487+
$text = preg_replace('/[^a-z0-9-]/', '', $text);
488+
489+
return $text;
490+
}
491+
475492
/**
476493
* Returns the current mobile url scheme of the site.
477494
*/

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
defined('MOODLE_INTERNAL') || die;
88

9-
$plugin->version = 2024041700;
9+
$plugin->version = 2024051300;
1010
$plugin->requires = 2016052300;
1111
$plugin->maturity = MATURITY_STABLE;
1212
$plugin->release = '4.4.0';

0 commit comments

Comments
 (0)