MDL-73272 behat: move behat extension to core

This commit is contained in:
Petr Skoda
2021-12-31 09:46:30 +13:00
parent 504f784ae6
commit 99c49bb067
29 changed files with 3089 additions and 173 deletions
+1
View File
@@ -19,6 +19,7 @@ lib/editor/tinymce/plugins/spellchecker/rpc.php
lib/editor/tinymce/tiny_mce/
lib/mlbackend/php/phpml/
lib/adodb/
lib/behat/extension/
lib/bennu/
lib/evalmath/
lib/phpspreadsheet/
+1
View File
@@ -20,6 +20,7 @@ lib/editor/tinymce/plugins/spellchecker/rpc.php
lib/editor/tinymce/tiny_mce/
lib/mlbackend/php/phpml/
lib/adodb/
lib/behat/extension/
lib/bennu/
lib/evalmath/
lib/phpspreadsheet/
+12 -2
View File
@@ -7,8 +7,18 @@
"require-dev": {
"phpunit/phpunit": "7.5.*",
"phpunit/dbunit": "4.0.*",
"moodlehq/behat-extension": "3.39.6",
"mikey179/vfsstream": "^1.6"
"mikey179/vfsstream": "^1.6",
"behat/mink": "~1.8",
"behat/mink-extension": "~2.3",
"behat/mink-goutte-driver": "~1.2",
"symfony/process": "^4.0 || ^5.0",
"behat/behat": "3.8.*",
"oleg-andreyev/mink-phpwebdriver": "^1.0"
},
"autoload-dev": {
"psr-0": {
"Moodle\\BehatExtension": "lib/behat/extension/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
Generated
+409 -171
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "88295d5900d8704c90004c83f18613dd",
"content-hash": "5c6a2c41632a31d8d425c71c80f92f41",
"packages": [],
"packages-dev": [
{
@@ -897,64 +897,6 @@
},
"time": "2021-09-25T08:05:01+00:00"
},
{
"name": "moodlehq/behat-extension",
"version": "v3.39.6",
"source": {
"type": "git",
"url": "https://github.com/moodlehq/moodle-behat-extension.git",
"reference": "f1a76db33decdc1b367c58b250a1ab214b08388f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/moodlehq/moodle-behat-extension/zipball/f1a76db33decdc1b367c58b250a1ab214b08388f",
"reference": "f1a76db33decdc1b367c58b250a1ab214b08388f",
"shasum": ""
},
"require": {
"behat/behat": "3.8.*",
"behat/mink": "~1.8",
"behat/mink-extension": "~2.3",
"behat/mink-goutte-driver": "~1.2",
"oleg-andreyev/mink-phpwebdriver": "^1.0",
"php": ">=7.2.0",
"symfony/process": "^4.0 || ^5.0"
},
"type": "library",
"autoload": {
"psr-0": {
"Moodle\\BehatExtension": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0-or-later"
],
"authors": [
{
"name": "David Monllaó",
"email": "[email protected]",
"homepage": "http://moodle.com",
"role": "Developer"
},
{
"name": "Andrew Nicols",
"email": "[email protected]",
"homepage": "http://moodle.com",
"role": "Developer"
}
],
"description": "Moodle behat extension",
"keywords": [
"BDD",
"Behat",
"moodle"
],
"support": {
"source": "https://github.com/moodlehq/moodle-behat-extension/tree/v3.39.6"
},
"time": "2021-02-15T09:07:03+00:00"
},
{
"name": "myclabs/deep-copy",
"version": "1.10.2",
@@ -972,9 +914,6 @@
"require": {
"php": "^7.1 || ^8.0"
},
"replace": {
"myclabs/deep-copy": "self.version"
},
"require-dev": {
"doctrine/collections": "^1.0",
"doctrine/common": "^2.6",
@@ -1963,6 +1902,56 @@
},
"time": "2021-03-05T17:36:06+00:00"
},
{
"name": "psr/event-dispatcher",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/event-dispatcher.git",
"reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0",
"reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0",
"shasum": ""
},
"require": {
"php": ">=7.2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\EventDispatcher\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Standard interfaces for event handling.",
"keywords": [
"events",
"psr",
"psr-14"
],
"support": {
"issues": "https://github.com/php-fig/event-dispatcher/issues",
"source": "https://github.com/php-fig/event-dispatcher/tree/1.0.0"
},
"time": "2019-01-08T18:20:26+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
@@ -2798,16 +2787,16 @@
},
{
"name": "symfony/config",
"version": "v4.4.34",
"version": "v4.4.36",
"source": {
"type": "git",
"url": "https://github.com/symfony/config.git",
"reference": "e99b65a18faa34fde57078095c39a1bc91a22492"
"reference": "03218ffbd5faeda5e6a97f9109acebf7973ff385"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/config/zipball/e99b65a18faa34fde57078095c39a1bc91a22492",
"reference": "e99b65a18faa34fde57078095c39a1bc91a22492",
"url": "https://api.github.com/repos/symfony/config/zipball/03218ffbd5faeda5e6a97f9109acebf7973ff385",
"reference": "03218ffbd5faeda5e6a97f9109acebf7973ff385",
"shasum": ""
},
"require": {
@@ -2856,7 +2845,7 @@
"description": "Helps you find, load, combine, autofill and validate configuration values of any kind",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/config/tree/v4.4.34"
"source": "https://github.com/symfony/config/tree/v4.4.36"
},
"funding": [
{
@@ -2872,47 +2861,50 @@
"type": "tidelift"
}
],
"time": "2021-10-29T15:43:26+00:00"
"time": "2021-12-12T15:06:47+00:00"
},
{
"name": "symfony/console",
"version": "v4.4.34",
"version": "v5.4.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "329b3a75cc6b16d435ba1b1a41df54a53382a3f0"
"reference": "a2c6b7ced2eb7799a35375fb9022519282b5405e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/329b3a75cc6b16d435ba1b1a41df54a53382a3f0",
"reference": "329b3a75cc6b16d435ba1b1a41df54a53382a3f0",
"url": "https://api.github.com/repos/symfony/console/zipball/a2c6b7ced2eb7799a35375fb9022519282b5405e",
"reference": "a2c6b7ced2eb7799a35375fb9022519282b5405e",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1|^3",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php73": "^1.8",
"symfony/polyfill-php73": "^1.9",
"symfony/polyfill-php80": "^1.16",
"symfony/service-contracts": "^1.1|^2"
"symfony/service-contracts": "^1.1|^2|^3",
"symfony/string": "^5.1|^6.0"
},
"conflict": {
"psr/log": ">=3",
"symfony/dependency-injection": "<3.4",
"symfony/event-dispatcher": "<4.3|>=5",
"symfony/dependency-injection": "<4.4",
"symfony/dotenv": "<5.1",
"symfony/event-dispatcher": "<4.4",
"symfony/lock": "<4.4",
"symfony/process": "<3.3"
"symfony/process": "<4.4"
},
"provide": {
"psr/log-implementation": "1.0|2.0"
},
"require-dev": {
"psr/log": "^1|^2",
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
"symfony/event-dispatcher": "^4.3",
"symfony/lock": "^4.4|^5.0",
"symfony/process": "^3.4|^4.0|^5.0",
"symfony/var-dumper": "^4.3|^5.0"
"symfony/config": "^4.4|^5.0|^6.0",
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
"symfony/event-dispatcher": "^4.4|^5.0|^6.0",
"symfony/lock": "^4.4|^5.0|^6.0",
"symfony/process": "^4.4|^5.0|^6.0",
"symfony/var-dumper": "^4.4|^5.0|^6.0"
},
"suggest": {
"psr/log": "For using the console logger",
@@ -2945,8 +2937,14 @@
],
"description": "Eases the creation of beautiful and testable command line interfaces",
"homepage": "https://symfony.com",
"keywords": [
"cli",
"command line",
"console",
"terminal"
],
"support": {
"source": "https://github.com/symfony/console/tree/v4.4.34"
"source": "https://github.com/symfony/console/tree/v5.4.2"
},
"funding": [
{
@@ -2962,24 +2960,24 @@
"type": "tidelift"
}
],
"time": "2021-11-04T12:23:33+00:00"
"time": "2021-12-20T16:11:12+00:00"
},
{
"name": "symfony/css-selector",
"version": "v4.4.27",
"version": "v5.4.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
"reference": "5194f18bd80d106f11efa8f7cd0fbdcc3af96ce6"
"reference": "cfcbee910e159df402603502fe387e8b677c22fd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/5194f18bd80d106f11efa8f7cd0fbdcc3af96ce6",
"reference": "5194f18bd80d106f11efa8f7cd0fbdcc3af96ce6",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/cfcbee910e159df402603502fe387e8b677c22fd",
"reference": "cfcbee910e159df402603502fe387e8b677c22fd",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"php": ">=7.2.5",
"symfony/polyfill-php80": "^1.16"
},
"type": "library",
@@ -3012,7 +3010,7 @@
"description": "Converts CSS selectors to XPath expressions",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/css-selector/tree/v4.4.27"
"source": "https://github.com/symfony/css-selector/tree/v5.4.2"
},
"funding": [
{
@@ -3028,20 +3026,20 @@
"type": "tidelift"
}
],
"time": "2021-07-21T12:19:41+00:00"
"time": "2021-12-16T21:58:21+00:00"
},
{
"name": "symfony/dependency-injection",
"version": "v4.4.34",
"version": "v4.4.36",
"source": {
"type": "git",
"url": "https://github.com/symfony/dependency-injection.git",
"reference": "117d7f132ed7efbd535ec947709d49bec1b9d24b"
"reference": "24e802b4973d3a60c01fd77bdaac8a66944202e1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dependency-injection/zipball/117d7f132ed7efbd535ec947709d49bec1b9d24b",
"reference": "117d7f132ed7efbd535ec947709d49bec1b9d24b",
"url": "https://api.github.com/repos/symfony/dependency-injection/zipball/24e802b4973d3a60c01fd77bdaac8a66944202e1",
"reference": "24e802b4973d3a60c01fd77bdaac8a66944202e1",
"shasum": ""
},
"require": {
@@ -3098,7 +3096,7 @@
"description": "Allows you to standardize and centralize the way objects are constructed in your application",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/dependency-injection/tree/v4.4.34"
"source": "https://github.com/symfony/dependency-injection/tree/v4.4.36"
},
"funding": [
{
@@ -3114,20 +3112,87 @@
"type": "tidelift"
}
],
"time": "2021-11-15T14:42:25+00:00"
"time": "2021-12-29T10:03:29+00:00"
},
{
"name": "symfony/dom-crawler",
"version": "v4.4.30",
"name": "symfony/deprecation-contracts",
"version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
"reference": "4632ae3567746c7e915c33c67a2fb6ab746090c4"
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/4632ae3567746c7e915c33c67a2fb6ab746090c4",
"reference": "4632ae3567746c7e915c33c67a2fb6ab746090c4",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/6f981ee24cf69ee7ce9736146d1c57c2780598a8",
"reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "2.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": {
"files": [
"function.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "[email protected]"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-07-12T14:48:14+00:00"
},
{
"name": "symfony/dom-crawler",
"version": "v4.4.36",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
"reference": "42de12bee3b5e594977209bcdf58ec4fef8dde39"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/42de12bee3b5e594977209bcdf58ec4fef8dde39",
"reference": "42de12bee3b5e594977209bcdf58ec4fef8dde39",
"shasum": ""
},
"require": {
@@ -3172,7 +3237,7 @@
"description": "Eases DOM navigation for HTML and XML documents",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/dom-crawler/tree/v4.4.30"
"source": "https://github.com/symfony/dom-crawler/tree/v4.4.36"
},
"funding": [
{
@@ -3188,43 +3253,44 @@
"type": "tidelift"
}
],
"time": "2021-08-28T15:40:01+00:00"
"time": "2021-12-28T14:48:02+00:00"
},
{
"name": "symfony/event-dispatcher",
"version": "v4.4.34",
"version": "v5.4.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "1a024b45369c9d55d76b6b8a241bd20c9ea1cbd8"
"reference": "27d39ae126352b9fa3be5e196ccf4617897be3eb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/1a024b45369c9d55d76b6b8a241bd20c9ea1cbd8",
"reference": "1a024b45369c9d55d76b6b8a241bd20c9ea1cbd8",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/27d39ae126352b9fa3be5e196ccf4617897be3eb",
"reference": "27d39ae126352b9fa3be5e196ccf4617897be3eb",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"symfony/event-dispatcher-contracts": "^1.1",
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1|^3",
"symfony/event-dispatcher-contracts": "^2|^3",
"symfony/polyfill-php80": "^1.16"
},
"conflict": {
"symfony/dependency-injection": "<3.4"
"symfony/dependency-injection": "<4.4"
},
"provide": {
"psr/event-dispatcher-implementation": "1.0",
"symfony/event-dispatcher-implementation": "1.1"
"symfony/event-dispatcher-implementation": "2.0"
},
"require-dev": {
"psr/log": "^1|^2|^3",
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
"symfony/error-handler": "~3.4|~4.4",
"symfony/expression-language": "^3.4|^4.0|^5.0",
"symfony/http-foundation": "^3.4|^4.0|^5.0",
"symfony/service-contracts": "^1.1|^2",
"symfony/stopwatch": "^3.4|^4.0|^5.0"
"symfony/config": "^4.4|^5.0|^6.0",
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
"symfony/error-handler": "^4.4|^5.0|^6.0",
"symfony/expression-language": "^4.4|^5.0|^6.0",
"symfony/http-foundation": "^4.4|^5.0|^6.0",
"symfony/service-contracts": "^1.1|^2|^3",
"symfony/stopwatch": "^4.4|^5.0|^6.0"
},
"suggest": {
"symfony/dependency-injection": "",
@@ -3256,7 +3322,7 @@
"description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/event-dispatcher/tree/v4.4.34"
"source": "https://github.com/symfony/event-dispatcher/tree/v5.4.0"
},
"funding": [
{
@@ -3272,33 +3338,33 @@
"type": "tidelift"
}
],
"time": "2021-11-15T14:42:25+00:00"
"time": "2021-11-23T10:19:22+00:00"
},
{
"name": "symfony/event-dispatcher-contracts",
"version": "v1.1.11",
"version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher-contracts.git",
"reference": "01e9a4efac0ee33a05dfdf93b346f62e7d0e998c"
"reference": "66bea3b09be61613cd3b4043a65a8ec48cfa6d2a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/01e9a4efac0ee33a05dfdf93b346f62e7d0e998c",
"reference": "01e9a4efac0ee33a05dfdf93b346f62e7d0e998c",
"url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/66bea3b09be61613cd3b4043a65a8ec48cfa6d2a",
"reference": "66bea3b09be61613cd3b4043a65a8ec48cfa6d2a",
"shasum": ""
},
"require": {
"php": ">=7.1.3"
"php": ">=7.2.5",
"psr/event-dispatcher": "^1"
},
"suggest": {
"psr/event-dispatcher": "",
"symfony/event-dispatcher-implementation": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.1-dev"
"dev-main": "2.5-dev"
},
"thanks": {
"name": "symfony/contracts",
@@ -3335,7 +3401,7 @@
"standards"
],
"support": {
"source": "https://github.com/symfony/event-dispatcher-contracts/tree/v1.1.11"
"source": "https://github.com/symfony/event-dispatcher-contracts/tree/v2.5.0"
},
"funding": [
{
@@ -3351,25 +3417,26 @@
"type": "tidelift"
}
],
"time": "2021-03-23T15:25:38+00:00"
"time": "2021-07-12T14:48:14+00:00"
},
{
"name": "symfony/filesystem",
"version": "v4.4.27",
"version": "v5.4.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "517fb795794faf29086a77d99eb8f35e457837a7"
"reference": "731f917dc31edcffec2c6a777f3698c33bea8f01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/517fb795794faf29086a77d99eb8f35e457837a7",
"reference": "517fb795794faf29086a77d99eb8f35e457837a7",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/731f917dc31edcffec2c6a777f3698c33bea8f01",
"reference": "731f917dc31edcffec2c6a777f3698c33bea8f01",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"php": ">=7.2.5",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.8",
"symfony/polyfill-php80": "^1.16"
},
"type": "library",
@@ -3398,7 +3465,7 @@
"description": "Provides basic utilities for the filesystem",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/filesystem/tree/v4.4.27"
"source": "https://github.com/symfony/filesystem/tree/v5.4.0"
},
"funding": [
{
@@ -3414,7 +3481,7 @@
"type": "tidelift"
}
],
"time": "2021-07-21T12:19:41+00:00"
"time": "2021-10-28T13:39:27+00:00"
},
{
"name": "symfony/polyfill-ctype",
@@ -3495,6 +3562,87 @@
],
"time": "2021-02-19T12:13:01+00:00"
},
{
"name": "symfony/polyfill-intl-grapheme",
"version": "v1.23.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
"reference": "16880ba9c5ebe3642d1995ab866db29270b36535"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/16880ba9c5ebe3642d1995ab866db29270b36535",
"reference": "16880ba9c5ebe3642d1995ab866db29270b36535",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"suggest": {
"ext-intl": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.23-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Intl\\Grapheme\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "[email protected]"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for intl's grapheme_* functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"grapheme",
"intl",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.23.1"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-05-27T12:26:48+00:00"
},
{
"name": "symfony/polyfill-intl-idn",
"version": "v1.23.0",
@@ -4065,20 +4213,20 @@
},
{
"name": "symfony/process",
"version": "v4.4.35",
"version": "v5.4.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "c2098705326addae6e6742151dfade47ac71da1b"
"reference": "2b3ba8722c4aaf3e88011be5e7f48710088fb5e4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/c2098705326addae6e6742151dfade47ac71da1b",
"reference": "c2098705326addae6e6742151dfade47ac71da1b",
"url": "https://api.github.com/repos/symfony/process/zipball/2b3ba8722c4aaf3e88011be5e7f48710088fb5e4",
"reference": "2b3ba8722c4aaf3e88011be5e7f48710088fb5e4",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"php": ">=7.2.5",
"symfony/polyfill-php80": "^1.16"
},
"type": "library",
@@ -4107,7 +4255,7 @@
"description": "Executes commands in sub-processes",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/process/tree/v4.4.35"
"source": "https://github.com/symfony/process/tree/v5.4.2"
},
"funding": [
{
@@ -4123,25 +4271,29 @@
"type": "tidelift"
}
],
"time": "2021-11-22T22:36:24+00:00"
"time": "2021-12-27T21:01:00+00:00"
},
{
"name": "symfony/service-contracts",
"version": "v1.1.11",
"version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/service-contracts.git",
"reference": "633df678bec3452e04a7b0337c9bcfe7354124b3"
"reference": "1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/service-contracts/zipball/633df678bec3452e04a7b0337c9bcfe7354124b3",
"reference": "633df678bec3452e04a7b0337c9bcfe7354124b3",
"url": "https://api.github.com/repos/symfony/service-contracts/zipball/1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc",
"reference": "1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"psr/container": "^1.0"
"php": ">=7.2.5",
"psr/container": "^1.1",
"symfony/deprecation-contracts": "^2.1"
},
"conflict": {
"ext-psr": "<1.1|>=2"
},
"suggest": {
"symfony/service-implementation": ""
@@ -4149,7 +4301,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.1-dev"
"dev-main": "2.5-dev"
},
"thanks": {
"name": "symfony/contracts",
@@ -4186,7 +4338,7 @@
"standards"
],
"support": {
"source": "https://github.com/symfony/service-contracts/tree/v1.1.11"
"source": "https://github.com/symfony/service-contracts/tree/v2.5.0"
},
"funding": [
{
@@ -4202,7 +4354,93 @@
"type": "tidelift"
}
],
"time": "2021-11-04T13:32:43+00:00"
"time": "2021-11-04T16:48:04+00:00"
},
{
"name": "symfony/string",
"version": "v5.4.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
"reference": "e6a5d5ecf6589c5247d18e0e74e30b11dfd51a3d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/e6a5d5ecf6589c5247d18e0e74e30b11dfd51a3d",
"reference": "e6a5d5ecf6589c5247d18e0e74e30b11dfd51a3d",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-intl-grapheme": "~1.0",
"symfony/polyfill-intl-normalizer": "~1.0",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "~1.15"
},
"conflict": {
"symfony/translation-contracts": ">=3.0"
},
"require-dev": {
"symfony/error-handler": "^4.4|^5.0|^6.0",
"symfony/http-client": "^4.4|^5.0|^6.0",
"symfony/translation-contracts": "^1.1|^2",
"symfony/var-exporter": "^4.4|^5.0|^6.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\String\\": ""
},
"files": [
"Resources/functions.php"
],
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "[email protected]"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way",
"homepage": "https://symfony.com",
"keywords": [
"grapheme",
"i18n",
"string",
"unicode",
"utf-8",
"utf8"
],
"support": {
"source": "https://github.com/symfony/string/tree/v5.4.2"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-12-16T21:52:00+00:00"
},
{
"name": "symfony/translation",
@@ -4295,20 +4533,20 @@
},
{
"name": "symfony/translation-contracts",
"version": "v1.1.11",
"version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/translation-contracts.git",
"reference": "58ae23095ffdea045725dda70752566aa2908be6"
"reference": "d28150f0f44ce854e942b671fc2620a98aae1b1e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/translation-contracts/zipball/58ae23095ffdea045725dda70752566aa2908be6",
"reference": "58ae23095ffdea045725dda70752566aa2908be6",
"url": "https://api.github.com/repos/symfony/translation-contracts/zipball/d28150f0f44ce854e942b671fc2620a98aae1b1e",
"reference": "d28150f0f44ce854e942b671fc2620a98aae1b1e",
"shasum": ""
},
"require": {
"php": ">=7.1.3"
"php": ">=7.2.5"
},
"suggest": {
"symfony/translation-implementation": ""
@@ -4316,7 +4554,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.1-dev"
"dev-main": "2.5-dev"
},
"thanks": {
"name": "symfony/contracts",
@@ -4353,7 +4591,7 @@
"standards"
],
"support": {
"source": "https://github.com/symfony/translation-contracts/tree/v1.1.11"
"source": "https://github.com/symfony/translation-contracts/tree/v2.5.0"
},
"funding": [
{
@@ -4369,20 +4607,20 @@
"type": "tidelift"
}
],
"time": "2021-07-13T10:01:39+00:00"
"time": "2021-08-17T14:20:01+00:00"
},
{
"name": "symfony/yaml",
"version": "v4.4.34",
"version": "v4.4.36",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "2c309e258adeb9970229042be39b360d34986fad"
"reference": "a19f7c44ba665fa9d9d415cc4493361381b93f9b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/2c309e258adeb9970229042be39b360d34986fad",
"reference": "2c309e258adeb9970229042be39b360d34986fad",
"url": "https://api.github.com/repos/symfony/yaml/zipball/a19f7c44ba665fa9d9d415cc4493361381b93f9b",
"reference": "a19f7c44ba665fa9d9d415cc4493361381b93f9b",
"shasum": ""
},
"require": {
@@ -4424,7 +4662,7 @@
"description": "Loads and dumps YAML files",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/yaml/tree/v4.4.34"
"source": "https://github.com/symfony/yaml/tree/v4.4.36"
},
"funding": [
{
@@ -4440,7 +4678,7 @@
"type": "tidelift"
}
],
"time": "2021-11-18T18:49:23+00:00"
"time": "2021-11-25T16:40:00+00:00"
},
{
"name": "theseer/tokenizer",
@@ -4578,5 +4816,5 @@
"ext-fileinfo": "*"
},
"platform-dev": [],
"plugin-api-version": "2.1.0"
"plugin-api-version": "2.2.0"
}
@@ -0,0 +1,83 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Moodle behat context class resolver.
*
* @package behat
* @copyright 2104 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Context\ContextClass;
use Behat\Behat\Context\Environment\Handler\ContextEnvironmentHandler;
use Behat\Behat\Context\ContextClass\ClassResolver as Resolver;
/**
* Resolves arbitrary context strings into a context classes.
*
* @see ContextEnvironmentHandler
*
* @author Konstantin Kudryashov <[email protected]>
*/
final class ClassResolver implements Resolver {
/**
* @var array keep list of all behat contexts in moodle.
*/
private $moodlebehatcontexts = null;
/**
* @param $parameters array list of params provided to moodle.
*/
public function __construct($parameters) {
$this->moodlebehatcontexts = $parameters['steps_definitions'];
}
/**
* Checks if resolvers supports provided class.
* Moodle behat context class starts with behat_
*
* @param string $contextString
*
* @return Boolean
*/
public function supportsClass($contextString) {
return (strpos($contextString, 'behat_') === 0);
}
/**
* Resolves context class.
*
* @param string $contexclass
*
* @return string context class.
*/
public function resolveClass($contextclass) {
if (!is_array($this->moodlebehatcontexts)) {
throw new \RuntimeException('There are no Moodle context with steps definitions');
}
// Using the key as context identifier load context class.
if (!empty($this->moodlebehatcontexts[$contextclass]) &&
(file_exists($this->moodlebehatcontexts[$contextclass]))) {
require_once($this->moodlebehatcontexts[$contextclass]);
} else {
throw new \RuntimeException('Moodle behat context "'.$contextclass.'" not found');
}
return $contextclass;
}
}
@@ -0,0 +1,41 @@
<?php
namespace Moodle\BehatExtension\Context\Initializer;
use Moodle\BehatExtension\Context\MoodleContext;
use Behat\Behat\Context\Initializer\ContextInitializer;
use Behat\Behat\Context\Context;
/**
* MoodleContext initializer
*
* @author David Monllaó <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleAwareInitializer implements ContextInitializer
{
private $parameters;
/**
* Initializes initializer.
*
* @param Mink $mink
* @param array $parameters
*/
public function __construct(array $parameters) {
$this->parameters = $parameters;
}
/**
* Initializes provided context.
*
* @param Context $context
*/
public function initializeContext(Context $context) {
if (method_exists($context, 'setMoodleConfig')) {
$context->setMoodleConfig($this->parameters);
}
}
}
@@ -0,0 +1,31 @@
<?php
namespace Moodle\BehatExtension\Context;
use Behat\MinkExtension\Context\RawMinkContext;
/**
* Moodle contexts loader
*
* It gathers all the available steps definitions reading the
* Moodle configuration file
*
* @copyright 2012 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleContext extends RawMinkContext {
/**
* Moodle features and steps definitions list
* @var array
*/
protected $moodleConfig;
/**
* Includes all the specified Moodle subcontexts
* @param array $parameters
*/
public function setMoodleConfig($parameters) {
$this->moodleConfig = $parameters;
}
}
@@ -0,0 +1,64 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Override step tester to ensure chained steps gets executed.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Context\Step;
use Behat\Gherkin\Node\StepNode;
/**
* Base ChainedStep class.
*/
abstract class ChainedStep extends StepNode {
/**
* @var string
*/
private $language;
/**
* Initializes ChainedStep.
*
* @param string $type
* @param string $text
* @param array $arguments
*/
public function __construct($keyword, $text, array $arguments, $line = 0, $keywordType = 'Given') {
parent::__construct($keyword, $text, $arguments, $line, $keywordType);
}
/**
* Sets language.
*
* @param string $language
*/
public function setLanguage($language) {
$this->language = $language;
}
/**
* Returns language.
*
* @return string
*/
public function getLanguage() {
return $this->language;
}
}
@@ -0,0 +1,38 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Override step tester to ensure chained steps gets executed.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Context\Step;
/**
* Given sub-step.
*/
class Given extends ChainedStep {
/**
* Initializes `Given` sub-step.
*/
public function __construct() {
$arguments = func_get_args();
$text = array_shift($arguments);
parent::__construct('Given', $text, $arguments);
}
}
@@ -0,0 +1,38 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Override step tester to ensure chained steps gets executed.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Context\Step;
/**
* `Then` ChainedStep.
*/
class Then extends ChainedStep {
/**
* Initializes `Then` sub-step.
*/
public function __construct() {
$arguments = func_get_args();
$text = array_shift($arguments);
parent::__construct('Then', $text, $arguments);
}
}
@@ -0,0 +1,37 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Override step tester to ensure chained steps gets executed.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Context\Step;
/**
* `When` ChainedStep.
*/
class When extends ChainedStep {
/**
* Initializes `When` sub-step.
*/
public function __construct() {
$arguments = func_get_args();
$text = array_shift($arguments);
parent::__construct('When', $text, $arguments);
}
}
@@ -0,0 +1,123 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace Moodle\BehatExtension\Definition\Cli;
use Behat\Behat\Definition\DefinitionWriter;
use Moodle\BehatExtension\Definition\Printer\ConsoleDefinitionInformationPrinter;
use Behat\Behat\Definition\Printer\ConsoleDefinitionListPrinter;
use Behat\Behat\Definition\Printer\DefinitionPrinter;
use Behat\Testwork\Cli\Controller;
use Behat\Testwork\Suite\SuiteRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Available definition controller, for calling moodle information printer.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class AvailableDefinitionsController implements Controller {
/**
* @var SuiteRepository
*/
private $suiteRepository;
/**
* @var DefinitionWriter
*/
private $writer;
/**
* @var ConsoleDefinitionListPrinter
*/
private $listPrinter;
/**
* @var ConsoleDefinitionInformationPrinter
*/
private $infoPrinter;
/**
* Initializes controller.
*
* @param SuiteRepository $suiteRepository
* @param DefinitionWriter $writer
* @param ConsoleDefinitionListPrinter $listPrinter
* @param ConsoleDefinitionInformationPrinter $infoPrinter
*/
public function __construct(
SuiteRepository $suiteRepository,
DefinitionWriter $writer,
ConsoleDefinitionListPrinter $listPrinter,
ConsoleDefinitionInformationPrinter $infoPrinter
) {
$this->suiteRepository = $suiteRepository;
$this->writer = $writer;
$this->listPrinter = $listPrinter;
$this->infoPrinter = $infoPrinter;
}
/**
* {@inheritdoc}
*/
public function configure(Command $command) {
$command->addOption('--definitions', '-d', InputOption::VALUE_REQUIRED,
"Print all available step definitions:" . PHP_EOL .
"- use <info>--definitions l</info> to just list definition expressions." . PHP_EOL .
"- use <info>--definitions i</info> to show definitions with extended info." . PHP_EOL .
"- use <info>--definitions 'needle'</info> to find specific definitions." . PHP_EOL .
"Use <info>--lang</info> to see definitions in specific language."
);
}
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output) {
if (null === $argument = $input->getOption('definitions')) {
return null;
}
$printer = $this->getDefinitionPrinter($argument);
foreach ($this->suiteRepository->getSuites() as $suite) {
$this->writer->printSuiteDefinitions($printer, $suite);
}
return 0;
}
/**
* Returns definition printer for provided option argument.
*
* @param string $argument
*
* @return DefinitionPrinter
*/
private function getDefinitionPrinter($argument) {
if ('l' === $argument) {
return $this->listPrinter;
}
if ('i' !== $argument) {
$this->infoPrinter->setSearchCriterion($argument);
}
return $this->infoPrinter;
}
}
@@ -0,0 +1,101 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace Moodle\BehatExtension\Definition\Printer;
use Behat\Behat\Definition\Definition;
use Behat\Testwork\Suite\Suite;
use Behat\Behat\Definition\Printer\ConsoleDefinitionPrinter;
/**
* Moodle console definition information printer.
* Used in moodle for definition printing.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class ConsoleDefinitionInformationPrinter extends ConsoleDefinitionPrinter {
/**
* @var null|string
*/
private $searchCriterion;
/**
* Sets search criterion.
*
* @param string $criterion
*/
public function setSearchCriterion($criterion) {
$this->searchCriterion = $criterion;
}
/**
* {@inheritdoc}
*/
public function printDefinitions(Suite $suite, $definitions) {
$template = <<<TPL
<div class="step"><div class="stepdescription">{description}</div>
<div class="stepcontent"><span class="steptype">{type}</span><span class="stepregex">{regex}</span></div>
<div class="stepapipath">{apipath}</div>
</div>
TPL;
$search = $this->searchCriterion;
// If there is a specific type (given, when or then) required.
if (strpos($search, '&&') !== false) {
list($search, $type) = explode('&&', $search);
}
foreach ($definitions as $definition) {
$definition = $this->translateDefinition($suite, $definition);
if (!empty($type) && strtolower($definition->getType()) != $type) {
continue;
}
$pattern = $definition->getPattern();
if ($search && !preg_match('/'.str_replace(' ', '.*', preg_quote($search, '/').'/'), $pattern)) {
continue;
}
$description = $definition->getDescription();
// Removing beginning and end.
$pattern = substr($pattern, 2, strlen($pattern) - 4);
// Replacing inline regex for expected info string.
$pattern = preg_replace_callback(
'/"\(\?P<([^>]*)>(.*?)"( |$)/',
function ($matches) {
return '"' . strtoupper($matches[1]) . '" ';
}, $pattern);
$definitiontoprint[] = strtr($template, array(
'{regex}' => $pattern,
'{type}' => str_pad($definition->getType(), 5, ' ', STR_PAD_LEFT),
'{description}' => $description ? $description : '',
'{apipath}' => $definition->getPath()
));
$this->write(implode("\n", $definitiontoprint));
unset($definitiontoprint);
}
}
}
@@ -0,0 +1,59 @@
<?php
namespace Moodle\BehatExtension\Driver;
use Behat\Mink\Session;
use OAndreyev\Mink\Driver\WebDriver as UpstreamDriver;
use WebDriver\Key as key;
/**
* WebDriver Driver to allow extra selenium capabilities required by Moodle.
*/
class WebDriver extends UpstreamDriver
{
/**
* Dirty attribute to get the browser name; $browserName is private
* @var string
*/
protected static $browser;
/**
* Instantiates the driver.
*
* @param string $browser Browser name
* @param array $desiredCapabilities The desired capabilities
* @param string $wdHost The WebDriver host
* @param array $moodleParameters Moodle parameters including our non-behat-friendly selenium capabilities
*/
public function __construct($browserName = 'chrome', $desiredCapabilities = null, $wdHost = 'http://localhost:4444/wd/hub', $moodleParameters = array()) {
parent::__construct($browserName, $desiredCapabilities, $wdHost);
// This class is instantiated by the dependencies injection system so
// prior to all of beforeSuite subscribers which will call getBrowser*()
self::$browser = $browserName;
}
/**
* Returns the browser being used.
*
* We need to know it:
* - To show info about the run.
* - In case there are differences between browsers in the steps.
*
* @static
* @return string
*/
public static function getBrowserName() {
return self::$browser;
}
/**
* Post key on specified xpath.
*
* @param string $xpath
*/
public function post_key($key, $xpath) {
throw new \Exception('No longer used - please use keyDown and keyUp');
}
}
@@ -0,0 +1,67 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Driver factory for the Moodle WebDriver.
*
* @package behat
* @copyright 2020 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Driver;
use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory;
use OAndreyev\Mink\Driver\WebDriverFactory as UpstreamFactory;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\Definition;
class WebDriverFactory extends UpstreamFactory implements DriverFactory {
/**
* {@inheritdoc}
*/
public function buildDriver(array $config)
{
// Merge capabilities
$extraCapabilities = $config['capabilities']['extra_capabilities'];
unset($config['capabilities']['extra_capabilities']);
// Ensure that the capabilites.browser is set correctly.
$config['capabilities']['browser'] = $config['browser'];
$capabilities = array_replace($this->guessCapabilities(), $extraCapabilities, $config['capabilities']);
// Build driver definition
return new Definition(WebDriver::class, [
$config['browser'],
$capabilities,
$config['wd_host'],
]);
}
/**
* {@inheritdoc}
*/
protected function getCapabilitiesNode()
{
$node = parent::getCapabilitiesNode();
// Specify chrome as the default browser.
$node->find('browser')->defaultValue('chrome');
return $node;
}
}
@@ -0,0 +1,263 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Override step tester to ensure chained steps gets executed.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\EventDispatcher\Tester;
use Behat\Behat\Tester\Result\ExecutedStepResult;
use Behat\Behat\Tester\Result\SkippedStepResult;
use Behat\Behat\Tester\Result\StepResult;
use Behat\Behat\Tester\StepTester;
use Behat\Behat\Tester\Result\UndefinedStepResult;
use Moodle\BehatExtension\Context\Step\Given;
use Moodle\BehatExtension\Context\Step\ChainedStep;
use Behat\Gherkin\Node\FeatureNode;
use Behat\Gherkin\Node\StepNode;
use Behat\Testwork\Call\CallResult;
use Behat\Testwork\Environment\Environment;
use Behat\Testwork\EventDispatcher\TestworkEventDispatcher;
use Behat\Behat\EventDispatcher\Event\AfterStepSetup;
use Behat\Behat\EventDispatcher\Event\AfterStepTested;
use Behat\Behat\EventDispatcher\Event\BeforeStepTeardown;
use Behat\Behat\EventDispatcher\Event\BeforeStepTested;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Moodle\BehatExtension\Exception\SkippedException;
/**
* Override step tester to ensure chained steps gets executed.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class ChainedStepTester implements StepTester {
/**
* The text of the step to look for exceptions / debugging messages.
*/
const EXCEPTIONS_STEP_TEXT = 'I look for exceptions';
/**
* @var StepTester Base step tester.
*/
private $singlesteptester;
/**
* @var EventDispatcher keep step event dispatcher.
*/
private $eventDispatcher;
/**
* Keep status of chained steps if used.
* @var bool
*/
protected static $chainedstepused = false;
/**
* Constructor.
*
* @param StepTester $steptester single step tester.
*/
public function __construct(StepTester $steptester) {
$this->singlesteptester = $steptester;
}
/**
* Set event dispatcher to use for events.
*
* @param EventDispatcherInterface $eventDispatcher
*/
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
}
/**
* {@inheritdoc}
*/
public function setUp(Environment $env, FeatureNode $feature, StepNode $step, $skip) {
return $this->singlesteptester->setUp($env, $feature, $step, $skip);
}
/**
* {@inheritdoc}
*/
public function test(Environment $env, FeatureNode $feature, StepNode $step, $skip) {
$result = $this->singlesteptester->test($env, $feature, $step, $skip);
if (!($result instanceof ExecutedStepResult) || !$this->supportsResult($result->getCallResult())) {
$result = $this->checkSkipResult($result);
// If undefined step then don't continue chained steps.
if ($result instanceof UndefinedStepResult) {
return $result;
}
// If exception caught, then don't continue chained steps.
if (($result instanceof ExecutedStepResult) && $result->hasException()) {
return $result;
}
// If step is skipped, then return. no need to continue chain steps.
if ($result instanceof SkippedStepResult) {
return $result;
}
// Check for exceptions.
// Extra step, looking for a moodle exception, a debugging() message or a PHP debug message.
$checkingStep = new StepNode('Given', self::EXCEPTIONS_STEP_TEXT, array(), $step->getLine());
$afterExceptionCheckingEvent = $this->singlesteptester->test($env, $feature, $checkingStep, $skip);
return $this->checkSkipResult($afterExceptionCheckingEvent);
}
return $this->runChainedSteps($env, $feature, $result, $skip);
}
/**
* {@inheritdoc}
*/
public function tearDown(Environment $env, FeatureNode $feature, StepNode $step, $skip, StepResult $result) {
return $this->singlesteptester->tearDown($env, $feature, $step, $skip, $result);
}
/**
* Check if results supported.
*
* @param CallResult $result
* @return bool
*/
private function supportsResult(CallResult $result) {
$return = $result->getReturn();
if ($return instanceof ChainedStep) {
return true;
}
if (!is_array($return) || empty($return)) {
return false;
}
foreach ($return as $value) {
if (!$value instanceof ChainedStep) {
return false;
}
}
return true;
}
/**
* Run chained steps.
*
* @param Environment $env
* @param FeatureNode $feature
* @param ExecutedStepResult $result
* @param $skip
*
* @return ExecutedStepResult|StepResult
*/
private function runChainedSteps(Environment $env, FeatureNode $feature, ExecutedStepResult $result, $skip) {
// Set chained setp is used, so it can be used by formatter to o/p.
self::$chainedstepused = true;
$callResult = $result->getCallResult();
$steps = $callResult->getReturn();
if (!is_array($steps)) {
// Test it, no need to dispatch events for single chain.
$stepResult = $this->test($env, $feature, $steps, $skip);
return $this->checkSkipResult($stepResult);
}
// Test all steps.
foreach ($steps as $step) {
// Setup new step.
$event = new BeforeStepTested($env, $feature, $step);
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
// Symfony 4.3 and up.
$this->eventDispatcher->dispatch($event, $event::BEFORE);
} else {
// TODO: Remove when our min supported version is >= 4.3.
$this->eventDispatcher->dispatch($event::BEFORE, $event);
}
$setup = $this->setUp($env, $feature, $step, $skip);
$event = new AfterStepSetup($env, $feature, $step, $setup);
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
// Symfony 4.3 and up.
$this->eventDispatcher->dispatch($event, $event::AFTER_SETUP);
} else {
// TODO: Remove when our min supported version is >= 4.3.
$this->eventDispatcher->dispatch($event::AFTER_SETUP, $event);
}
// Test it.
$stepResult = $this->test($env, $feature, $step, $skip);
// Tear down.
$event = new BeforeStepTeardown($env, $feature, $step, $result);
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
// Symfony 4.3 and up.
$this->eventDispatcher->dispatch($event, $event::BEFORE_TEARDOWN);
} else {
// TODO: Remove when our min supported version is >= 4.3.
$this->eventDispatcher->dispatch($event::BEFORE_TEARDOWN, $event);
}
$teardown = $this->tearDown($env, $feature, $step, $skip, $result);
$event = new AfterStepTested($env, $feature, $step, $result, $teardown);
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
// Symfony 4.3 and up.
$this->eventDispatcher->dispatch($event, $event::AFTER);
} else {
// TODO: Remove when our min supported version is >= 4.3.
$this->eventDispatcher->dispatch($event::AFTER, $event);
}
//
if (!$stepResult->isPassed()) {
return $this->checkSkipResult($stepResult);
}
}
return $this->checkSkipResult($stepResult);
}
/**
* Handle skip exception.
*
* @param StepResult $result
*
* @return ExecutedStepResult|SkippedStepResult
*/
private function checkSkipResult(StepResult $result) {
if ((method_exists($result, 'getException')) && ($result->getException() instanceof SkippedException)) {
return new SkippedStepResult($result->getSearchResult());
} else {
return $result;
}
}
/**
* Returns if cahined steps are used.
* @return bool.
*/
public static function is_chained_step_used() {
return self::$chainedstepused;
}
}
@@ -0,0 +1,130 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Override step tester to ensure chained steps gets executed.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\EventDispatcher\Tester;
use Behat\Behat\EventDispatcher\Event\AfterStepSetup;
use Behat\Behat\EventDispatcher\Event\AfterStepTested;
use Behat\Behat\EventDispatcher\Event\BeforeStepTeardown;
use Behat\Behat\EventDispatcher\Event\BeforeStepTested;
use Behat\Behat\Tester\Result\StepResult;
use Behat\Behat\Tester\StepTester;
use Behat\Gherkin\Node\FeatureNode;
use Behat\Gherkin\Node\StepNode;
use Behat\Testwork\Environment\Environment;
use Behat\Testwork\EventDispatcher\TestworkEventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Step tester dispatching BEFORE/AFTER events during tests.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class MoodleEventDispatchingStepTester implements StepTester
{
/**
* @var StepTester
*/
private $baseTester;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* Initializes tester.
*
* @param StepTester $baseTester
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(StepTester $baseTester, EventDispatcherInterface $eventDispatcher) {
$this->baseTester = $baseTester;
$this->eventDispatcher = $eventDispatcher;
}
/**
* {@inheritdoc}
*/
public function setUp(Environment $env, FeatureNode $feature, StepNode $step, $skip) {
$event = new BeforeStepTested($env, $feature, $step);
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
// Symfony 4.3 and up.
$this->eventDispatcher->dispatch($event, $event::BEFORE);
} else {
// TODO: Remove when our min supported version is >= 4.3.
$this->eventDispatcher->dispatch($event::BEFORE, $event);
}
$setup = $this->baseTester->setUp($env, $feature, $step, $skip);
$this->baseTester->setEventDispatcher($this->eventDispatcher);
$event = new AfterStepSetup($env, $feature, $step, $setup);
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
// Symfony 4.3 and up.
$this->eventDispatcher->dispatch($event, $event::AFTER_SETUP);
} else {
// TODO: Remove when our min supported version is >= 4.3.
$this->eventDispatcher->dispatch($event::AFTER_SETUP, $event);
}
return $setup;
}
/**
* {@inheritdoc}
*/
public function test(Environment $env, FeatureNode $feature, StepNode $step, $skip) {
return $this->baseTester->test($env, $feature, $step, $skip);
}
/**
* {@inheritdoc}
*/
public function tearDown(Environment $env, FeatureNode $feature, StepNode $step, $skip, StepResult $result) {
$event = new BeforeStepTeardown($env, $feature, $step, $result);
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
// Symfony 4.3 and up.
$this->eventDispatcher->dispatch($event, $event::BEFORE_TEARDOWN);
} else {
// TODO: Remove when our min supported version is >= 4.3.
$this->eventDispatcher->dispatch($event::BEFORE_TEARDOWN, $event);
}
$teardown = $this->baseTester->tearDown($env, $feature, $step, $skip, $result);
$event = new AfterStepTested($env, $feature, $step, $result, $teardown);
if (TestworkEventDispatcher::DISPATCHER_VERSION === 2) {
// Symfony 4.3 and up.
$this->eventDispatcher->dispatch($event, $event::AFTER);
} else {
// TODO: Remove when our min supported version is >= 4.3.
$this->eventDispatcher->dispatch($event::AFTER, $event);
}
return $teardown;
}
}
@@ -0,0 +1,10 @@
<?php
namespace Moodle\BehatExtension\Exception;
/**
* Skipped exception (throw this to mark step as "skipped").
*
* @author Jerome Mouneyrac
*/
class SkippedException extends \Exception{}
@@ -0,0 +1,101 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Skips gherkin features using a file with the list of scenarios.
*
* @copyright 2016 onwards Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Locator;
use Behat\Behat\Gherkin\Specification\LazyFeatureIterator;
use Behat\Gherkin\Gherkin;
use Behat\Testwork\Specification\Locator\SpecificationLocator;
use Behat\Testwork\Specification\NoSpecificationsIterator;
use Behat\Testwork\Suite\Suite;
/**
* Skips gherkin features using a file with the list of scenarios.
*
* @copyright 2016 onwards Rajesh Taneja
*/
final class FilesystemSkipPassedListLocator implements SpecificationLocator {
/**
* @var Gherkin
*/
private $gherkin;
/**
* Initializes locator.
*
* @param Gherkin $gherkin
*/
public function __construct(Gherkin $gherkin) {
$this->gherkin = $gherkin;
}
/**
* {@inheritdoc}
*/
public function getLocatorExamples() {
return array();
}
/**
* {@inheritdoc}
*/
public function locateSpecifications(Suite $suite, $locator) {
if (!is_file($locator) || 'passed' !== pathinfo($locator, PATHINFO_EXTENSION)) {
return new NoSpecificationsIterator($suite);
}
$scenarios = json_decode(trim(file_get_contents($locator)), true);
if (empty($scenarios) || empty($scenarios[$suite->getName()])) {
return new NoSpecificationsIterator($suite);
}
$suitepaths = $this->getSuitePaths($suite);
$scenarios = array_diff($suitepaths, array_values($scenarios[$suite->getName()]));
return new LazyFeatureIterator($suite, $this->gherkin, $scenarios);
}
/**
* Returns array of feature paths configured for the provided suite.
*
* @param Suite $suite
*
* @return string[]
*
* @throws SuiteConfigurationException If `paths` setting is not an array
*/
private function getSuitePaths(Suite $suite) {
if (!is_array($suite->getSetting('paths'))) {
throw new SuiteConfigurationException(
sprintf('`paths` setting of the "%s" suite is expected to be an array, %s given.',
$suite->getName(),
gettype($suite->getSetting('paths'))
),
$suite->getName()
);
}
return $suite->getSetting('paths');
}
}
@@ -0,0 +1,149 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Feature step counter for distributing features between parallel runs.
*
* Use it with --dry-run (and any other selectors combination) to
* get the results quickly.
*
* @copyright 2015 onwards Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Output\Formatter;
use Behat\Behat\EventDispatcher\Event\AfterFeatureTested;
use Behat\Behat\EventDispatcher\Event\AfterOutlineTested;
use Behat\Behat\EventDispatcher\Event\AfterScenarioTested;
use Behat\Behat\EventDispatcher\Event\AfterStepTested;
use Behat\Behat\EventDispatcher\Event\BeforeFeatureTested;
use Behat\Behat\EventDispatcher\Event\BeforeOutlineTested;
use Behat\Behat\EventDispatcher\Event\BeforeScenarioTested;
use Behat\Behat\Tester\Result\ExecutedStepResult;
use Behat\Testwork\Counter\Memory;
use Behat\Testwork\Counter\Timer;
use Behat\Testwork\EventDispatcher\Event\AfterExerciseCompleted;
use Behat\Testwork\EventDispatcher\Event\AfterSuiteTested;
use Behat\Testwork\EventDispatcher\Event\BeforeExerciseCompleted;
use Behat\Testwork\EventDispatcher\Event\BeforeSuiteTested;
use Behat\Testwork\Output\Exception\BadOutputPathException;
use Behat\Testwork\Output\Formatter;
use Behat\Testwork\Output\Printer\OutputPrinter;
class MoodleListFormatter implements Formatter {
/**
* @var OutputPrinter
*/
private $printer;
/**
* @var array
*/
private $parameters;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $description;
/**
* Initializes formatter.
*
* @param string $name
* @param string $description
* @param array $parameters
* @param OutputPrinter $printer
*/
public function __construct($name, $description, array $parameters, OutputPrinter $printer) {
$this->name = $name;
$this->description = $description;
$this->parameters = $parameters;
$this->printer = $printer;
}
/**
* Returns an array of event names this subscriber wants to listen to.
* @return array The event names to listen to
*/
public static function getSubscribedEvents() {
return array(
'tester.scenario_tested.after' => 'afterScenario',
'tester.outline_tested.after' => 'afterOutlineExample',
);
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->description;
}
/**
* {@inheritdoc}
*/
public function getOutputPrinter() {
return $this->printer;
}
/**
* {@inheritdoc}
*/
public function setParameter($name, $value) {
$this->parameters[$name] = $value;
}
/**
* {@inheritdoc}
*/
public function getParameter($name) {
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
}
/**
* Listens to "scenario.after" event.
*
* @param ScenarioEvent $event
*/
public function afterScenario(AfterScenarioTested $event) {
$scenario = $event->getScenario();
$this->printer->writeln($event->getFeature()->getFile() . ':' . $scenario->getLine());
}
/**
* Listens to "outline.example.after" event.
*
* @param OutlineExampleEvent $event
*/
public function afterOutlineExample(AfterOutlineTested $event) {
$outline = $event->getOutline();
$line = $outline->getLine();
$this->printer->writeln($event->getFeature()->getFile() . ':' . $line);
}
}
@@ -0,0 +1,207 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Moodle behat context class resolver.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Output\Formatter;
use Behat\Testwork\Exception\ServiceContainer\ExceptionExtension;
use Behat\Testwork\Output\ServiceContainer\OutputExtension;
use Behat\Testwork\ServiceContainer\ServiceProcessor;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Behat\Behat\Output\ServiceContainer\Formatter\ProgressFormatterFactory;
use Behat\Behat\EventDispatcher\Event\OutlineTested;
use Behat\Testwork\Output\ServiceContainer\Formatter\FormatterFactory;
use Behat\Testwork\Translator\ServiceContainer\TranslatorExtension;
class MoodleProgressFormatterFactory implements FormatterFactory {
/**
* @var ServiceProcessor
*/
private $processor;
/*
* Available services
*/
const ROOT_LISTENER_ID_MOODLE = 'output.node.listener.moodleprogress';
const RESULT_TO_STRING_CONVERTER_ID_MOODLE = 'output.node.printer.result_to_string';
/*
* Available extension points
*/
const ROOT_LISTENER_WRAPPER_TAG_MOODLE = 'output.node.listener.moodleprogress.wrapper';
/**
* Initializes extension.
*
* @param null|ServiceProcessor $processor
*/
public function __construct(ServiceProcessor $processor = null) {
$this->processor = $processor ? : new ServiceProcessor();
}
/**
* {@inheritdoc}
*/
public function buildFormatter(ContainerBuilder $container) {
$this->loadRootNodeListener($container);
$this->loadCorePrinters($container);
$this->loadPrinterHelpers($container);
$this->loadFormatter($container);
}
/**
* {@inheritdoc}
*/
public function processFormatter(ContainerBuilder $container) {
$this->processListenerWrappers($container);
}
/**
* Loads progress formatter node event listener.
*
* @param ContainerBuilder $container
*/
protected function loadRootNodeListener(ContainerBuilder $container) {
$definition = new Definition('Behat\Behat\Output\Node\EventListener\AST\StepListener', array(
new Reference('output.node.printer.moodleprogress.step')
));
$container->setDefinition(self::ROOT_LISTENER_ID_MOODLE, $definition);
}
/**
* Loads formatter itself.
*
* @param ContainerBuilder $container
*/
protected function loadFormatter(ContainerBuilder $container) {
$definition = new Definition('Behat\Behat\Output\Statistics\TotalStatistics');
$container->setDefinition('output.moodleprogress.statistics', $definition);
$moodleconfig = $container->getParameter('behat.moodle.parameters');
$definition = new Definition('Moodle\BehatExtension\Output\Printer\MoodleProgressPrinter',
array($moodleconfig['moodledirroot']));
$container->setDefinition('moodle.output.node.printer.moodleprogress.printer', $definition);
$definition = new Definition('Behat\Testwork\Output\NodeEventListeningFormatter', array(
'moodle_progress',
'Prints information about then run followed by one character per step.',
array(
'timer' => true
),
$this->createOutputPrinterDefinition(),
new Definition('Behat\Testwork\Output\Node\EventListener\ChainEventListener', array(
array(
new Reference(self::ROOT_LISTENER_ID_MOODLE),
new Definition('Behat\Behat\Output\Node\EventListener\Statistics\StatisticsListener', array(
new Reference('output.moodleprogress.statistics'),
new Reference('output.node.printer.moodleprogress.statistics')
)),
new Definition('Behat\Behat\Output\Node\EventListener\Statistics\ScenarioStatsListener', array(
new Reference('output.moodleprogress.statistics')
)),
new Definition('Behat\Behat\Output\Node\EventListener\Statistics\StepStatsListener', array(
new Reference('output.moodleprogress.statistics'),
new Reference(ExceptionExtension::PRESENTER_ID)
)),
new Definition('Behat\Behat\Output\Node\EventListener\Statistics\HookStatsListener', array(
new Reference('output.moodleprogress.statistics'),
new Reference(ExceptionExtension::PRESENTER_ID)
)),
new Definition('Behat\Behat\Output\Node\EventListener\AST\SuiteListener', array(
new Reference('moodle.output.node.printer.moodleprogress.printer')
))
)
)
)
));
$definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 1));
$container->setDefinition(OutputExtension::FORMATTER_TAG . '.moodleprogress', $definition);
}
/**
* Loads printer helpers.
*
* @param ContainerBuilder $container
*/
protected function loadPrinterHelpers(ContainerBuilder $container) {
$definition = new Definition('Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter');
$container->setDefinition(self::RESULT_TO_STRING_CONVERTER_ID_MOODLE, $definition);
}
/**
* Loads feature, scenario and step printers.
*
* @param ContainerBuilder $container
*/
protected function loadCorePrinters(ContainerBuilder $container) {
$definition = new Definition('Behat\Behat\Output\Node\Printer\CounterPrinter', array(
new Reference(self::RESULT_TO_STRING_CONVERTER_ID_MOODLE),
new Reference(TranslatorExtension::TRANSLATOR_ID),
));
$container->setDefinition('output.node.moodle.printer.counter', $definition);
$definition = new Definition('Behat\Behat\Output\Node\Printer\ListPrinter', array(
new Reference(self::RESULT_TO_STRING_CONVERTER_ID_MOODLE),
new Reference(ExceptionExtension::PRESENTER_ID),
new Reference(TranslatorExtension::TRANSLATOR_ID),
'%paths.base%'
));
$container->setDefinition('output.node.moodle.printer.list', $definition);
$definition = new Definition('Behat\Behat\Output\Node\Printer\Progress\ProgressStepPrinter', array(
new Reference(self::RESULT_TO_STRING_CONVERTER_ID_MOODLE)
));
$container->setDefinition('output.node.printer.moodleprogress.step', $definition);
$definition = new Definition('Behat\Behat\Output\Node\Printer\Progress\ProgressStatisticsPrinter', array(
new Reference('output.node.moodle.printer.counter'),
new Reference('output.node.moodle.printer.list')
));
$container->setDefinition('output.node.printer.moodleprogress.statistics', $definition);
}
/**
* Creates output printer definition.
*
* @return Definition
*/
protected function createOutputPrinterDefinition() {
return new Definition('Behat\Testwork\Output\Printer\StreamOutputPrinter', array(
new Definition('Behat\Behat\Output\Printer\ConsoleOutputFactory'),
));
}
/**
* Processes all registered pretty formatter node listener wrappers.
*
* @param ContainerBuilder $container
*/
protected function processListenerWrappers(ContainerBuilder $container) {
$this->processor->processWrapperServices($container, self::ROOT_LISTENER_ID_MOODLE, self::ROOT_LISTENER_WRAPPER_TAG_MOODLE);
}
}
@@ -0,0 +1,299 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Feature step counter for distributing features between parallel runs.
*
* Use it with --dry-run (and any other selectors combination) to
* get the results quickly.
*
* @copyright 2016 onwards Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Output\Formatter;
use Behat\Behat\EventDispatcher\Event\AfterFeatureTested;
use Behat\Behat\EventDispatcher\Event\AfterOutlineTested;
use Behat\Behat\EventDispatcher\Event\AfterScenarioTested;
use Behat\Behat\EventDispatcher\Event\AfterStepTested;
use Behat\Behat\EventDispatcher\Event\BeforeFeatureTested;
use Behat\Behat\EventDispatcher\Event\BeforeOutlineTested;
use Behat\Behat\EventDispatcher\Event\BeforeScenarioTested;
use Behat\Behat\EventDispatcher\Event\BeforeStepTested;
use Behat\Behat\Tester\Result\ExecutedStepResult;
use Behat\Testwork\Counter\Memory;
use Behat\Testwork\Counter\Timer;
use Behat\Testwork\EventDispatcher\Event\AfterExerciseCompleted;
use Behat\Testwork\EventDispatcher\Event\AfterSuiteTested;
use Behat\Testwork\EventDispatcher\Event\BeforeExerciseCompleted;
use Behat\Testwork\EventDispatcher\Event\BeforeSuiteTested;
use Behat\Testwork\Output\Exception\BadOutputPathException;
use Behat\Testwork\Output\Formatter;
use Behat\Testwork\Output\Printer\OutputPrinter;
class MoodleScreenshotFormatter implements Formatter {
/**
* @var OutputPrinter
*/
private $printer;
/**
* @var array
*/
private $parameters;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $description;
/**
* @var int The scenario count.
*/
protected static $currentscenariocount = 0;
/**
* @var int The step count within the current scenario.
*/
protected static $currentscenariostepcount = 0;
/**
* If we are saving any kind of dump on failure we should use the same parent dir during a run.
*
* @var The parent dir name
*/
protected static $faildumpdirname = false;
/**
* Initializes formatter.
*
* @param string $name
* @param string $description
* @param array $parameters
* @param OutputPrinter $printer
* @param EventListener $listener
*/
public function __construct($name, $description, array $parameters, OutputPrinter $printer) {
$this->name = $name;
$this->description = $description;
$this->parameters = $parameters;
$this->printer = $printer;
}
/**
* Returns an array of event names this subscriber wants to listen to.
* @return array The event names to listen to
*/
public static function getSubscribedEvents() {
return array(
'tester.scenario_tested.before' => 'beforeScenario',
'tester.step_tested.before' => 'beforeStep',
'tester.step_tested.after' => 'afterStep',
);
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->description;
}
/**
* {@inheritdoc}
*/
public function getOutputPrinter() {
return $this->printer;
}
/**
* {@inheritdoc}
*/
public function setParameter($name, $value) {
$this->parameters[$name] = $value;
}
/**
* {@inheritdoc}
*/
public function getParameter($name) {
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
}
/**
* Reset currentscenariostepcount
*
* @param BeforeScenarioTested $event
*/
public function beforeScenario(BeforeScenarioTested $event) {
self::$currentscenariostepcount = 0;
self::$currentscenariocount++;
}
/**
* Increment currentscenariostepcount
*
* @param BeforeStepTested $event
*/
public function beforeStep(BeforeStepTested $event) {
self::$currentscenariostepcount++;
}
/**
* Take screenshot after step is executed. Behat\Behat\Event\html
*
* @param AfterStepTested $event
*/
public function afterStep(AfterStepTested $event) {
$behathookcontext = $event->getEnvironment()->getContext('behat_hooks');
$formats = $this->getParameter('formats');
$formats = explode(',', $formats);
// Take screenshot.
if (in_array('image', $formats)) {
$this->take_screenshot($event, $behathookcontext);
}
// Save html content.
if (in_array('html', $formats)) {
$this->take_contentdump($event, $behathookcontext);
}
}
/**
* Return screenshot directory where all screenshots will be saved.
*
* @return string
*/
protected function get_run_screenshot_dir() {
global $CFG;
if (self::$faildumpdirname) {
return self::$faildumpdirname;
}
// If output_path is set then use output_path else use faildump_path.
if ($this->getOutputPrinter()->getOutputPath()) {
$screenshotpath = $this->getOutputPrinter()->getOutputPath();
} else if ($CFG->behat_faildump_path) {
$screenshotpath = $CFG->behat_faildump_path;
} else {
// It should never reach here.
throw new FormatterException('You should specify --out "SOME/PATH" for moodle_screenshot format');
}
if ($this->getParameter('dir_permissions')) {
$dirpermissions = $this->getParameter('dir_permissions');
} else {
$dirpermissions = 0777;
}
// All the screenshot dumps should be in the same parent dir.
self::$faildumpdirname = $screenshotpath . DIRECTORY_SEPARATOR . date('Ymd_His');
if (!is_dir(self::$faildumpdirname) && !mkdir(self::$faildumpdirname, $dirpermissions, true)) {
// It shouldn't, we already checked that the directory is writable.
throw new FormatterException(sprintf(
'No directories can be created inside %s, check the directory permissions.', $screenshotpath));
}
return self::$faildumpdirname;
}
/**
* Take screenshot when a step fails.
*
* @throws Exception
* @param AfterStepTested $event
*/
protected function take_screenshot(AfterStepTested $event, $context) {
// Goutte can't save screenshots.
if ($context->getMink()->isSessionStarted($context->getMink()->getDefaultSessionName())) {
if (get_class($context->getMink()->getSession()->getDriver()) === 'Behat\Mink\Driver\GoutteDriver') {
return false;
}
list ($dir, $filename) = $this->get_faildump_filename($event, 'png');
$context->saveScreenshot($filename, $dir);
}
}
/**
* Take a dump of the page content when a step fails.
*
* @throws Exception
* @param AfterStepTested $event
*/
protected function take_contentdump(AfterStepTested $event, $context) {
list ($dir, $filename) = $this->get_faildump_filename($event, 'html');
$fh = fopen($dir . DIRECTORY_SEPARATOR . $filename, 'w');
fwrite($fh, $context->getMink()->getSession()->getPage()->getContent());
fclose($fh);
}
/**
* Determine the full pathname to store a failure-related dump.
*
* This is used for content such as the DOM, and screenshots.
*
* @param AfterStepTested $event
* @param String $filetype The file suffix to use. Limited to 4 chars.
*/
protected function get_faildump_filename(AfterStepTested $event, $filetype) {
// Make a directory for the scenario.
$featurename = $event->getFeature()->getTitle();
$featurename = preg_replace('/([^a-zA-Z0-9\_]+)/', '-', $featurename);
if ($this->getParameter('dir_permissions')) {
$dirpermissions = $this->getParameter('dir_permissions');
} else {
$dirpermissions = 0777;
}
$dir = $this->get_run_screenshot_dir();
// We want a i-am-the-scenario-title format.
$dir = $dir . DIRECTORY_SEPARATOR . self::$currentscenariocount . '-' . $featurename;
if (!is_dir($dir) && !mkdir($dir, $dirpermissions, true)) {
// We already checked that the directory is writable. This should not fail.
throw new FormatterException(sprintf(
'No directories can be created inside %s, check the directory permissions.', $dir));
}
// The failed step text.
// We want a stepno-i-am-the-failed-step.$filetype format.
$filename = $event->getStep()->getText();
$filename = preg_replace('/([^a-zA-Z0-9\_]+)/', '-', $filename);
$filename = self::$currentscenariostepcount . '-' . $filename;
// File name limited to 255 characters. Leaving 4 chars for the file
// extension as we allow .png for images and .html for DOM contents.
$filename = substr($filename, 0, 250) . '.' . $filetype;
return array($dir, $filename);
}
}
@@ -0,0 +1,159 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Feature step counter for distributing features between parallel runs.
*
* Use it with --dry-run (and any other selectors combination) to
* get the results quickly.
*
* @copyright 2016 onwards Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Output\Formatter;
use Behat\Behat\EventDispatcher\Event\AfterFeatureTested;
use Behat\Behat\EventDispatcher\Event\AfterOutlineTested;
use Behat\Behat\EventDispatcher\Event\AfterScenarioTested;
use Behat\Behat\EventDispatcher\Event\AfterStepTested;
use Behat\Behat\EventDispatcher\Event\BeforeFeatureTested;
use Behat\Behat\EventDispatcher\Event\BeforeOutlineTested;
use Behat\Behat\EventDispatcher\Event\BeforeScenarioTested;
use Behat\Behat\Tester\Result\ExecutedStepResult;
use Behat\Testwork\Counter\Memory;
use Behat\Testwork\Counter\Timer;
use Behat\Testwork\EventDispatcher\Event\AfterExerciseCompleted;
use Behat\Testwork\EventDispatcher\Event\AfterSuiteTested;
use Behat\Testwork\EventDispatcher\Event\BeforeExerciseCompleted;
use Behat\Testwork\EventDispatcher\Event\BeforeSuiteTested;
use Behat\Testwork\Output\Exception\BadOutputPathException;
use Behat\Testwork\Output\Formatter;
use Behat\Testwork\Output\Printer\OutputPrinter;
class MoodleStepcountFormatter implements Formatter {
/** @var int Number of steps executed in feature file. */
private static $stepcount = 0;
/**
* @var OutputPrinter
*/
private $printer;
/**
* @var array
*/
private $parameters;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $description;
/**
* Initializes formatter.
*
* @param string $name
* @param string $description
* @param array $parameters
* @param OutputPrinter $printer
* @param EventListener $listener
*/
public function __construct($name, $description, array $parameters, OutputPrinter $printer) {
$this->name = $name;
$this->description = $description;
$this->parameters = $parameters;
$this->printer = $printer;
}
/**
* Returns an array of event names this subscriber wants to listen to.
* @return array The event names to listen to
*/
public static function getSubscribedEvents() {
return array(
'tester.feature_tested.before' => 'beforeFeature',
'tester.feature_tested.after' => 'afterFeature',
'tester.step_tested.after' => 'afterStep',
);
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->description;
}
/**
* {@inheritdoc}
*/
public function getOutputPrinter() {
return $this->printer;
}
/**
* {@inheritdoc}
*/
public function setParameter($name, $value) {
$this->parameters[$name] = $value;
}
/**
* {@inheritdoc}
*/
public function getParameter($name) {
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
}
/**
* Listens to "feature.before" event.
*
* @param FeatureEvent $event
*/
public function beforeFeature(BeforeFeatureTested $event) {
self::$stepcount = 0;
}
/**
* Listens to "feature.after" event.
*
* @param FeatureEvent $event
*/
public function afterFeature(AfterFeatureTested $event) {
$this->printer->writeln($event->getFeature()->getFile() . '::' . self::$stepcount);
}
/**
* Listens to "step.after" event.
*
* @param StepEvent $event
*/
public function afterStep(AfterStepTested $event) {
self::$stepcount++;
}
}
@@ -0,0 +1,127 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Moodle behat context class resolver.
*
* @package behat
* @copyright 2016 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Output\Printer;
use Behat\Behat\Output\Node\Printer\SetupPrinter;
use Behat\Testwork\Output\Formatter;
use Behat\Testwork\Tester\Setup\Setup;
use Behat\Testwork\Tester\Setup\Teardown;
use Behat\Testwork\Call\CallResult;
use Behat\Testwork\Hook\Tester\Setup\HookedTeardown;
use Behat\Testwork\Output\Printer\OutputPrinter;
use Behat\Testwork\Tester\Result\TestResult;
use Moodle\BehatExtension\Driver\WebDriver;
/**
* Prints hooks in a pretty fashion.
*/
final class MoodleProgressPrinter implements SetupPrinter {
/**
* @var string Moodle directory root.
*/
private $moodledirroot;
/**
* @var bool true if output is displayed.
*/
private static $outputdisplayed;
/**
* Constructor.
*
* @param string $moodledirroot Moodle dir root.
*/
public function __construct($moodledirroot) {
$this->moodledirroot = $moodledirroot;
}
/**
* {@inheritdoc}
*/
public function printSetup(Formatter $formatter, Setup $setup) {
if (empty(self::$outputdisplayed)) {
$this->printMoodleInfo($formatter->getOutputPrinter());
self::$outputdisplayed = true;
}
}
/**
* {@inheritdoc}
*/
public function printTeardown(Formatter $formatter, Teardown $teardown) {
if (!$teardown instanceof HookedTeardown) {
return;
}
foreach ($teardown->getHookCallResults() as $callResult) {
$this->printTeardownHookCallResult($formatter->getOutputPrinter(), $callResult);
}
}
/**
* We print the site info + driver used and OS.
*
* @param Printer $printer
* @return void
*/
public function printMoodleInfo($printer) {
require_once($this->moodledirroot . '/lib/behat/classes/util.php');
$browser = WebDriver::getBrowserName();
// Calling all directly from here as we avoid more behat framework extensions.
$runinfo = \behat_util::get_site_info();
$runinfo .= 'Server OS "' . PHP_OS . '"' . ', Browser: "' . $browser . '"' . PHP_EOL;
$runinfo .= 'Started at ' . date('d-m-Y, H:i', time());
$printer->writeln($runinfo);
}
/**
* Prints teardown hook call result.
*
* @param OutputPrinter $printer
* @param CallResult $callResult
*/
private function printTeardownHookCallResult(OutputPrinter $printer, CallResult $callResult) {
// Notify dev that chained step is being used.
if (\Moodle\BehatExtension\EventDispatcher\Tester\ChainedStepTester::is_chained_step_used()) {
$printer->writeln();
$printer->write("{+failed}Chained steps are deprecated. See https://docs.moodle.org/dev/Acceptance_testing/Migrating_from_Behat_2.5_to_3.x_in_Moodle#Changes_required_in_context_file{-failed}");
}
if (!$callResult->hasStdOut() && !$callResult->hasException()) {
return;
}
$hook = $callResult->getCall()->getCallee();
$path = $hook->getPath();
$printer->writeln($hook);
$printer->writeln($path);
}
}
@@ -0,0 +1,302 @@
<?php
namespace Moodle\BehatExtension\ServiceContainer;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
use Behat\Testwork\ServiceContainer\ExtensionManager;
use Behat\Testwork\ServiceContainer\ServiceProcessor;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Moodle\BehatExtension\Output\Formatter\MoodleProgressFormatterFactory;
use Behat\Behat\Tester\ServiceContainer\TesterExtension;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Behat\Behat\EventDispatcher\ServiceContainer\EventDispatcherExtension;
use Behat\Testwork\Suite\ServiceContainer\SuiteExtension;
use Behat\Behat\Definition\ServiceContainer\DefinitionExtension;
use Behat\Testwork\Cli\ServiceContainer\CliExtension;
use Behat\Behat\Definition\Printer\ConsoleDefinitionListPrinter;
use Behat\Behat\Gherkin\ServiceContainer\GherkinExtension;
use Behat\Testwork\Output\ServiceContainer\OutputExtension;
use Behat\Testwork\Specification\ServiceContainer\SpecificationExtension;
use Moodle\BehatExtension\Driver\WebDriverFactory;
/**
* Behat extension for moodle
*
* Provides multiple features directory loading (Gherkin\Loader\MoodleFeaturesSuiteLoader
*/
class BehatExtension implements ExtensionInterface {
/**
* Extension configuration ID.
*/
const MOODLE_ID = 'moodle';
const GHERKIN_ID = 'gherkin';
/**
* @var ServiceProcessor
*/
private $processor;
/**
* Initializes compiler pass.
*
* @param null|ServiceProcessor $processor
*/
public function __construct(ServiceProcessor $processor = null) {
$this->processor = $processor ? : new ServiceProcessor();
}
/**
* Loads moodle specific configuration.
*
* @param array $config Extension configuration hash (from behat.yml)
* @param ContainerBuilder $container ContainerBuilder instance
*/
public function load(ContainerBuilder $container, array $config) {
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/services'));
$loader->load('core.xml');
// Getting the extension parameters.
$container->setParameter('behat.moodle.parameters', $config);
// Load moodle progress formatter.
$moodleprogressformatter = new MoodleProgressFormatterFactory();
$moodleprogressformatter->buildFormatter($container);
// Load custom step tester event dispatcher.
$this->loadEventDispatchingStepTester($container);
// Load chained step tester.
$this->loadChainedStepTester($container);
// Load step count formatter.
$this->loadMoodleListFormatter($container);
// Load step count formatter.
$this->loadMoodleStepcountFormatter($container);
// Load screenshot formatter.
$this->loadMoodleScreenshotFormatter($container);
// Load namespace alias.
$this->alias_old_namespaces();
// Load skip passed controller and list locator.
$this->loadSkipPassedController($container, $config['passed_cache']);
$this->loadFilesystemSkipPassedScenariosListLocator($container);
}
/**
* Loads moodle List formatter.
*
* @param ContainerBuilder $container
*/
protected function loadMoodleListFormatter(ContainerBuilder $container) {
$definition = new Definition('Moodle\BehatExtension\Output\Formatter\MoodleListFormatter', array(
'moodle_list',
'List all scenarios. Use with --dry-run',
array('stepcount' => false),
$this->createOutputPrinterDefinition()
));
$definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 101));
$container->setDefinition(OutputExtension::FORMATTER_TAG . '.moodle_list', $definition);
}
/**
* Loads moodle Step count formatter.
*
* @param ContainerBuilder $container
*/
protected function loadMoodleStepcountFormatter(ContainerBuilder $container) {
$definition = new Definition('Moodle\BehatExtension\Output\Formatter\MoodleStepcountFormatter', array(
'moodle_stepcount',
'Count steps in feature files. Use with --dry-run',
array('stepcount' => false),
$this->createOutputPrinterDefinition()
));
$definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 101));
$container->setDefinition(OutputExtension::FORMATTER_TAG . '.moodle_stepcount', $definition);
}
/**
* Loads moodle screenshot formatter.
*
* @param ContainerBuilder $container
*/
protected function loadMoodleScreenshotFormatter(ContainerBuilder $container) {
$definition = new Definition('Moodle\BehatExtension\Output\Formatter\MoodleScreenshotFormatter', array(
'moodle_screenshot',
'Take screenshot of all steps. Use --format-settings \'{"formats": "html,image"}\' to get specific o/p type',
array('formats' => 'html,image'),
$this->createOutputPrinterDefinition()
));
$definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 102));
$container->setDefinition(OutputExtension::FORMATTER_TAG . '.moodle_screenshot', $definition);
}
/**
* Creates output printer definition.
*
* @return Definition
*/
protected function createOutputPrinterDefinition() {
return new Definition('Behat\Testwork\Output\Printer\StreamOutputPrinter', array(
new Definition('Behat\Behat\Output\Printer\ConsoleOutputFactory'),
));
}
/**
* Loads skip passed controller.
*
* @param ContainerBuilder $container
* @param null|string $cachePath
*/
protected function loadSkipPassedController(ContainerBuilder $container, $cachePath) {
$definition = new Definition('Moodle\BehatExtension\Tester\Cli\SkipPassedController', array(
new Reference(EventDispatcherExtension::DISPATCHER_ID),
$cachePath,
$container->getParameter('paths.base')
));
$definition->addTag(CliExtension::CONTROLLER_TAG, array('priority' => 200));
$container->setDefinition(CliExtension::CONTROLLER_TAG . '.passed', $definition);
}
/**
* Loads filesystem passed scenarios list locator.
*
* @param ContainerBuilder $container
*/
private function loadFilesystemSkipPassedScenariosListLocator(ContainerBuilder $container) {
$definition = new Definition('Moodle\BehatExtension\Locator\FilesystemSkipPassedListLocator', array(
new Reference(self::GHERKIN_ID)
));
$definition->addTag(SpecificationExtension::LOCATOR_TAG, array('priority' => 50));
$container->setDefinition(SpecificationExtension::LOCATOR_TAG . '.filesystem_skip_passed_scenarios_list', $definition);
}
/**
* Loads definition printers.
*
* @param ContainerBuilder $container
*/
private function loadDefinitionPrinters(ContainerBuilder $container) {
$definition = new Definition('Moodle\BehatExtension\Definition\Printer\ConsoleDefinitionInformationPrinter', array(
new Reference(CliExtension::OUTPUT_ID),
new Reference(DefinitionExtension::PATTERN_TRANSFORMER_ID),
new Reference(DefinitionExtension::DEFINITION_TRANSLATOR_ID),
new Reference(GherkinExtension::KEYWORDS_ID)
));
$container->removeDefinition('definition.information_printer');
$container->setDefinition('definition.information_printer', $definition);
}
/**
* Loads definition controller.
*
* @param ContainerBuilder $container
*/
private function loadController(ContainerBuilder $container) {
$definition = new Definition('Moodle\BehatExtension\Definition\Cli\AvailableDefinitionsController', array(
new Reference(SuiteExtension::REGISTRY_ID),
new Reference(DefinitionExtension::WRITER_ID),
new Reference('definition.list_printer'),
new Reference('definition.information_printer'))
);
$container->removeDefinition(CliExtension::CONTROLLER_TAG . '.available_definitions');
$container->setDefinition(CliExtension::CONTROLLER_TAG . '.available_definitions', $definition);
}
/**
* Loads chained step tester.
*
* @param ContainerBuilder $container
*/
protected function loadChainedStepTester(ContainerBuilder $container) {
// Chained steps.
$definition = new Definition('Moodle\BehatExtension\EventDispatcher\Tester\ChainedStepTester', array(
new Reference(TesterExtension::STEP_TESTER_ID),
));
$definition->addTag(TesterExtension::STEP_TESTER_WRAPPER_TAG, array('priority' => 100));
$container->setDefinition(TesterExtension::STEP_TESTER_WRAPPER_TAG . '.substep', $definition);
}
/**
* Loads event-dispatching step tester.
*
* @param ContainerBuilder $container
*/
protected function loadEventDispatchingStepTester(ContainerBuilder $container) {
$definition = new Definition('Moodle\BehatExtension\EventDispatcher\Tester\MoodleEventDispatchingStepTester', array(
new Reference(TesterExtension::STEP_TESTER_ID),
new Reference(EventDispatcherExtension::DISPATCHER_ID)
));
$definition->addTag(TesterExtension::STEP_TESTER_WRAPPER_TAG, array('priority' => -9999));
$container->setDefinition(TesterExtension::STEP_TESTER_WRAPPER_TAG . '.event_dispatching', $definition);
}
/**
* Setups configuration for current extension.
*
* @param ArrayNodeDefinition $builder
*/
public function configure(ArrayNodeDefinition $builder) {
$builder->
children()->
arrayNode('capabilities')->
useAttributeAsKey('key')->
prototype('variable')->end()->
end()->
arrayNode('steps_definitions')->
useAttributeAsKey('key')->
prototype('variable')->end()->
end()->
scalarNode('moodledirroot')->
defaultNull()->
end()->
scalarNode('passed_cache')->
info('Sets the passed cache path')->
defaultValue(
is_writable(sys_get_temp_dir())
? sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat_passed_cache'
: null)->
end()->
end()->
end();
}
/**
* {@inheritDoc}
*/
public function getConfigKey() {
return self::MOODLE_ID;
}
/**
* {@inheritdoc}
*/
public function initialize(ExtensionManager $extensionManager) {
if (null !== $minkExtension = $extensionManager->getExtension('mink')) {
$minkExtension->registerDriverFactory(new WebDriverFactory());
}
}
public function process(ContainerBuilder $container) {
// Load controller for definition printing.
$this->loadDefinitionPrinters($container);
$this->loadController($container);
}
/**
* Alias old namespace of given. when and then for BC.
*/
private function alias_old_namespaces() {
class_alias('Moodle\\BehatExtension\\Context\\Step\\Given', 'Behat\\Behat\\Context\\Step\\Given', true);
class_alias('Moodle\\BehatExtension\\Context\\Step\\When', 'Behat\\Behat\\Context\\Step\\When', true);
class_alias('Moodle\\BehatExtension\\Context\\Step\\Then', 'Behat\\Behat\\Context\\Step\\Then', true);
}
}
@@ -0,0 +1,26 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="behat.moodle.parameters"></parameter>
<parameter key="moodle.context.initializer.class">Moodle\BehatExtension\Context\Initializer\MoodleAwareInitializer</parameter>
<parameter key="moodle.context.contextclass.classresolver.class">Moodle\BehatExtension\Context\ContextClass\ClassResolver</parameter>
<parameter key="behat.mink.selector.handler.class">Behat\Mink\Selector\SelectorsHandler</parameter>
</parameters>
<services>
<!-- Moodle context initializer -->
<service id="moodle.context.initializer" class="%moodle.context.initializer.class%">
<argument>%behat.moodle.parameters%</argument>
<tag name="context.initializer" />
</service>
<!-- Moodle class resolver for behat context -->
<service id="moodle.context.contextclass.classresolver" class="%moodle.context.contextclass.classresolver.class%">
<argument>%behat.moodle.parameters%</argument>
<tag name="context.class_resolver" />
</service>
</services>
</container>
@@ -0,0 +1,199 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Caches passed scenarios and skip only them if `--skip-passed` option provided.
*
* @copyright 2016 onwards Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace Moodle\BehatExtension\Tester\Cli;
use Behat\Behat\EventDispatcher\Event\AfterFeatureTested;
use Behat\Behat\EventDispatcher\Event\AfterScenarioTested;
use Behat\Behat\EventDispatcher\Event\ExampleTested;
use Behat\Behat\EventDispatcher\Event\FeatureTested;
use Behat\Behat\EventDispatcher\Event\ScenarioTested;
use Behat\Testwork\Cli\Controller;
use Behat\Testwork\EventDispatcher\Event\ExerciseCompleted;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Behat\Testwork\Tester\Result\TestResult;
/**
* Caches passed scenarios and skip only them if `--skip-passed` option provided.
*
* @copyright 2016 onwards Rajesh Taneja
*/
final class SkipPassedController implements Controller {
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var null|string
*/
private $cachePath;
/**
* @var string
*/
private $key;
/**
* @var string[]
*/
private $lines = array();
/**
* @var string
*/
private $basepath;
/**
* Initializes controller.
*
* @param EventDispatcherInterface $eventDispatcher
* @param null|string $cachePath
* @param string $basepath
*/
public function __construct(EventDispatcherInterface $eventDispatcher, $cachePath, $basepath) {
$this->eventDispatcher = $eventDispatcher;
$this->cachePath = null !== $cachePath ? rtrim($cachePath, DIRECTORY_SEPARATOR) : null;
$this->basepath = $basepath;
}
/**
* Configures command to be executable by the controller.
*
* @param Command $command
*/
public function configure(Command $command) {
$command->addOption('--skip-passed', null, InputOption::VALUE_NONE,
'Skip scenarios that passed during last execution.'
);
}
/**
* Executes controller.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return null|integer
*/
public function execute(InputInterface $input, OutputInterface $output) {
if (!$input->getOption('skip-passed')) {
// If no skip option is passed then remove any old file which we are saving.
if (!$this->getFileName()) {
return;
}
if (file_exists($this->getFileName())) {
unlink($this->getFileName());
}
return;
}
$this->eventDispatcher->addListener(ScenarioTested::AFTER, array($this, 'collectPassedScenario'), -50);
$this->eventDispatcher->addListener(ExampleTested::AFTER, array($this, 'collectPassedScenario'), -50);
$this->eventDispatcher->addListener(ExerciseCompleted::AFTER, array($this, 'writeCache'), -50);
$this->key = $this->generateKey($input);
if (!$this->getFileName() || !file_exists($this->getFileName())) {
return;
}
$input->setArgument('paths', $this->getFileName());
$existing = json_decode(file_get_contents($this->getFileName()), true);
if (!empty($existing)) {
$this->lines = array_merge_recursive($existing, $this->lines);
}
}
/**
* Records scenario if it is passed.
*
* @param AfterScenarioTested $event
*/
public function collectPassedScenario(AfterScenarioTested $event) {
if (!$this->getFileName()) {
return;
}
$feature = $event->getFeature();
$suitename = $event->getSuite()->getName();
if (($event->getTestResult()->getResultCode() !== TestResult::PASSED) &&
($event->getTestResult()->getResultCode() !== TestResult::SKIPPED)) {
unset($this->lines[$suitename][$feature->getFile()]);
return;
}
$this->lines[$suitename][$feature->getFile()] = $feature->getFile();
}
/**
* Writes passed scenarios cache.
*/
public function writeCache() {
if (!$this->getFileName()) {
return;
}
if (0 === count($this->lines)) {
return;
}
file_put_contents($this->getFileName(), json_encode($this->lines));
}
/**
* Generates cache key.
*
* @param InputInterface $input
*
* @return string
*/
private function generateKey(InputInterface $input) {
return md5(
$input->getParameterOption(array('--profile', '-p')) .
$input->getOption('suite') .
implode(' ', $input->getOption('name')) .
implode(' ', $input->getOption('tags')) .
$input->getOption('role') .
$input->getArgument('paths') .
$this->basepath
);
}
/**
* Returns cache filename (if exists).
*
* @return null|string
*/
private function getFileName() {
if (null === $this->cachePath || null === $this->key) {
return null;
}
if (!is_dir($this->cachePath)) {
mkdir($this->cachePath, 0777);
}
return $this->cachePath . DIRECTORY_SEPARATOR . $this->key . '.passed';
}
}
+5
View File
@@ -0,0 +1,5 @@
This directory is a copy of original Moodle behat extension
located at https://github.com/moodlehq/moodle-behat-extension
The reason to move this code to Moodle core was to simplify
maintenance of behat integration.
+7
View File
@@ -7,6 +7,13 @@
<version>5.20.16</version>
<licenseversion>2.1+</licenseversion>
</library>
<library>
<location>behat/extension</location>
<name>Moodle behat extension</name>
<license>GPL</license>
<version>3.39.6</version>
<licenseversion>3.0+</licenseversion>
</library>
<library>
<location>bennu</location>
<name>Bennu</name>