| 1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace Moodle\BehatExtension\Output\Formatter;
|
|
|
18 |
|
|
|
19 |
use Behat\Behat\EventDispatcher\Event\AfterOutlineTested;
|
|
|
20 |
use Behat\Behat\EventDispatcher\Event\AfterScenarioTested;
|
|
|
21 |
use Behat\Testwork\Output\Formatter;
|
|
|
22 |
use Behat\Testwork\Output\Printer\OutputPrinter;
|
|
|
23 |
|
|
|
24 |
// phpcs:disable moodle.NamingConventions.ValidFunctionName.LowercaseMethod
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Feature step counter for distributing features between parallel runs.
|
|
|
28 |
*
|
|
|
29 |
* Use it with --dry-run (and any other selectors combination) to
|
|
|
30 |
* get the results quickly.
|
|
|
31 |
*
|
|
|
32 |
* @package core
|
|
|
33 |
* @copyright 2015 onwards Rajesh Taneja
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class MoodleListFormatter implements Formatter {
|
|
|
37 |
|
|
|
38 |
/** @var OutputPrinter */
|
|
|
39 |
private $printer;
|
|
|
40 |
|
|
|
41 |
/** @var array */
|
|
|
42 |
private $parameters;
|
|
|
43 |
|
|
|
44 |
/** @var string */
|
|
|
45 |
private $name;
|
|
|
46 |
|
|
|
47 |
/** @var string */
|
|
|
48 |
private $description;
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Initializes formatter.
|
|
|
52 |
*
|
|
|
53 |
* @param string $name
|
|
|
54 |
* @param string $description
|
|
|
55 |
* @param array $parameters
|
|
|
56 |
* @param OutputPrinter $printer
|
|
|
57 |
*/
|
|
|
58 |
public function __construct($name, $description, array $parameters, OutputPrinter $printer) {
|
|
|
59 |
$this->name = $name;
|
|
|
60 |
$this->description = $description;
|
|
|
61 |
$this->parameters = $parameters;
|
|
|
62 |
$this->printer = $printer;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Returns an array of event names this subscriber wants to listen to.
|
|
|
67 |
*
|
|
|
68 |
* @return array The event names to listen to
|
|
|
69 |
*/
|
|
|
70 |
public static function getSubscribedEvents() {
|
|
|
71 |
return [
|
|
|
72 |
|
|
|
73 |
'tester.scenario_tested.after' => 'afterScenario',
|
|
|
74 |
'tester.outline_tested.after' => 'afterOutlineExample',
|
|
|
75 |
];
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Returns formatter name.
|
|
|
80 |
*
|
|
|
81 |
* @return string
|
|
|
82 |
*/
|
|
|
83 |
public function getName() {
|
|
|
84 |
return $this->name;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Returns formatter description.
|
|
|
89 |
*
|
|
|
90 |
* @return string
|
|
|
91 |
*/
|
|
|
92 |
public function getDescription() {
|
|
|
93 |
return $this->description;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Returns formatter output printer.
|
|
|
98 |
*
|
|
|
99 |
* @return OutputPrinter
|
|
|
100 |
*/
|
|
|
101 |
public function getOutputPrinter() {
|
|
|
102 |
return $this->printer;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* Sets formatter parameter.
|
|
|
107 |
*
|
|
|
108 |
* @param string $name
|
|
|
109 |
* @param mixed $value
|
|
|
110 |
*/
|
|
|
111 |
public function setParameter($name, $value) {
|
|
|
112 |
$this->parameters[$name] = $value;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
/**
|
|
|
116 |
* Returns parameter name.
|
|
|
117 |
*
|
|
|
118 |
* @param string $name
|
|
|
119 |
*
|
|
|
120 |
* @return mixed
|
|
|
121 |
*/
|
|
|
122 |
public function getParameter($name) {
|
|
|
123 |
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Listens to "scenario.after" event.
|
|
|
128 |
*
|
|
|
129 |
* @param AfterScenarioTested $event
|
|
|
130 |
*/
|
|
|
131 |
public function afterScenario(AfterScenarioTested $event) {
|
|
|
132 |
$scenario = $event->getScenario();
|
|
|
133 |
$this->printer->writeln($event->getFeature()->getFile() . ':' . $scenario->getLine());
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* Listens to "outline.example.after" event.
|
|
|
139 |
*
|
|
|
140 |
* @param AfterOutlineTested $event
|
|
|
141 |
*/
|
|
|
142 |
public function afterOutlineExample(AfterOutlineTested $event) {
|
|
|
143 |
$outline = $event->getOutline();
|
|
|
144 |
$line = $outline->getLine();
|
|
|
145 |
$this->printer->writeln($event->getFeature()->getFile() . ':' . $line);
|
|
|
146 |
}
|
|
|
147 |
}
|