3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 use Civi\Core\Event\EventScanner
;
19 * @var \Civi\Test\EventCheck[]|null
21 private $allChecks = NULL;
24 * @var \Civi\Test\EventCheck[]|null
26 private $activeChecks = NULL;
29 * @param \PHPUnit\Framework\Test $test
33 public function start($test) {
34 if ($this->activeChecks
=== NULL) {
35 $this->activeChecks
= [];
36 foreach ($this->findAll() as $template) {
37 /** @var EventCheck $template */
38 if ($template->isSupported($test)) {
39 $checker = clone $template;
40 $checker->setTest($test);
41 $this->activeChecks
[] = $checker;
52 public function addListeners() {
53 $d = \Civi
::dispatcher();
54 foreach ($this->activeChecks ?
: [] as $checker) {
55 /** @var EventCheck $checker */
56 $d->addListenerMap($checker, EventScanner
::findListeners($checker));
57 // For the moment, KISS. But we may want a counter at some point - to ensure things actually run.
58 //foreach (EventScanner::findListeners($checker) as $event => $listeners) {
59 // foreach ($listeners as $listener) {
60 // $d->addListener($event,
61 // function($args...) use ($listener) {
64 // $checker->$m(...$args);
77 public function stop() {
78 // NOTE: In test environment, dispatcher will be removed regardless.
79 foreach ($this->activeChecks ??
[] as $checker) {
80 /** @var \Civi\Test\EventCheck $checker */
81 Invasive
::call([$checker, 'tearDown']);
82 $checker->setTest(NULL);
84 $this->activeChecks
= NULL;
89 * @return EventCheck[]
91 protected function findAll() {
92 if ($this->allChecks
=== NULL) {
94 $testDir = \Civi
::paths()->getPath('[civicrm.root]/tests/events');
95 $files = \CRM_Utils_File
::findFiles($testDir, '*.evch.php', TRUE);
97 foreach ($files as $file) {
98 $all[$file] = require $testDir . '/' . $file;
100 $this->allChecks
= $all;
103 return $this->allChecks
;