ILIAS  release_8 Revision v8.24
ILIASSuite.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
6
7use PHPUnit\Framework\TestSuite;
8use PHPUnit\Framework\TestCase;
9use PHPUnit\Runner\Filter\Factory as FilterFactory;
10use PHPUnit\Runner\Filter\ExcludeGroupFilterIterator as GroupExcludeFilter;
11
22class ILIASSuite extends TestSuite
23{
27 public const REGEX_TEST_FILENAME = "#[a-zA-Z]+Test\.php#";
28 public const PHP_UNIT_PARENT_CLASS = TestCase::class;
29
30 public static function suite()
31 {
32 $suite = new ILIASSuite();
33 echo "ILIAS PHPUnit-Tests need installed dev-requirements, please install using 'composer install' in ./libs/composer \n";
34 echo "\n";
35
36 // scan Modules and Services directories
37 $basedirs = array("Services", "Modules");
38
39 foreach ($basedirs as $basedir) {
40 // read current directory
41 $dir = opendir($basedir);
42
43 while ($file = readdir($dir)) {
44 if ($file != "." && $file != ".." && is_dir($basedir . "/" . $file)) {
45 $suite_path =
46 $basedir . "/" . $file . "/test/il" . $basedir . $file . "Suite.php";
47 if (is_file($suite_path)) {
48 include_once($suite_path);
49
50 $name = "il" . $basedir . $file . "Suite";
51 $s = $name::suite();
52 echo "Adding Suite: " . $name . "\n";
53 $suite->addTest($s);
54 //$suite->addTestSuite("ilSettingTest");
55 }
56 }
57 }
58 }
59
60 $suite = self::addTestFolderToSuite($suite);
61
62 echo "\n";
63
64 return $suite;
65 }
66
70 protected static function addTestFolderToSuite(ILIASSuite $suite): ILIASSuite
71 {
72 $test_directories = array("tests");
73 while ($aux_dir = current($test_directories)) {
74 if ($handle = opendir($aux_dir)) {
75 $aux_dir .= DIRECTORY_SEPARATOR;
76 while (false !== ($entry = readdir($handle))) {
77 if ($entry === '.' || $entry === '..') {
78 continue;
79 }
80 if (is_dir($aux_dir . $entry)) {
81 $test_directories[] = $aux_dir . $entry;
82 } else {
83 if (1 === preg_match(self::REGEX_TEST_FILENAME, $entry)) {
84 $ref_declared_classes = get_declared_classes();
85 require_once $aux_dir . "/" . $entry;
86 $new_declared_classes = array_diff(get_declared_classes(), $ref_declared_classes);
87 foreach ($new_declared_classes as $entry_class) {
88 $reflection = new ReflectionClass($entry_class);
89 if (!$reflection->isAbstract() && $reflection->isSubclassOf(self::PHP_UNIT_PARENT_CLASS)) {
90 echo "Adding Test-Suite: " . $entry_class . "\n";
91 $suite->addTestSuite($entry_class);
92 }
93 }
94 }
95 }
96 }
97 }
98 next($test_directories);
99 }
100 return $suite;
101 }
102}
This is the global ILIAS test suite.
Definition: ILIASSuite.php:23
const REGEX_TEST_FILENAME
Definition: ILIASSuite.php:27
static addTestFolderToSuite(ILIASSuite $suite)
Find and add all testSuits beneath ILIAS_ROOL/tests - folder.
Definition: ILIASSuite.php:70
const PHP_UNIT_PARENT_CLASS
Definition: ILIASSuite.php:28
static suite()
Definition: ILIASSuite.php:30
if($format !==null) $name
Definition: metadata.php:247